I Captured a Real gRPC Response Body (and Read Every Byte)
I ran a gRPC server, pointed a client at a streaming endpoint that returns two small messages, and captured exactly what crossed the wire. Thirty-five bytes, no padding, no mystery. The first frame is a 0x00 flag byte, four big-endian length bytes saying fifteen, and fifteen bytes of ordinary protobuf — a message with a name, an age, a list of tags. The second frame is the same shape: flag, length ten, ten bytes of a different message. Zero bytes after the last frame. That is the whole body. Not a message, not even a message with a header — a stream of messages, each wrapped in a five-byte envelope, concatenated with no separator and no count.
The envelope is the tell, and it is in the first five bytes. Byte zero is 0x00, and a protobuf message does not open with 0x00: that reads as field number zero, wire type zero, the one combination a tag walker can legally skip, so the length bytes get consumed as its value and the walk keeps going. I fed the framed body to a schema decoder anyway, to watch it fail the way they do. It took the opening 0x00 as field zero, kept reading the length bytes and the payload as if they were a message, and died at offset seventeen with 'invalid wire type 4' — a clean error, in this case, and it was still inside the first frame when it got there. Other decoders are less polite and hand you garbage that looks plausible. The detection a no-schema reader uses is the whole rule: a stream that opens 0x00 or 0x01 and whose next four bytes, read big-endian, fit inside the remaining length is a gRPC body. Strip the five bytes, decode what is left, repeat. A message that opens with a real tag like 0x0a is a message, not a frame, and the frames stay out of the way.
Two messages in one body is the normal case for a streaming response, not an edge case, and this is where the common bug lives. A decoder that reads one message and stops does not error — it decodes the first frame cleanly and sits on fifteen bytes it never looked at. 'Decodes fine but leaves bytes over' is the symptom, and the fix is to keep walking frames until the body is consumed, one entry per frame. The length field is what makes that safe: each envelope says exactly how many payload bytes follow, so the next frame starts at a known offset, and the stream is unambiguous. A single-frame body decodes to one object, a multi-frame body to an array, and nothing about the payload tells the two apart except how many envelopes are in it.
The flag byte has exactly two legal values and the second one changes everything about the payload. Flag zero means the bytes are the wire format as-is. Flag one means the payload was gzip-compressed by the sender, and the length field counts the compressed bytes. My capture came back uncompressed, so I built the compressed frame by hand around the same message to verify that path, because flag one is what real servers send more often than you would expect from the spec. The raw gzip bytes open with 0x1f, which a tag walk reads as field three, wire type seven, and seven is not a wire type, so a decoder that skips the gunzip step does not even get to the plausible-garbage stage. It throws immediately. Decompress first, then decode, and the frame comes back identical to the uncompressed one.
The part nobody's body capture shows is the status, because the status is not in the body. The call result rides in HTTP/2 trailers — a separate headers frame that arrives after the data, carrying grpc-status and a message, and in my capture that frame said status zero, OK. A body-only capture of a successful call and a failed call can be byte-identical; the verdict is in the trailers, not the payload. That is two framing layers doing their own jobs, and it is why 'just decode the response' is never quite true: HTTP/2 frames the data, gRPC frames the messages inside it, and the transport closes the call in a place the protobuf reader never sees. If you are debugging a call and the bytes decode perfectly, the failure may be sitting in the trailers the whole time.
All of it runs in the browser with no protoc. Paste the body from a capture or a client log into the decode tab at proto.datajutsu.com with your .proto and it strips the frames, gunzips the compressed ones, and returns one entry per message, with the flags and sizes named in the note. The raw decode tab takes the no-schema path: every field number in the stream in plain view, so the 0x00 opening tells you 'this is framed' before you commit to a schema. The sister posts are the response-decoding post and the request-building post, and the tag math the whole walk depends on is in the wire format post.