Encoding and decoding Go data
Go features a number of alternative encoding types aside from JSON, TOML, and YAML. These are largely meant for transporting data between Go processes with things such as wire protocols and RPC or in cases where some character formats are restricted.
This recipe will explore encoding and decoding gob format and base64. The later chapters will explore protocols such as GRPC.
Getting ready
Refer to the steps given in the Getting ready section of the Converting Data Types and Interface Casting recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to a the
chapter3/encoding
directory. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter3/encoding or use this as an exercise to write some of your own.
- Create a file called
gob.go
with the following contents:
package encoding import ( "bytes" "encoding/gob" "fmt" ...