Effective Serialization In Go: JSON, Protocol Buffers and More

Effective Serialization In Go: JSON, Protocol Buffers and More

1h 11mAdvanced2024-07-22

Authors

Miki Tebeka

Miki Tebeka

CEO at 353Solutions

Course details

Serialization—taking data structures from the language and converting them to a sequence of bytes—is something every developer encounters at one point or another. In this course, instructor Miki Tebeka teaches you how to work effectively with serialization in Go. This course is targeted to advanced Go developers, and starts with a look at some serialization best practices. Miki then looks at some Go-specific formats as well as JSON. He also shows you how to work with protocol buffers—a powerful binary format—and finishes with a tour of some other popular serialization formats like XML, CSV, and SQL. Each chapter ends with a challenge, so you can test your serialization skills as you go.

Learning objectives
Describe why we need serialization.
Explain what to consider when picking a format.
Review common formats.
Use interfaces for serialization.

Skills covered

GoProgramming FoundationsGoogleProgramming LanguagesSoftware DevelopmentOne-Off

Concepts

Introduction

  • Effective serialization in Go
  • What you should know
  • Working with Codespaces

Serialization Overview

  • Why do we need serialization
  • Picking a format
  • General rules
  • Formats overview

Go-Specific Formats

  • String representation
  • encoding.TextMarshaler
  • encoding gob
  • Challenge - User database
  • Solution - User database

Working with JSON

  • encoding json API
  • Custom marshaling
  • Zero vs. missing values
  • Handling dynamic types
  • Streaming JSON
  • Challenge - Marshal metrics
  • Solution - Marshal metrics

Working with Protocol Buffers

  • Protocol buffers overview
  • Generating code
  • Using the generated code
  • Working with time
  • Emitting JSON
  • Challenge - Encode RideEnd to a file
  • Solution - Encode a RideEnd to a file

Other Serialization Formats

  • YAML and TOML
  • XML
  • CSV
  • SQL
  • Challenge - ETL
  • Solution - ETL

Conclusion

  • Next steps
40,000 Toman