mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-27 15:26:51 +00:00
all: remove dependency on proto v1
This does not remove all dependencies, but all of the cases where it can now be implemented in terms of v2. Change-Id: Idc5b0273f0d35c284bf2141eb9cce998692ceb15 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/184878 Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
parent
6e381b5c7f
commit
8d30bbeede
@ -9,9 +9,10 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/internal/fieldnum"
|
||||
"google.golang.org/protobuf/internal/scalar"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
@ -26,7 +27,7 @@ func TestAnnotations(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gotInfo := &descriptorpb.GeneratedCodeInfo{}
|
||||
if err := proto.UnmarshalText(string(metaFile), gotInfo); err != nil {
|
||||
if err := prototext.Unmarshal(metaFile, gotInfo); err != nil {
|
||||
t.Fatalf("can't parse meta file: %v", err)
|
||||
}
|
||||
|
||||
@ -66,7 +67,6 @@ func TestAnnotations(t *testing.T) {
|
||||
})
|
||||
}
|
||||
if !proto.Equal(gotInfo, wantInfo) {
|
||||
t.Errorf("unexpected annotations for annotations.proto; got:\n%v\nwant:\n%v",
|
||||
proto.MarshalTextString(gotInfo), proto.MarshalTextString(wantInfo))
|
||||
t.Errorf("unexpected annotations for annotations.proto; got:\n%v\nwant:\n%v", gotInfo, wantInfo)
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ func New(req *pluginpb.CodeGeneratorRequest, opts *Options) (*Plugin, error) {
|
||||
// .proto source file specifying the full import path of the Go package
|
||||
// associated with this file.
|
||||
//
|
||||
// option go_package = "github.com/golang/protobuf/ptypes/any";
|
||||
// option go_package = "google.golang.org/protobuf/types/known/anypb";
|
||||
//
|
||||
// Build systems which want to exert full control over import paths may
|
||||
// specify M<filename>=<import_path> flags.
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
protoV1 "github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/encoding/testprotos/pb2"
|
||||
"google.golang.org/protobuf/encoding/testprotos/pb3"
|
||||
@ -2483,7 +2482,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
if err == nil && tt.wantErr {
|
||||
t.Error("Unmarshal() got nil error, want error\n\n")
|
||||
}
|
||||
if tt.wantMessage != nil && !protoV1.Equal(tt.inputMessage.(protoV1.Message), tt.wantMessage.(protoV1.Message)) {
|
||||
if tt.wantMessage != nil && !proto.Equal(tt.inputMessage, tt.wantMessage) {
|
||||
t.Errorf("Unmarshal()\n<got>\n%v\n<want>\n%v\n", tt.inputMessage, tt.wantMessage)
|
||||
}
|
||||
})
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
protoV1 "github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
pimpl "google.golang.org/protobuf/internal/impl"
|
||||
"google.golang.org/protobuf/internal/scalar"
|
||||
@ -1498,7 +1497,7 @@ type_url: "pb2.Nested"
|
||||
if err == nil && tt.wantErr {
|
||||
t.Error("Unmarshal() got nil error, want error\n\n")
|
||||
}
|
||||
if tt.wantMessage != nil && !protoV1.Equal(tt.inputMessage.(protoV1.Message), tt.wantMessage.(protoV1.Message)) {
|
||||
if tt.wantMessage != nil && !proto.Equal(tt.inputMessage, tt.wantMessage) {
|
||||
t.Errorf("Unmarshal()\n<got>\n%v\n<want>\n%v\n", tt.inputMessage, tt.wantMessage)
|
||||
}
|
||||
})
|
||||
|
@ -7,7 +7,6 @@ package prototext_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
protoV1 "github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/internal/impl"
|
||||
pimpl "google.golang.org/protobuf/internal/impl"
|
||||
@ -240,7 +239,7 @@ func TestRoundTrip(t *testing.T) {
|
||||
t.Errorf("Unmarshal() returned error: %v\n\n", err)
|
||||
}
|
||||
|
||||
if !protoV1.Equal(gotMessage, tt.message.(protoV1.Message)) {
|
||||
if !proto.Equal(gotMessage, tt.message) {
|
||||
t.Errorf("Unmarshal()\n<got>\n%v\n<want>\n%v\n", gotMessage, tt.message)
|
||||
}
|
||||
})
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protodesc"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
|
@ -135,22 +135,22 @@ var testProtos = []testProto{
|
||||
OptionalNestedEnum: test3pb.TestAllTypes_BAR,
|
||||
}, build(
|
||||
&testpb.TestAllExtensions{},
|
||||
extend(testpb.E_OptionalInt32Extension, scalar.Int32(1001)),
|
||||
extend(testpb.E_OptionalInt64Extension, scalar.Int64(1002)),
|
||||
extend(testpb.E_OptionalUint32Extension, scalar.Uint32(1003)),
|
||||
extend(testpb.E_OptionalUint64Extension, scalar.Uint64(1004)),
|
||||
extend(testpb.E_OptionalSint32Extension, scalar.Int32(1005)),
|
||||
extend(testpb.E_OptionalSint64Extension, scalar.Int64(1006)),
|
||||
extend(testpb.E_OptionalFixed32Extension, scalar.Uint32(1007)),
|
||||
extend(testpb.E_OptionalFixed64Extension, scalar.Uint64(1008)),
|
||||
extend(testpb.E_OptionalSfixed32Extension, scalar.Int32(1009)),
|
||||
extend(testpb.E_OptionalSfixed64Extension, scalar.Int64(1010)),
|
||||
extend(testpb.E_OptionalFloatExtension, scalar.Float32(1011.5)),
|
||||
extend(testpb.E_OptionalDoubleExtension, scalar.Float64(1012.5)),
|
||||
extend(testpb.E_OptionalBoolExtension, scalar.Bool(true)),
|
||||
extend(testpb.E_OptionalStringExtension, scalar.String("string")),
|
||||
extend(testpb.E_OptionalInt32Extension, int32(1001)),
|
||||
extend(testpb.E_OptionalInt64Extension, int64(1002)),
|
||||
extend(testpb.E_OptionalUint32Extension, uint32(1003)),
|
||||
extend(testpb.E_OptionalUint64Extension, uint64(1004)),
|
||||
extend(testpb.E_OptionalSint32Extension, int32(1005)),
|
||||
extend(testpb.E_OptionalSint64Extension, int64(1006)),
|
||||
extend(testpb.E_OptionalFixed32Extension, uint32(1007)),
|
||||
extend(testpb.E_OptionalFixed64Extension, uint64(1008)),
|
||||
extend(testpb.E_OptionalSfixed32Extension, int32(1009)),
|
||||
extend(testpb.E_OptionalSfixed64Extension, int64(1010)),
|
||||
extend(testpb.E_OptionalFloatExtension, float32(1011.5)),
|
||||
extend(testpb.E_OptionalDoubleExtension, float64(1012.5)),
|
||||
extend(testpb.E_OptionalBoolExtension, bool(true)),
|
||||
extend(testpb.E_OptionalStringExtension, string("string")),
|
||||
extend(testpb.E_OptionalBytesExtension, []byte("bytes")),
|
||||
extend(testpb.E_OptionalNestedEnumExtension, testpb.TestAllTypes_BAR.Enum()),
|
||||
extend(testpb.E_OptionalNestedEnumExtension, testpb.TestAllTypes_BAR),
|
||||
)},
|
||||
wire: pack.Message{
|
||||
pack.Tag{1, pack.VarintType}, pack.Varint(1001),
|
||||
@ -1370,14 +1370,21 @@ func unknown(raw pref.RawFields) buildOpt {
|
||||
}
|
||||
|
||||
func extend(desc *protoV1.ExtensionDesc, value interface{}) buildOpt {
|
||||
// TODO: Should ExtensionType.ValueOf accept []T instead of *[]T?
|
||||
t := reflect.TypeOf(value)
|
||||
if t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 {
|
||||
v := reflect.New(t)
|
||||
v.Elem().Set(reflect.ValueOf(value))
|
||||
value = v.Interface()
|
||||
}
|
||||
|
||||
return func(m proto.Message) {
|
||||
if err := protoV1.SetExtension(m.(protoV1.Message), desc, value); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
xt := desc.Type
|
||||
m.ProtoReflect().Set(xt, xt.ValueOf(value))
|
||||
}
|
||||
}
|
||||
|
||||
func marshalText(m proto.Message) string {
|
||||
b, _ := prototext.Marshal(m)
|
||||
b, _ := prototext.MarshalOptions{Indent: "\t", AllowPartial: true}.Marshal(m)
|
||||
return string(b)
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
protoV1 "github.com/golang/protobuf/proto"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
@ -38,7 +37,7 @@ func TestEncode(t *testing.T) {
|
||||
AllowPartial: test.partial,
|
||||
}
|
||||
if err := uopts.Unmarshal(wire, got); err != nil {
|
||||
t.Errorf("Unmarshal error: %v\nMessage:\n%v", err, protoV1.MarshalTextString(want.(protoV1.Message)))
|
||||
t.Errorf("Unmarshal error: %v\nMessage:\n%v", err, marshalText(want))
|
||||
return
|
||||
}
|
||||
|
||||
@ -47,7 +46,7 @@ func TestEncode(t *testing.T) {
|
||||
return
|
||||
}
|
||||
if !proto.Equal(got, want) {
|
||||
t.Errorf("Unmarshal returned unexpected result; got:\n%v\nwant:\n%v", protoV1.MarshalTextString(got.(protoV1.Message)), protoV1.MarshalTextString(want.(protoV1.Message)))
|
||||
t.Errorf("Unmarshal returned unexpected result; got:\n%v\nwant:\n%v", marshalText(got), marshalText(want))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -393,16 +393,16 @@ var inequalities = []struct{ a, b proto.Message }{
|
||||
// Extensions.
|
||||
{
|
||||
build(&testpb.TestAllExtensions{},
|
||||
extend(testpb.E_OptionalInt32Extension, scalar.Int32(1)),
|
||||
extend(testpb.E_OptionalInt32Extension, int32(1)),
|
||||
),
|
||||
build(&testpb.TestAllExtensions{},
|
||||
extend(testpb.E_OptionalInt32Extension, scalar.Int32(2)),
|
||||
extend(testpb.E_OptionalInt32Extension, int32(2)),
|
||||
),
|
||||
},
|
||||
{
|
||||
&testpb.TestAllExtensions{},
|
||||
build(&testpb.TestAllExtensions{},
|
||||
extend(testpb.E_OptionalInt32Extension, scalar.Int32(2)),
|
||||
extend(testpb.E_OptionalInt32Extension, int32(2)),
|
||||
),
|
||||
},
|
||||
// Proto2 default values are not considered by Equal, so the following are still unequal.
|
||||
|
Loading…
Reference in New Issue
Block a user