O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The gob serialization and deserialization need the Encoder and Decoder. The gob.NewEncoder function creates the Encoder with the underlying Writer. Each call of the Encode method will serialize the object into a gob format. The gob format itself is the self-describing binary format. This means each serialized struct is preceded by its description.

To decode the data from the serialized form, the Decoder must be created by calling the gob.NewDecoder with the underlying Reader. The Decode then accepts the pointer to the structure where the data should be deserialized. 

Note that the gob format does not need the source and destination type to match exactly. For the rules, refer to the encoding/gob package.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required