> ## Content Index
> Fetch the complete content index at: https://datajutsu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# A Protobuf Required Is a Check the Decoder Runs (and the Wire Never Carried It)
- URL: https://datajutsu.com/protobuf-required-presence/
- Published: 2026-10-24T02:15:42.000Z
- Updated: 2026-10-24T02:15:42.000Z
- Author: Data Jutsu

A required field looks like a promise about the data. It reads as: this field will be there. I built a small proto2 message with two required fields and ran it through both the JavaScript library and the real protoc 25.3 binary, and the word required turns out to be something narrower and stranger than that. It is a check that runs in one place, with one consequence, and the bytes it is supposed to protect carry absolutely no trace of it. The field that must be present is indistinguishable, byte for byte, from a field that never was.

Here is what the word actually is, in the parts that matter. The parser stores the rule word on the field, and in the file descriptor the whole difference between required and optional is a single byte, a label with the value two instead of one. I compared the descriptors of the same message, one field required, one optional, and the only byte that differs is that label. The wire has none of it. The message with name and age set encodes to the same bytes whether the fields are required, optional, or bare proto3 fields. There is no marker, no checksum, no count. Presence is a schema fact, and the schema is a file on a machine somewhere, not in the stream.

The check runs at decode time, and only there, at least in the JavaScript library. Feed the decoder the bytes for name and age, no problem. Hand it bytes that have name but no age, and after it has read every byte in the stream it throws, missing required age, naming the field. The nested case behaves the same: a required message field that was never on the wire throws missing required inner at the outer level. And a field that is present but empty, a zero that was actually written, passes the check, because the check is about seeing the tag, not about the value. A required int that carried zero satisfies required. The library distinguishes the two cases by a property on the decoded object, the key exists only if the bytes carried it, and that is the closest the format gets to a has-method.

The encoders disagree about the check, and that is where it gets quiet. The JavaScript library does not check at all on the way out. I called fromObject on an empty object and encoded it, and a message with two required fields wrote out cleanly: the required string became a present-but-empty field and the required integer became zero, four bytes total, no error. The reason is in the generated code: optional fields are guarded by a property check before they are written, required fields are written unconditionally, and an undefined value encodes as the empty form of its type. protoc checks on the way out, but only as a warning: encode a message missing a required field and it prints, Input message is missing required fields: age, keeps exit code zero, and writes the bytes it has. So the JavaScript library throws on the way in, the real encoder warns on the way out, the wire verifies nothing, and the one API that would catch it before encoding, the verify method that reports age: integer expected, is the one nobody calls. That is the whole enforcement surface: one throw, one warning, one byte.

The parser has its own opinions about the word, and two of them go the direction that will surprise you. First, it accepts required inside a proto3 file, stores it, and the decoder enforces it, while protoc rejects the same line with Required fields are not allowed in proto3\. A file that fails the real compiler parses and runs in the browser tool, which is the reverse of the more common trap where the parser refuses a shape protoc forgives. Second, in a proto2 file the rule word is mandatory on every field line: a bare int32 plain = 5 dies with illegal token int32, because the parser, like protoc, expects one of required, optional, or repeated first. And while the file was open I checked how proto3 implements its own optional keyword, the one that lets a proto3 field carry a zero and prove it was written: it is a synthetic oneof, one member, with the field registered inside it, which is the same machinery the oneof post covers, and it is why a proto3 field with the word optional in front of it stores a oneof membership instead of a rule.

That is where it lands for a schema change. I ran the diff tab's own comparison, the real function, not a re-implementation, over three edits: required changed to optional, optional changed to required, and a bare proto3 field promoted to proto2 required. All three came back with zero breaking changes and zero safe additions, the report reads no difference at all, because it checks the number, the type, and whether the field is repeated, not the rule word. The change that adds a check your next decoder will throw on is the one change the report cannot see. The rule word is a byte in the descriptor, a throw on one side of the connection, and a line your diff tool skips, and the wire it is supposed to guard does not know it exists. The two-syntax history it sits in is in the [proto3 versus proto2 post](https://datajutsu.com/proto3-vs-proto2/), the synthetic oneof mechanism under proto3 optional is in the [oneof post](https://datajutsu.com/protobuf-oneof/), and what the diff report does show, line by line, is in the [diff report post](https://datajutsu.com/protobuf-diff-breaking-changes-report/). The tool at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com) parses both syntaxes, and if you paste a proto2 message with required fields, the decode tab will tell you about the check the moment your bytes fail it.