Skip to content

Commit

Permalink
Merge pull request #15 from euroelessar/proto2-support
Browse files Browse the repository at this point in the history
generator: support proto2
  • Loading branch information
vmg authored Jul 12, 2021
2 parents 81d623a + c968771 commit 27a3a9c
Show file tree
Hide file tree
Showing 11 changed files with 16,697 additions and 202 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gen-include:
mv include/github.com/planetscale/vtprotobuf/vtproto/*.go ./vtproto

gen-testproto:
for name in "pool/pool.proto proto3opt/opt.proto"; do \
for name in "pool/pool.proto proto3opt/opt.proto proto2/scalars.proto"; do \
$(PROTOBUF_ROOT)/src/protoc \
--proto_path=testproto \
--proto_path=include \
Expand All @@ -46,4 +46,4 @@ gen-testproto:
genall: install gen-include gen-conformance gen-testproto

test: install gen-conformance
go test -count=1 ./conformance/...
go test -count=1 ./conformance/...
36 changes: 16 additions & 20 deletions conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,19 @@ func conformanceUnmarshal(b []byte, msg proto.Message) error {
type unmarshalvt interface {
UnmarshalVT(b []byte) error
}
if u, ok := msg.(unmarshalvt); ok {
if err := u.UnmarshalVT(b); err != nil {
return err
}
u := msg.(unmarshalvt)
if err := u.UnmarshalVT(b); err != nil {
return err
}

if !proto.Equal(expected, msg) {
fmt.Fprintf(marshalDifflog, "UNMARSHAL\n")
fmt.Fprintf(marshalDifflog, "expected:\n%s\n\n", prototext.Format(expected))
fmt.Fprintf(marshalDifflog, "got:\n%s\n\n", prototext.Format(msg))
fmt.Fprintf(marshalDifflog, "raw: %#v\n\n", b)
fmt.Fprintf(marshalDifflog, "==============\n\n")
}
return nil
if !proto.Equal(expected, msg) {
fmt.Fprintf(marshalDifflog, "UNMARSHAL\n")
fmt.Fprintf(marshalDifflog, "expected:\n%s\n\n", prototext.Format(expected))
fmt.Fprintf(marshalDifflog, "got:\n%s\n\n", prototext.Format(msg))
fmt.Fprintf(marshalDifflog, "raw: %#v\n\n", b)
fmt.Fprintf(marshalDifflog, "==============\n\n")
}
return proto.Unmarshal(b, msg)
return nil
}

func conformanceMarshal(msg proto.Message) ([]byte, error) {
Expand Down Expand Up @@ -115,14 +113,12 @@ func conformanceMarshal(msg proto.Message) ([]byte, error) {
type marshalvt interface {
MarshalVT() ([]byte, error)
}
if m, ok := msg.(marshalvt); ok {
got, err = m.MarshalVT()
if err != nil {
return nil, err
}
return got, nil
m := msg.(marshalvt)
got, err = m.MarshalVT()
if err != nil {
return nil, err
}
return expected, nil
return got, nil
}

func main() {
Expand Down
Loading

0 comments on commit 27a3a9c

Please sign in to comment.