Skip to content

Instantly share code, notes, and snippets.

@gebv
Last active September 11, 2022 01:29
Show Gist options
  • Save gebv/37698d2f33de38a17a14827bda4644d8 to your computer and use it in GitHub Desktop.
Save gebv/37698d2f33de38a17a14827bda4644d8 to your computer and use it in GitHub Desktop.
Example of encode and decode a binary message from proto
# encode
echo 'foo: "bar", nested: { obj: {foo: "bar"}}' | protoc  \
  --proto_path=${PWD} \
  --encode="package.full.naem.v1.MessageFooBar" \
  ${PWD}/path/to/file.proto > message.bin
  
# decode
cat message.bin | protoc \
  --proto_path=${PWD} \
  --decode=package.full.naem.v1.MessageFooBar \
  ${PWD}/path/to/file.proto

# binary message in C-format
# hexdump -v -e '1/1 "\\x%02x"' message.bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment