Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Last active May 13, 2018 23:48
Show Gist options
  • Save jasonkeene/ac707953c9dd3dbb9b6979bc45bc1f9c to your computer and use it in GitHub Desktop.
Save jasonkeene/ac707953c9dd3dbb9b6979bc45bc1f9c to your computer and use it in GitHub Desktop.
Notes for Protobuf Episode

Why use protobuf?

Protocol buffers are a flexible and efficient way to represent structured data.

  • Binary Serialzation
  • Schema vs Schemaless
  • Parse time
  • Backwards compatibility
  • Cross language/platform

Supported Types

Primitive

  • double
  • float
  • int64
  • uint64
  • int32
  • uint32
  • bool
  • string
  • bytes

Stdlib Types

  • Duration
  • Timestamp
  • Empty
  • Any

Versions

  • syntax = "proto2";
  • syntax = "proto3";

Runtime Dependency and Code Gen

Basic .proto file

syntax = "proto3";

package gobuildit;

import "google/protobuf/timestamp.proto";

message Request {
    uint64 id = 1;
    string name = 2;
    google.protobuf.Timestamp timestamp = 3;
}

Compile!

protoc -I . -I include/ --go_out=out/ request.proto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment