Skip to content

Delimited messages read/write support #2745

Closed Answered by JakeWharton
friendoye asked this question in Q&A
Discussion options

You must be logged in to vote

Okay so the code to do this today is a bit annoying, but it's doable. Let's go!

First, I haven't thought about length-delimited protos since that comment in 2016 so my memory on how they work is a little hazy. I believe they're quite simply varint32 length-prefixed messages. This is basically the encoding of a nested message on the wire (sans the tag byte). If they're not that, just replace that varint call with whatever the actual type of the length prefix is.

Encoding in this format is trivial with our APIs:

Buffer buffer = new Buffer();
ProtoWriter writer = new ProtoWriter(buffer);

OneField firstWrite = new OneField.Builder().opt_int32(2).build();
writer.writeVarint32(OneField.ADAPTER.e…

Replies: 2 comments 2 replies

This comment has been hidden.

Comment options

You must be logged in to vote
2 replies
@friendoye
Comment options

@JakeWharton
Comment options

Answer selected by JakeWharton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants