npm.io
0.10.0 • Published 3 weeks ago

@dxos/codec-protobuf

Licence
FSL-1.1-Apache-2.0
Version
0.10.0
Deps
9
Size
442 kB
Vulns
0
Weekly
0
Stars
510

codec-protobuf

There's an associated @dxos/protobuf-compiler package that does codegen based on protobuf schema.

Handling of scalar fields with default values

Based on:

In protobuf scalar fields (numbers, booleans, strings, bytes, enums) may have an implicit default value:

  • 0 for number types
  • false for booleans
  • '' (empty string) for strings
  • [] for bytes
  • First enum value for enums

Non-optional fields

Example:

int32 number = 1;

If the field is set to it's default value (0 in this example) it MAY be missing in the wire encoding (Go implementation) or present with the value set to 0 (JS implementation).

When decoding, the missing fields MUST be treated as having the default implicit value (0 in this case).

Optional fields
optional int32 number = 1;

If the field is set to it's default value (0 in this example) it MUST be present in the wire encoding with the value set to 0.

When decoding, the missing fields it MUST be set as undefined. If the field is present in the wire format, it must be set to its numeric value.

Toolchain

This package must NOT use toolchain to avoid cyclic dependencies.