Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed descriptors in generated code #743

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ perf: $(BUILD)/protobuf-test
.PHONY: bootstrap
bootstrap: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es node_modules ## Bootstrap well-known types and edition features-set defaults in @bufbuild/protobuf from upstream protobuf
npm run -w packages/protobuf bootstrap:wkt
npm run -w packages/protobuf bootstrap:wktv2
npm run -w packages/protobuf bootstrap:featureset-defaults

.PHONY: setversion
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

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

3 changes: 3 additions & 0 deletions packages/protobuf-test/extra/jstype.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
syntax = "proto3";
package spec;

// See proto2.proto and proto2.proto - extend them to all relevant scalar types if necessary
option deprecated = true;

message JSTypeOmittedMessage {
fixed64 fixed64_field = 1;
int64 int64_field = 3;
Expand Down
171 changes: 165 additions & 6 deletions packages/protobuf-test/extra/proto2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,185 @@

syntax = "proto2";
package spec;

option go_package = "github.com/bufbuild/protobuf-es";
import "google/protobuf/wrappers.proto";

message Proto2Message {
required string required_string_field = 1;
required bytes required_bytes_field = 2;
required int32 required_int32_field = 3;
required int64 required_int64_field = 4;
required int64 required_int64_js_number_field = 103 [jstype=JS_NUMBER];
required int64 required_int64_js_string_field = 102 [jstype=JS_STRING];
required float required_float_field = 5;
required bool required_bool_field = 6;
required Proto2Enum required_enum_field = 7;
required Proto2Message required_message_field = 8;
required group RequiredGroup = 9 {
optional int32 int32_field = 1;
}
required google.protobuf.UInt32Value required_wrapped_uint32_field = 201;

required string required_default_string_field = 10 [default = "hello \" */ "];
required bytes required_default_bytes_field = 11 [default = "\0x\\x\"x\'A\101\x41\x41\u0041\U00000041\b\f\n\r\t\v"];
required int32 required_default_int32_field = 12 [default = 128];
required int64 required_default_int64_field = 13 [default = -256];
required int64 required_default_int64_js_number_field = 110 [default = -256, jstype = JS_NUMBER];
required int64 required_default_int64_js_string_field = 113 [default = -256, jstype = JS_STRING];
required float required_default_float_field = 14 [default = -512.13];
required bool required_default_bool_field = 15 [default = true];
required Proto2Enum required_default_enum_field = 16 [default = PROTO2_ENUM_YES];
required Proto2Message required_default_message_field = 17;
required group RequiredDefaultGroup = 18 {
optional int32 int32_field = 1;
}
required google.protobuf.UInt32Value required_default_wrapped_uint32_field = 202;

optional string optional_string_field = 19;
optional bytes optional_bytes_field = 20;
optional int32 optional_int32_field = 21;
optional int64 optional_int64_field = 22;
optional int64 optional_int64_js_number_field = 106 [jstype=JS_NUMBER];
optional int64 optional_int64_js_string_field = 105 [jstype=JS_STRING];
optional float optional_float_field = 23;
optional bool optional_bool_field = 24;
optional Proto2Enum optional_enum_field = 25;
optional Proto2Message optional_message_field = 26;
optional group OptionalGroup = 27 {
optional int32 int32_field = 1;
}
required google.protobuf.UInt32Value optional_wrapped_uint32_field = 207;

required string optional_default_string_field = 28 [default = "hello \" */ "];
required bytes optional_default_bytes_field = 29 [default = "\0x\\x\"x\'A\101\x41\x41\u0041\U00000041\b\f\n\r\t\v"];
required int32 optional_default_int32_field = 30 [default = 128];
required int64 optional_default_int64_field = 31 [default = -256];
optional int64 optional_default_int64_js_number_field = 120 [default = -256, jstype = JS_NUMBER];
optional int64 optional_default_int64_js_string_field = 121 [default = -256, jstype = JS_STRING];
required float optional_default_float_field = 32 [default = -512.13];
required bool optional_default_bool_field = 33 [default = true];
required Proto2Enum optional_default_enum_field = 34 [default = PROTO2_ENUM_YES];
optional Proto2Message optional_default_message_field = 35;
optional group OptionalDefaultGroup = 36 {
optional int32 int32_field = 1;
}
required google.protobuf.UInt32Value optional_default_wrapped_uint32_field = 203;

repeated string repeated_string_field = 37;
repeated bytes repeated_bytes_field = 38;
repeated int32 repeated_int32_field = 39;
repeated int64 repeated_int64_field = 40;
repeated int64 repeated_int64_js_number_field = 109 [jstype=JS_NUMBER];
repeated int64 repeated_int64_js_string_field = 108 [jstype=JS_STRING];
repeated float repeated_float_field = 41;
repeated bool repeated_bool_field = 42;
repeated Proto2Enum repeated_enum_field = 43;
repeated Proto2Message repeated_message_field = 44;
repeated group RepeatedGroup = 45 {
optional int32 int32_field = 1;
}
repeated google.protobuf.UInt32Value repeated_wrapped_uint32_field = 204;

repeated double packed_double_field = 46 [packed = true];
repeated uint32 packed_uint32_field = 47 [packed = true];
repeated uint64 packed_uint64_field = 48 [packed = true];

repeated double unpacked_double_field = 49 [packed = false];
repeated uint32 unpacked_uint32_field = 50 [packed = false];
repeated uint64 unpacked_uint64_field = 51 [packed = false];

oneof either {
string oneof_string_field = 52;
bytes oneof_bytes_field = 53;
int32 oneof_int32_field = 54;
int64 oneof_int64_field = 55;
int64 oneof_int64_js_number_field = 112 [jstype=JS_NUMBER];
int64 oneof_int64_js_string_field = 111 [jstype=JS_STRING];
float oneof_float_field = 56;
bool oneof_bool_field = 57;
Proto2Enum oneof_enum_field = 58;
Proto2Message oneof_message_field = 59;
group OneofGroup = 60 {
optional int32 int32_field = 1;
}
google.protobuf.UInt32Value oneof_wrapped_uint32_field = 205;
}
map<string, string> map_string_string_field = 70;
map<int32, int32> map_int32_int32_field = 71;
map<bool, bool> map_bool_bool_field = 72;
map<int64, int64> map_int64_int64_field = 73;
map<int32, Proto2EnumWithZero> map_int32_enum_field = 74;
map<int32, Proto2Message> map_int32_message_field = 75;
map<int32, google.protobuf.UInt32Value> map_int32_wrapped_uint32_field = 209;
}

enum Proto2Enum {
PROTO2_ENUM_YES = 1;
PROTO2_ENUM_NO = 2;
}

// First enum value must be 0 when used as map value type
enum Proto2EnumWithZero {
PROTO2_ENUM_WITH_ZERO_ZERO = 0;
PROTO2_ENUM_WITH_ZERO_ONE = 1;
}


message Proto2RepeatedMessage {
option deprecated = true;
repeated string string_field = 1;
repeated bytes bytes_field = 2;
repeated int32 int32_field = 3;
repeated int64 int64_field = 4;
repeated float float_field = 5;
repeated bool bool_field = 6;
repeated Proto2Enum enum_field = 7;
repeated Proto2ChildMessage message_field = 8;
repeated group RepeatedGroup = 9 {
optional int32 int32_field = 1;
}
}

message Proto2OneofMessage {
option deprecated = true;
oneof some {
string string_field = 1;
bytes bytes_field = 2;
int32 int32_field = 3;
int64 int64_field = 4;
float float_field = 5;
bool bool_field = 6;
Proto2Enum enum_field = 7;
Proto2ChildMessage message_field = 8;
group RepeatedGroup = 9 {
optional int32 int32_field = 1;
}
}
}

message Proto2PackedMessage {
option deprecated = true;
repeated double packed_double_field = 101 [packed = true];
repeated uint32 packed_uint32_field = 102 [packed = true];
repeated uint64 packed_uint64_field = 103 [packed = true];
}

message Proto2UnpackedMessage {
option deprecated = true;
repeated double unpacked_double_field = 201 [packed = false];
repeated uint32 unpacked_uint32_field = 202 [packed = false];
repeated uint64 unpacked_uint64_field = 203 [packed = false];
}

message Proto2UnspecifiedPackedMessage {
option deprecated = true;
repeated double double_field = 1;
repeated uint32 uint32_field = 2;
repeated uint64 uint64_field = 3;
}

message Proto2OptionalMessage {
option deprecated = true;
optional string string_field = 1;
optional bytes bytes_field = 2;
optional int32 int32_field = 3;
Expand All @@ -47,6 +204,7 @@ message Proto2OptionalMessage {
}

message Proto2RequiredMessage {
option deprecated = true;
required string string_field = 1;
required bytes bytes_field = 2;
required int32 int32_field = 3;
Expand All @@ -58,6 +216,7 @@ message Proto2RequiredMessage {
}

message Proto2RequiredDefaultsMessage {
option deprecated = true;
required string string_field = 1 [default = "hello \" */ "];
required bytes bytes_field = 2 [default = "\0x\\x\"x\'A\101\x41\x41\u0041\U00000041\b\f\n\r\t\v"];
required int32 int32_field = 3 [default = 128];
Expand All @@ -69,6 +228,7 @@ message Proto2RequiredDefaultsMessage {
}

message Proto2DefaultsMessage {
option deprecated = true;
optional string string_field = 1 [default = "hello \" */ "];
optional bytes bytes_field = 2 [default = "\0x\\x\"x\'A\101\x41\x41\u0041\U00000041\b\f\n\r\t\v"];
optional int32 int32_field = 3 [default = 128];
Expand All @@ -79,27 +239,26 @@ message Proto2DefaultsMessage {
optional Proto2ChildMessage message_field = 8;
}

enum Proto2Enum {
PROTO2_ENUM_YES = 1;
PROTO2_ENUM_NO = 2;
}

message Proto2ChildMessage {
option deprecated = true;
optional string string_field = 1;
}

message Proto2GroupsMessage {
option deprecated = true;
optional group Group = 1 {
optional int32 int32_field = 1;
optional group NestedGroup = 2 {
optional string string_field = 1;
}
}
repeated group RepeatedGroup = 2 {
option deprecated = true;
optional int32 int32_field = 1;
}
oneof oneof_with_group {
group OneofGroup = 3 {
option deprecated = true;
optional bool bool_field = 1;
}
}
Expand Down
Loading
Loading