Skip to content

Commit

Permalink
Revert "Add functions for field presence (#717)"
Browse files Browse the repository at this point in the history
This reverts commit 93797f3.
  • Loading branch information
timostamm committed Feb 20, 2024
1 parent e14d086 commit 602744d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 825 deletions.
25 changes: 0 additions & 25 deletions docs/runtime_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ provided by the library.
- [Default field values](#default-field-values)
- [Accessing fields](#accessing-fields)
- [Accessing oneof groups](#accessing-oneof-groups)
- [Field presence](#field-presence)
- [Cloning messages](#cloning-messages)
- [Comparing messages](#comparing-messages)
- [Serializing messages](#serializing-messages)
Expand Down Expand Up @@ -234,27 +233,6 @@ the TypeScript compiler option [`strictNullChecks`](https://www.typescriptlang.o
This option is automatically enabled with the option `strict`, which is recommended.


### Field presence

As we explained above, fields have [default values](#default-field-values). To
determine whether a field has an actual value, you can use the function `isFieldSet`.
To reset a field to its initial value, use the function `clearField`.

```typescript
import { isFieldSet, clearField } from "@bufbuild/protobuf";

const user = new User({
active: true,
});

isFieldSet(user, "active"); // true
isFieldSet(user, "firstName"); // false

clearField(user, "active");
isFieldSet(user, "active"); // false
```


### Cloning messages

While a shallow copy of a message can be created by using the spread operator with the
Expand Down Expand Up @@ -761,9 +739,6 @@ walkFields(user);
For a more practical example that covers all cases, you can take a look at the
source of [`toPlainMessage`][src-toPlainMessage].

Not that the functions `isFieldSet` and `clearField` (see [Field presence](#field-presence))
optionally accept a field info object instead of a field name.


### Message types

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,073 b | 41,481 b | 10,747 b |
| protobuf-es | 96,999 b | 41,438 b | 10,763 b |
| protobuf-javascript | 394,384 b | 288,654 b | 45,122 b |
23 changes: 4 additions & 19 deletions packages/protobuf-test/extra/proto3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,21 @@ message Proto3UnpackedMessage {
repeated uint64 unpacked_uint64_field = 203 [packed = false];
}

message Proto3UnspecifiedPackedMessage {
message Proto3UnlabelledMessage {
repeated double double_field = 1;
repeated uint32 uint32_field = 2;
repeated uint64 uint64_field = 3;
}

message Proto3UnlabelledMessage {
string string_field = 1;
bytes bytes_field = 2;
int32 int32_field = 3;
int64 int64_field = 4;
float float_field = 5;
bool bool_field = 6;
Proto3Enum enum_field = 7;
Proto3OptionalMessage message_field = 8;
}

message Proto3OptionalMessage {
optional string string_field = 1;
optional bytes bytes_field = 2;
optional int32 int32_field = 3;
optional int64 int64_field = 4;
optional float float_field = 5;
optional bool bool_field = 6;
optional Proto3Enum enum_field = 7;
optional Proto3OptionalMessage message_field = 8;
optional Proto3Enum enum_field = 3;
optional Proto3OptionalMessage message_field = 4;
}

enum Proto3Enum {
PROTO3_ENUM_UNSPECIFIED = 0;
PROTO3_ENUM_YES = 1;
PROTO3_ENUM_NO = 2;
}
}
87 changes: 4 additions & 83 deletions packages/protobuf-test/src/gen/js/extra/proto3_pb.d.ts

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

31 changes: 5 additions & 26 deletions packages/protobuf-test/src/gen/js/extra/proto3_pb.js

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

Loading

0 comments on commit 602744d

Please sign in to comment.