Q: Why does Gob deserialize a ptr to an empty string back as null?

141 views
Skip to first unread message

Robert Whitcher

unread,
Dec 1, 2021, 3:22:21 PM12/1/21
to golang-nuts

Seems like it is impossible to differentiate between not set and set to empty string which seem like different cases to me.

Rob Pike

unread,
Dec 1, 2021, 4:41:55 PM12/1/21
to Robert Whitcher, golang-nuts
Gob does not encode pointers as different from values. The stream is a
stream of values. How many indirections it takes the values to come to
the stream is not recorded. A consequence of that, combined with not
sending zero values, is that empty strings and nil pointers to strings
are encoded the same. In fact they are not encoded at all.


-rob
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fde8754f-f381-4d90-ab04-248f45e69f8dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages