Open bokunodev opened 2 years ago
@bokunodev There is a no copy converting trick:
func ToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
@bokunodev There is a no copy converting trick:
func ToString(b []byte) string { return *(*string)(unsafe.Pointer(&b)) }
where is that code? i couldn't find it with github search. do i have to implement it?
i have made a working prototype, can i submit a pull request?
it's just a coding trick in go, you should use it to convert your []byte
to string, and pass the string variable to QRcode library's API.
by the way, It is not necessary to care about the performance loss of converting between []byte
and string
at the most time except your application is highly realtime
Hi, we are using this library to encode output from
json.Marshal
into a qrcode. but converting[]byte
tostring
is a copy operation, and we want to minimize that. havingqrcode.Encode
variant that accept[]byte
instead ofstring
would be great. probably i'll be namedqrcode.EncodeBytes
, with that we could reuse buffer and probably improve performance.