Skip to content

Commit

Permalink
Support proto2 default values and field presence (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Feb 19, 2024
1 parent 0f32996 commit 0b0f084
Show file tree
Hide file tree
Showing 64 changed files with 6,282 additions and 3,908 deletions.
4 changes: 2 additions & 2 deletions docs/generated_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ foo = "";
bar?: string;
```

Note that all scalar fields have an intrinsic default value in proto3 syntax, unless they are marked
as `optional`. Protobuf types map to ECMAScript types as follows:
Note that all scalar fields have a zero-value in proto3 syntax, unless they are
marked as `optional`. Protobuf types map to ECMAScript types as follows:

| protobuf type | ECMAScript type | default value |
|---------------|-----------------|----------------------|
Expand Down
12 changes: 3 additions & 9 deletions docs/runtime_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ You can create an instance with the `new` keyword:
const user = new User();
```


For convenience, constructors accept an initializer object. All fields in the
initializer object are optional, and if not provided, the default value for the
field is used.
initializer object are optional, and if not provided, the field keeps its
default value.

```typescript
const user = new User({
Expand Down Expand Up @@ -1163,12 +1162,7 @@ let plain: PlainMessage<User> = {
};
```
As such, [`PlainMessage<T>`][src-PlainMessage] can be a great fit to use
throughout your business logic, if that business logic is never concerned with
serialization, and does not need `instanceof`.
Note that any `T` (assuming `T` extends `Message`) is assignable to a variable
of type [`PlainMessage<T>`][src-PlainMessage].
You can convert any message to a plain message with the function [`toPlainMessage`][src-toPlainMessage].
### AnyMessage
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ server would usually do.

| code generator | bundle size | minified | compressed |
|---------------------|------------------------:|-----------------------:|-------------------:|
| protobuf-es | 97,378 b | 41,628 b | 10,766 b |
| protobuf-es | 98,372 b | 41,985 b | 10,933 b |
| protobuf-javascript | 394,384 b | 288,654 b | 45,122 b |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b0f084

Please sign in to comment.