moonproto

Playground

Take a message apart

One schema, three samples. The bytes, the JSON and the text below were all written by this library; the page only switches between them.

1 envelope.proto
syntax = "proto3";
package demo;

enum Color {
  RED  = 0;
  BLUE = 1;
}

message Envelope {
  int32  id     = 1;
  string name   = 2;
  map<string, int32> counts = 3;
  Color  color  = 4;
}
2 output
starting the engine

A field is one tag byte and its payload. The low three bits of the tag carry the wire type, so the decoder knows whether to read a varint, eight bytes, or a length followed by that many bytes.

Note. The map entry is an ordinary message with fields 1 (key) and 2 (value); protobuf has no separate map encoding on the wire.