New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b2s and s2b #1186
Comments
We don't expose these methods because they are very dangerous to use. If people have to copy them into their code they can see how it works and are hopefully more aware of the dangers. The pointer for the argument to The The So in conclusion all these methods are basically the same, you can copy either, but the fasthttp ones are the simplest I guess. |
I did just realize that the easyjson implementation is wrong: mailru/easyjson#358 |
@erikdubbelboer thank you for the finding, great job 👍 |
The b2s (bytes to string) and s2b (string to byte sice) functions from bytesconv.go are named in lower case and can't be used from outside of fasthttp package. I do really need them too for two applications.
So I extracted them into a separate micro module https://github.com/stokito/go-strbytes
To make them usable I had to rename them to upper case
S2b
but that looks ugly and I gave more clear names.But then I decided to check how the similar functions looks in other libraries and I was wondered that they are look different:
github.com/buger/jsonparser@v1.1.1/bytes_unsafe.go
Here :
bytesToString
receives a pointer which looks like a hack for old Golang. Or maybe this is still valid thing to do?StringToBytes
has an additional lineb := make([]byte, 0, 0)
which is absent in the fasthttp'ss2b
. Maybe this is also needed?Now the similar function from github.com/mailru/easyjson@v0.7.7/jlexer/bytestostr.go
The function makes an additional steps that are missing in the
b2s
from fasthttp.So my question is: could anybody tell exactly the correct implementation of those functions?
Or maybe we must send a PR to that libraries.
The text was updated successfully, but these errors were encountered: