Decoding and Encoding
One of the most common network automation tasks is the ingesting and processing of structured data. You can retrieve data from or send it to a remote location or even store it on a local disk. Regardless of its location, you have to convert this data into an appropriate format. Encoding or marshaling is the process of transforming bytes from a Go data structure into a structured textual representation. Decoding or unmarshalling is the reverse process of populating Go values with externally sourced data.
Some examples of structured data encoding schemes are YAML, JSON, XML, and Protocol Buffers. Go’s standard library includes packages that implement encoding and decoding for most of these popular formats and they all leverage the io.Reader
and io.Writer
interface primitives which we’ve learned about in the last section.
In this section, we go through how Go deals with the following tasks:
- Using tags to annotate Go structs to help libraries encode and...