Printf can print hexadecimal just fine. Never understood the point of
encoding/hex.

Meanwhile, for questions about strings, see blog.golang.org/strings.

-rob


On Tue, Aug 20, 2019 at 9:00 PM Sam Whited <s...@samwhited.com> wrote:

> I personally wouldn't do this. If you're going to incur the overhead of a
> heap allocation, might as well incur a bit more and encode the hash, eg.
> using hex.EncodeToString [1], just so that you don't forget and try to
> print or decode the string as utf8 later.
>
> —Sam
>
> [1]: https://godoc.org/encoding/hex#EncodeToString
>
> On August 20, 2019 8:12:20 AM UTC, Pierre Durand <pierredur...@gmail.com>
> wrote:
> >I know that by convention Go string contain UTF-8 encoded text.
> >
> >Is it recommended/a good practice to store invalid bytes in a string ?
> >
> >The use case:
> >- compute a hash => get a []byte
> >- convert the []byte to string (this string is not UTF-8 valid)
> >- use the string as a map key
> >
> >In my case, the hash algorithm is md5.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/42989202-2854-479E-A536-13664BE41946%40samwhited.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOXNBZTKU%3DmSjj%2B9vujYFqphR0Zy%2BMtW0nHW2OayLchEgdvrEA%40mail.gmail.com.

Reply via email to