Skip to content

Commit

Permalink
Merge pull request #39 from perkupapp/proto3-optional
Browse files Browse the repository at this point in the history
Add optional support for proto3 fields
  • Loading branch information
mescanne authored Sep 15, 2023
2 parents 34288dc + 7249205 commit 8edab4b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion examples/foo/test_table.schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"mode": "NULLABLE",
"policyTags": {
"names": [
"public
"public"
]
}
},
Expand All @@ -40,5 +40,10 @@
"mode": "NULLABLE"
}
]
},
{
"name": "optional_c",
"type": "STRING",
"mode": "NULLABLE"
}
]
2 changes: 2 additions & 0 deletions examples/test_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ message TestTable{
message EmptyMessage {}

repeated EmptyMessage hasMessage = 4;

optional string optional_c = 5;
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.15
require (
github.com/golang/glog v1.0.0
github.com/golang/protobuf v1.5.2
google.golang.org/protobuf v1.28.0
google.golang.org/protobuf v1.31.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IV
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
5 changes: 4 additions & 1 deletion pkg/converter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
descriptor "google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)

var (
Expand Down Expand Up @@ -391,7 +392,9 @@ func Convert(req *plugin.CodeGeneratorRequest) (*plugin.CodeGeneratorResponse, e
generateTargets[file] = true
}

res := &plugin.CodeGeneratorResponse{}
res := &plugin.CodeGeneratorResponse{
SupportedFeatures: proto.Uint64(uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)),
}
for _, file := range req.GetProtoFile() {
for msgIndex, msg := range file.GetMessageType() {
glog.V(1).Infof("Loading a message type %s from package %s", msg.GetName(), file.GetPackage())
Expand Down

0 comments on commit 8edab4b

Please sign in to comment.