protogen, encoding/jsonpb, encoding/textpb: rename packages
Rename encoding/*pb to follow the convention of prefixing package names
with 'proto':
google.golang.org/protobuf/encoding/protojson
google.golang.org/protobuf/encoding/prototext
Move protogen under a compiler/ directory, just in case we ever do add
more compiler-related packages.
google.golang.org/protobuf/compiler/protogen
Change-Id: I31010cb5cabcea8274fffcac468477b58b56e8eb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/177178
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go b/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
index fd14a31..abc9d21 100644
--- a/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
+++ b/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
@@ -10,7 +10,7 @@
"strconv"
"strings"
- "google.golang.org/protobuf/protogen"
+ "google.golang.org/protobuf/compiler/protogen"
descriptorpb "google.golang.org/protobuf/types/descriptor"
)
diff --git a/cmd/protoc-gen-go-grpc/main.go b/cmd/protoc-gen-go-grpc/main.go
index 0d47c14..9cfc159 100644
--- a/cmd/protoc-gen-go-grpc/main.go
+++ b/cmd/protoc-gen-go-grpc/main.go
@@ -8,7 +8,7 @@
import (
"google.golang.org/protobuf/cmd/protoc-gen-go-grpc/internal_gengogrpc"
- "google.golang.org/protobuf/protogen"
+ "google.golang.org/protobuf/compiler/protogen"
)
func main() {
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 801590b..37bdc3d 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -16,9 +16,9 @@
"unicode"
"unicode/utf8"
+ "google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/internal/encoding/tag"
"google.golang.org/protobuf/internal/fieldnum"
- "google.golang.org/protobuf/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
descriptorpb "google.golang.org/protobuf/types/descriptor"
@@ -711,7 +711,7 @@
return "// Deprecated: Do not use."
}
-// TODO: Remove this. This was added to aid jsonpb, but jsonpb does this work
+// TODO: Remove this. This was added to aid protojson, but protojson does this work
// through the use of protobuf reflection now.
func genWellKnownType(g *protogen.GeneratedFile, ptr string, ident protogen.GoIdent, desc protoreflect.Descriptor) {
if wellKnownTypes[desc.FullName()] {
diff --git a/cmd/protoc-gen-go/internal_gengo/reflect.go b/cmd/protoc-gen-go/internal_gengo/reflect.go
index e0a2eb7..d5a8a47 100644
--- a/cmd/protoc-gen-go/internal_gengo/reflect.go
+++ b/cmd/protoc-gen-go/internal_gengo/reflect.go
@@ -10,8 +10,8 @@
"strings"
"unicode/utf8"
+ "google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
- "google.golang.org/protobuf/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
descriptorpb "google.golang.org/protobuf/types/descriptor"
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
index 3b8179d..53770da 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -11,7 +11,7 @@
"flag"
gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
- "google.golang.org/protobuf/protogen"
+ "google.golang.org/protobuf/compiler/protogen"
)
func main() {
diff --git a/protogen/names.go b/compiler/protogen/names.go
similarity index 100%
rename from protogen/names.go
rename to compiler/protogen/names.go
diff --git a/protogen/names_test.go b/compiler/protogen/names_test.go
similarity index 100%
rename from protogen/names_test.go
rename to compiler/protogen/names_test.go
diff --git a/protogen/protogen.go b/compiler/protogen/protogen.go
similarity index 99%
rename from protogen/protogen.go
rename to compiler/protogen/protogen.go
index ceaece0..41500e9 100644
--- a/protogen/protogen.go
+++ b/compiler/protogen/protogen.go
@@ -28,7 +28,7 @@
"strconv"
"strings"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/fieldnum"
"google.golang.org/protobuf/internal/scalar"
"google.golang.org/protobuf/proto"
@@ -1115,7 +1115,7 @@
}
}
- b, err := textpb.Marshal(info)
+ b, err := prototext.Marshal(info)
if err != nil {
return "", err
}
diff --git a/protogen/protogen_test.go b/compiler/protogen/protogen_test.go
similarity index 100%
rename from protogen/protogen_test.go
rename to compiler/protogen/protogen_test.go
diff --git a/encoding/bench_test.go b/encoding/bench_test.go
index 0341b19..5a54130 100644
--- a/encoding/bench_test.go
+++ b/encoding/bench_test.go
@@ -11,8 +11,8 @@
jsonpbV1 "github.com/golang/protobuf/jsonpb"
protoV1 "github.com/golang/protobuf/proto"
- "google.golang.org/protobuf/encoding/jsonpb"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/protojson"
+ "google.golang.org/protobuf/encoding/prototext"
pref "google.golang.org/protobuf/reflect/protoreflect"
tpb "google.golang.org/protobuf/internal/testprotos/test"
@@ -145,7 +145,7 @@
if *benchV1 {
protoV1.MarshalTextString(m)
} else {
- _, err := textpb.MarshalOptions{Indent: " "}.Marshal(m)
+ _, err := prototext.MarshalOptions{Indent: " "}.Marshal(m)
if err != nil {
b.Fatal(err)
}
@@ -155,7 +155,7 @@
func BenchmarkTextDecode(b *testing.B) {
m := makeProto()
- in, err := textpb.MarshalOptions{Indent: " "}.Marshal(m)
+ in, err := prototext.MarshalOptions{Indent: " "}.Marshal(m)
if err != nil {
b.Fatal(err)
}
@@ -166,7 +166,7 @@
if *benchV1 {
err = protoV1.UnmarshalText(string(in), m)
} else {
- err = textpb.Unmarshal(m, in)
+ err = prototext.Unmarshal(m, in)
}
if err != nil {
b.Fatal(err)
@@ -182,7 +182,7 @@
jsm := &jsonpbV1.Marshaler{Indent: " "}
_, err = jsm.MarshalToString(m)
} else {
- _, err = jsonpb.MarshalOptions{Indent: " "}.Marshal(m)
+ _, err = protojson.MarshalOptions{Indent: " "}.Marshal(m)
}
if err != nil {
b.Fatal(err)
@@ -192,7 +192,7 @@
func BenchmarkJSONDecode(b *testing.B) {
m := makeProto()
- out, err := jsonpb.MarshalOptions{Indent: " "}.Marshal(m)
+ out, err := protojson.MarshalOptions{Indent: " "}.Marshal(m)
if err != nil {
b.Fatal(err)
}
@@ -203,7 +203,7 @@
if *benchV1 {
err = jsonpbV1.UnmarshalString(string(out), m)
} else {
- err = jsonpb.Unmarshal(m, out)
+ err = protojson.Unmarshal(m, out)
}
if err != nil {
b.Fatal(err)
diff --git a/encoding/jsonpb/jsonpb.go b/encoding/jsonpb/jsonpb.go
new file mode 100644
index 0000000..43c28b5
--- /dev/null
+++ b/encoding/jsonpb/jsonpb.go
@@ -0,0 +1,14 @@
+// Package jsonpb is deprecated.
+package jsonpb
+
+import "google.golang.org/protobuf/encoding/protojson"
+
+var (
+ Marshal = protojson.Marshal
+ Unmarshal = protojson.Unmarshal
+)
+
+type (
+ MarshalOptions = protojson.MarshalOptions
+ UnmarshalOptions = protojson.UnmarshalOptions
+)
diff --git a/encoding/jsonpb/bench_test.go b/encoding/protojson/bench_test.go
similarity index 75%
rename from encoding/jsonpb/bench_test.go
rename to encoding/protojson/bench_test.go
index 3dcc5e0..595c908 100644
--- a/encoding/jsonpb/bench_test.go
+++ b/encoding/protojson/bench_test.go
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb_test
+package protojson_test
import (
"testing"
- "google.golang.org/protobuf/encoding/jsonpb"
+ "google.golang.org/protobuf/encoding/protojson"
knownpb "google.golang.org/protobuf/types/known"
)
@@ -15,7 +15,7 @@
input := []byte(`"-123456789.123456789s"`)
for i := 0; i < b.N; i++ {
- err := jsonpb.Unmarshal(&knownpb.Duration{}, input)
+ err := protojson.Unmarshal(&knownpb.Duration{}, input)
if err != nil {
b.Fatal(err)
}
diff --git a/encoding/jsonpb/decode.go b/encoding/protojson/decode.go
similarity index 99%
rename from encoding/jsonpb/decode.go
rename to encoding/protojson/decode.go
index 1712bf6..b6c056e 100644
--- a/encoding/jsonpb/decode.go
+++ b/encoding/protojson/decode.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb
+package protojson
import (
"encoding/base64"
diff --git a/encoding/jsonpb/decode_test.go b/encoding/protojson/decode_test.go
similarity index 97%
rename from encoding/jsonpb/decode_test.go
rename to encoding/protojson/decode_test.go
index 0410d53..75b28d3 100644
--- a/encoding/jsonpb/decode_test.go
+++ b/encoding/protojson/decode_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb_test
+package protojson_test
import (
"bytes"
@@ -10,7 +10,7 @@
"testing"
protoV1 "github.com/golang/protobuf/proto"
- "google.golang.org/protobuf/encoding/jsonpb"
+ "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/encoding/testprotos/pb2"
"google.golang.org/protobuf/encoding/testprotos/pb3"
pimpl "google.golang.org/protobuf/internal/impl"
@@ -53,7 +53,7 @@
func TestUnmarshal(t *testing.T) {
tests := []struct {
desc string
- umo jsonpb.UnmarshalOptions
+ umo protojson.UnmarshalOptions
inputMessage proto.Message
inputText string
wantMessage proto.Message
@@ -1065,7 +1065,7 @@
wantErr: true,
}, {
desc: "required fields partially set with AllowPartial",
- umo: jsonpb.UnmarshalOptions{AllowPartial: true},
+ umo: protojson.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.Requireds{},
inputText: `{
"reqBool": false,
@@ -1110,7 +1110,7 @@
wantErr: true,
}, {
desc: "indirect required field with AllowPartial",
- umo: jsonpb.UnmarshalOptions{AllowPartial: true},
+ umo: protojson.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `{
"optNested": {}
@@ -1138,7 +1138,7 @@
wantErr: true,
}, {
desc: "indirect required field in repeated with AllowPartial",
- umo: jsonpb.UnmarshalOptions{AllowPartial: true},
+ umo: protojson.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `{
"rptNested": [
@@ -1176,7 +1176,7 @@
wantErr: true,
}, {
desc: "indirect required field in map with AllowPartial",
- umo: jsonpb.UnmarshalOptions{AllowPartial: true},
+ umo: protojson.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `{
"strToNested": {
@@ -1208,7 +1208,7 @@
wantErr: true,
}, {
desc: "indirect required field in oneof with AllowPartial",
- umo: jsonpb.UnmarshalOptions{AllowPartial: true},
+ umo: protojson.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `{
"oneofNested": {}
@@ -1976,7 +1976,7 @@
wantMessage: &knownpb.Any{},
}, {
desc: "Any with non-custom message",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -2005,7 +2005,7 @@
}(),
}, {
desc: "Any with empty embedded message",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -2013,13 +2013,13 @@
wantMessage: &knownpb.Any{TypeUrl: "foo/pb2.Nested"},
}, {
desc: "Any without registered type",
- umo: jsonpb.UnmarshalOptions{Resolver: preg.NewTypes()},
+ umo: protojson.UnmarshalOptions{Resolver: preg.NewTypes()},
inputMessage: &knownpb.Any{},
inputText: `{"@type": "foo/pb2.Nested"}`,
wantErr: true,
}, {
desc: "Any with missing required error",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
inputMessage: &knownpb.Any{},
@@ -2046,7 +2046,7 @@
wantErr: true,
}, {
desc: "Any with partial required and AllowPartial",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
AllowPartial: true,
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
@@ -2073,7 +2073,7 @@
}(),
}, {
desc: "Any with invalid UTF8",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -2097,7 +2097,7 @@
wantErr: true,
}, {
desc: "Any with BoolValue",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.BoolValue{})),
},
inputMessage: &knownpb.Any{},
@@ -2118,7 +2118,7 @@
}(),
}, {
desc: "Any with Empty",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
inputMessage: &knownpb.Any{},
@@ -2131,7 +2131,7 @@
},
}, {
desc: "Any with missing Empty",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
inputMessage: &knownpb.Any{},
@@ -2141,7 +2141,7 @@
wantErr: true,
}, {
desc: "Any with StringValue containing invalid UTF8",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.StringValue{})),
},
inputMessage: &knownpb.Any{},
@@ -2163,7 +2163,7 @@
wantErr: true,
}, {
desc: "Any with Int64Value",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Int64Value{})),
},
inputMessage: &knownpb.Any{},
@@ -2184,7 +2184,7 @@
}(),
}, {
desc: "Any with invalid Int64Value",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Int64Value{})),
},
inputMessage: &knownpb.Any{},
@@ -2195,7 +2195,7 @@
wantErr: true,
}, {
desc: "Any with invalid UInt64Value",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.UInt64Value{})),
},
inputMessage: &knownpb.Any{},
@@ -2206,7 +2206,7 @@
wantErr: true,
}, {
desc: "Any with Duration",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Duration{})),
},
inputMessage: &knownpb.Any{},
@@ -2227,7 +2227,7 @@
}(),
}, {
desc: "Any with Value of StringValue",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Value{})),
},
inputMessage: &knownpb.Any{},
@@ -2249,7 +2249,7 @@
wantErr: true,
}, {
desc: "Any with Value of NullValue",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Value{})),
},
inputMessage: &knownpb.Any{},
@@ -2270,7 +2270,7 @@
}(),
}, {
desc: "Any with Struct",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(
pimpl.Export{}.MessageTypeOf(&knownpb.Struct{}),
pimpl.Export{}.MessageTypeOf(&knownpb.Value{}),
@@ -2319,7 +2319,7 @@
}(),
}, {
desc: "Any with missing @type",
- umo: jsonpb.UnmarshalOptions{},
+ umo: protojson.UnmarshalOptions{},
inputMessage: &knownpb.Any{},
inputText: `{
"value": {}
@@ -2334,7 +2334,7 @@
wantErr: true,
}, {
desc: "Any with duplicate @type",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(
pimpl.Export{}.MessageTypeOf(&pb2.Nested{}),
pimpl.Export{}.MessageTypeOf(&knownpb.StringValue{}),
@@ -2349,7 +2349,7 @@
wantErr: true,
}, {
desc: "Any with duplicate value",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.StringValue{})),
},
inputMessage: &knownpb.Any{},
@@ -2361,7 +2361,7 @@
wantErr: true,
}, {
desc: "Any with unknown field",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -2373,7 +2373,7 @@
wantErr: true,
}, {
desc: "Any with embedded type containing Any",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(
pimpl.Export{}.MessageTypeOf(&pb2.KnownTypes{}),
pimpl.Export{}.MessageTypeOf(&knownpb.Any{}),
@@ -2411,7 +2411,7 @@
wantErr: true,
}, {
desc: "well known types as field values",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
inputMessage: &pb2.KnownTypes{},
@@ -2490,7 +2490,7 @@
},
}, {
desc: "DiscardUnknown: regular messages",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb3.Nests{},
inputText: `{
"sNested": {
@@ -2504,7 +2504,7 @@
wantMessage: &pb3.Nests{SNested: &pb3.Nested{}},
}, {
desc: "DiscardUnknown: repeated",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb2.Nests{},
inputText: `{
"rptNested": [
@@ -2520,7 +2520,7 @@
},
}, {
desc: "DiscardUnknown: map",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb3.Maps{},
inputText: `{
"strToNested": {
@@ -2536,7 +2536,7 @@
},
}, {
desc: "DiscardUnknown: extension",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb2.Extensions{},
inputText: `{
"[pb2.opt_ext_nested]": {
@@ -2550,13 +2550,13 @@
}(),
}, {
desc: "DiscardUnknown: Empty",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &knownpb.Empty{},
inputText: `{"unknown": "something"}`,
wantMessage: &knownpb.Empty{},
}, {
desc: "DiscardUnknown: Any without type",
- umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
+ umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &knownpb.Any{},
inputText: `{
"value": {"foo": "bar"},
@@ -2565,7 +2565,7 @@
wantMessage: &knownpb.Any{},
}, {
desc: "DiscardUnknown: Any",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
DiscardUnknown: true,
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
@@ -2579,7 +2579,7 @@
},
}, {
desc: "DiscardUnknown: Any with Empty",
- umo: jsonpb.UnmarshalOptions{
+ umo: protojson.UnmarshalOptions{
DiscardUnknown: true,
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
diff --git a/encoding/jsonpb/doc.go b/encoding/protojson/doc.go
similarity index 81%
rename from encoding/jsonpb/doc.go
rename to encoding/protojson/doc.go
index 99cf2dd..00ea2fe 100644
--- a/encoding/jsonpb/doc.go
+++ b/encoding/protojson/doc.go
@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Package jsonpb marshals and unmarshals protocol buffer messages as JSON
+// Package protojson marshals and unmarshals protocol buffer messages as JSON
// format. It follows the guide at
// https://developers.google.com/protocol-buffers/docs/proto3#json.
//
// This package produces a different output than the standard "encoding/json"
// package, which does not operate correctly on protocol buffer messages.
-package jsonpb
+package protojson
diff --git a/encoding/jsonpb/encode.go b/encoding/protojson/encode.go
similarity index 99%
rename from encoding/jsonpb/encode.go
rename to encoding/protojson/encode.go
index 1d353b7..bd0ee3d 100644
--- a/encoding/jsonpb/encode.go
+++ b/encoding/protojson/encode.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb
+package protojson
import (
"encoding/base64"
diff --git a/encoding/jsonpb/encode_test.go b/encoding/protojson/encode_test.go
similarity index 97%
rename from encoding/jsonpb/encode_test.go
rename to encoding/protojson/encode_test.go
index 6043209..c652118 100644
--- a/encoding/jsonpb/encode_test.go
+++ b/encoding/protojson/encode_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb_test
+package protojson_test
import (
"bytes"
@@ -13,7 +13,7 @@
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
- "google.golang.org/protobuf/encoding/jsonpb"
+ "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/encoding/wire"
pimpl "google.golang.org/protobuf/internal/impl"
@@ -67,7 +67,7 @@
func TestMarshal(t *testing.T) {
tests := []struct {
desc string
- mo jsonpb.MarshalOptions
+ mo protojson.MarshalOptions
input proto.Message
want string
wantErr bool // TODO: Verify error message substring.
@@ -749,7 +749,7 @@
wantErr: true,
}, {
desc: "required fields not set with AllowPartial",
- mo: jsonpb.MarshalOptions{AllowPartial: true},
+ mo: protojson.MarshalOptions{AllowPartial: true},
input: &pb2.Requireds{
ReqBool: scalar.Bool(false),
ReqSfixed64: scalar.Int64(0),
@@ -793,7 +793,7 @@
wantErr: true,
}, {
desc: "indirect required field with AllowPartial",
- mo: jsonpb.MarshalOptions{AllowPartial: true},
+ mo: protojson.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
OptNested: &pb2.NestedWithRequired{},
},
@@ -821,7 +821,7 @@
wantErr: true,
}, {
desc: "indirect required field in repeated with AllowPartial",
- mo: jsonpb.MarshalOptions{AllowPartial: true},
+ mo: protojson.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
RptNested: []*pb2.NestedWithRequired{
&pb2.NestedWithRequired{},
@@ -853,7 +853,7 @@
wantErr: true,
}, {
desc: "indirect required field in map with AllowPartial",
- mo: jsonpb.MarshalOptions{AllowPartial: true},
+ mo: protojson.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
StrToNested: map[string]*pb2.NestedWithRequired{
"fail": &pb2.NestedWithRequired{},
@@ -877,7 +877,7 @@
wantErr: true,
}, {
desc: "indirect required field in oneof with AllowPartial",
- mo: jsonpb.MarshalOptions{AllowPartial: true},
+ mo: protojson.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
Union: &pb2.IndirectRequired_OneofNested{
OneofNested: &pb2.NestedWithRequired{},
@@ -1531,7 +1531,7 @@
want: `{}`,
}, {
desc: "Any with non-custom message",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: func() proto.Message {
@@ -1559,7 +1559,7 @@
}`,
}, {
desc: "Any with empty embedded message",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: &knownpb.Any{TypeUrl: "foo/pb2.Nested"},
@@ -1568,12 +1568,12 @@
}`,
}, {
desc: "Any without registered type",
- mo: jsonpb.MarshalOptions{Resolver: preg.NewTypes()},
+ mo: protojson.MarshalOptions{Resolver: preg.NewTypes()},
input: &knownpb.Any{TypeUrl: "foo/pb2.Nested"},
wantErr: true,
}, {
desc: "Any with missing required error",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
input: func() proto.Message {
@@ -1599,7 +1599,7 @@
wantErr: true,
}, {
desc: "Any with partial required and AllowPartial",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
AllowPartial: true,
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
@@ -1625,7 +1625,7 @@
}`,
}, {
desc: "Any with invalid UTF8",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: func() proto.Message {
@@ -1648,7 +1648,7 @@
wantErr: true,
}, {
desc: "Any with invalid value",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: &knownpb.Any{
@@ -1658,7 +1658,7 @@
wantErr: true,
}, {
desc: "Any with BoolValue",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.BoolValue{})),
},
input: func() proto.Message {
@@ -1678,7 +1678,7 @@
}`,
}, {
desc: "Any with Empty",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
input: func() proto.Message {
@@ -1698,7 +1698,7 @@
}`,
}, {
desc: "Any with StringValue containing invalid UTF8",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.StringValue{})),
},
input: func() proto.Message {
@@ -1719,7 +1719,7 @@
wantErr: true,
}, {
desc: "Any with Int64Value",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Int64Value{})),
},
input: func() proto.Message {
@@ -1739,7 +1739,7 @@
}`,
}, {
desc: "Any with Duration",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Duration{})),
},
input: func() proto.Message {
@@ -1759,7 +1759,7 @@
}`,
}, {
desc: "Any with empty Value",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Value{})),
},
input: func() proto.Message {
@@ -1776,7 +1776,7 @@
wantErr: true,
}, {
desc: "Any with Value of StringValue",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Value{})),
},
input: func() proto.Message {
@@ -1797,7 +1797,7 @@
wantErr: true,
}, {
desc: "Any with Value of NullValue",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Value{})),
},
input: func() proto.Message {
@@ -1817,7 +1817,7 @@
}`,
}, {
desc: "Any with Struct",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(
pimpl.Export{}.MessageTypeOf(&knownpb.Struct{}),
pimpl.Export{}.MessageTypeOf(&knownpb.Value{}),
@@ -1865,7 +1865,7 @@
}`,
}, {
desc: "Any with missing type_url",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.BoolValue{})),
},
input: func() proto.Message {
@@ -1881,7 +1881,7 @@
wantErr: true,
}, {
desc: "well known types as field values",
- mo: jsonpb.MarshalOptions{
+ mo: protojson.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},
input: &pb2.KnownTypes{
diff --git a/encoding/jsonpb/well_known_types.go b/encoding/protojson/well_known_types.go
similarity index 99%
rename from encoding/jsonpb/well_known_types.go
rename to encoding/protojson/well_known_types.go
index c3ca47e..6aedebd 100644
--- a/encoding/jsonpb/well_known_types.go
+++ b/encoding/protojson/well_known_types.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package jsonpb
+package protojson
import (
"bytes"
diff --git a/encoding/textpb/decode.go b/encoding/prototext/decode.go
similarity index 98%
rename from encoding/textpb/decode.go
rename to encoding/prototext/decode.go
index 88ac20e..f9263bd 100644
--- a/encoding/textpb/decode.go
+++ b/encoding/prototext/decode.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package textpb
+package prototext
import (
"fmt"
@@ -46,7 +46,7 @@
mr := m.ProtoReflect()
// Clear all fields before populating it.
- // TODO: Determine if this needs to be consistent with jsonpb and binary unmarshal where
+ // TODO: Determine if this needs to be consistent with protojson and binary unmarshal where
// behavior is to merge values into existing message. If decision is to not clear the fields
// ahead, code will need to be updated properly when merging nested messages.
resetMessage(mr)
diff --git a/encoding/textpb/decode_test.go b/encoding/prototext/decode_test.go
similarity index 97%
rename from encoding/textpb/decode_test.go
rename to encoding/prototext/decode_test.go
index d1e7b14..4837117 100644
--- a/encoding/textpb/decode_test.go
+++ b/encoding/prototext/decode_test.go
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package textpb_test
+package prototext_test
import (
"math"
"testing"
protoV1 "github.com/golang/protobuf/proto"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/errors"
pimpl "google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/internal/scalar"
@@ -24,7 +24,7 @@
func TestUnmarshal(t *testing.T) {
tests := []struct {
desc string
- umo textpb.UnmarshalOptions
+ umo prototext.UnmarshalOptions
inputMessage proto.Message
inputText string
wantMessage proto.Message
@@ -1001,7 +1001,7 @@
wantErr: true,
}, {
desc: "required fields partially set with AllowPartial",
- umo: textpb.UnmarshalOptions{AllowPartial: true},
+ umo: prototext.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.Requireds{},
inputText: `
req_bool: false
@@ -1044,7 +1044,7 @@
wantErr: true,
}, {
desc: "indirect required field with AllowPartial",
- umo: textpb.UnmarshalOptions{AllowPartial: true},
+ umo: prototext.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: "opt_nested: {}",
wantMessage: &pb2.IndirectRequired{
@@ -1070,7 +1070,7 @@
wantErr: true,
}, {
desc: "indirect required field in repeated with AllowPartial",
- umo: textpb.UnmarshalOptions{AllowPartial: true},
+ umo: prototext.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `
rpt_nested: {
@@ -1111,7 +1111,7 @@
wantErr: true,
}, {
desc: "indirect required field in map with AllowPartial",
- umo: textpb.UnmarshalOptions{AllowPartial: true},
+ umo: prototext.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `
str_to_nested: {
@@ -1145,7 +1145,7 @@
wantErr: true,
}, {
desc: "indirect required field in oneof with AllowPartial",
- umo: textpb.UnmarshalOptions{AllowPartial: true},
+ umo: prototext.UnmarshalOptions{AllowPartial: true},
inputMessage: &pb2.IndirectRequired{},
inputText: `oneof_nested: {}
`,
@@ -1390,7 +1390,7 @@
},
}, {
desc: "Any expanded",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -1420,7 +1420,7 @@
}(),
}, {
desc: "Any expanded with empty value",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -1430,7 +1430,7 @@
},
}, {
desc: "Any expanded with missing required error",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
inputMessage: &knownpb.Any{},
@@ -1458,7 +1458,7 @@
wantErr: true,
}, {
desc: "Any with invalid UTF-8",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb3.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -1484,13 +1484,13 @@
wantErr: true,
}, {
desc: "Any expanded with unregistered type",
- umo: textpb.UnmarshalOptions{Resolver: preg.NewTypes()},
+ umo: prototext.UnmarshalOptions{Resolver: preg.NewTypes()},
inputMessage: &knownpb.Any{},
inputText: `[SomeMessage]: {}`,
wantErr: true,
}, {
desc: "Any expanded with invalid value",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -1498,7 +1498,7 @@
wantErr: true,
}, {
desc: "Any expanded with unknown fields",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@@ -1509,7 +1509,7 @@
wantErr: true,
}, {
desc: "Any contains expanded and unexpanded fields",
- umo: textpb.UnmarshalOptions{
+ umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
diff --git a/encoding/textpb/doc.go b/encoding/prototext/doc.go
similarity index 65%
rename from encoding/textpb/doc.go
rename to encoding/prototext/doc.go
index ea97703..162b4f9 100644
--- a/encoding/textpb/doc.go
+++ b/encoding/prototext/doc.go
@@ -2,6 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Package textpb marshals and unmarshals protocol buffer messages as the
+// Package prototext marshals and unmarshals protocol buffer messages as the
// textproto format.
-package textpb
+package prototext
diff --git a/encoding/textpb/encode.go b/encoding/prototext/encode.go
similarity index 99%
rename from encoding/textpb/encode.go
rename to encoding/prototext/encode.go
index 3964a33..8f06370 100644
--- a/encoding/textpb/encode.go
+++ b/encoding/prototext/encode.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package textpb
+package prototext
import (
"fmt"
diff --git a/encoding/textpb/encode_test.go b/encoding/prototext/encode_test.go
similarity index 97%
rename from encoding/textpb/encode_test.go
rename to encoding/prototext/encode_test.go
index 03872e1..b2fc57b 100644
--- a/encoding/textpb/encode_test.go
+++ b/encoding/prototext/encode_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package textpb_test
+package prototext_test
import (
"bytes"
@@ -13,7 +13,7 @@
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/detrand"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/encoding/wire"
@@ -73,7 +73,7 @@
func TestMarshal(t *testing.T) {
tests := []struct {
desc string
- mo textpb.MarshalOptions
+ mo prototext.MarshalOptions
input proto.Message
want string
wantErr bool // TODO: Verify error message content.
@@ -761,7 +761,7 @@
wantErr: true,
}, {
desc: "required fields not set with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: &pb2.Requireds{
ReqBool: scalar.Bool(false),
ReqSfixed64: scalar.Int64(0xbeefcafe),
@@ -801,7 +801,7 @@
wantErr: true,
}, {
desc: "indirect required field with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
OptNested: &pb2.NestedWithRequired{},
},
@@ -823,7 +823,7 @@
wantErr: true,
}, {
desc: "indirect required field in repeated with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
RptNested: []*pb2.NestedWithRequired{
&pb2.NestedWithRequired{},
@@ -851,7 +851,7 @@
wantErr: true,
}, {
desc: "indirect required field in map with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
StrToNested: map[string]*pb2.NestedWithRequired{
"fail": &pb2.NestedWithRequired{},
@@ -873,7 +873,7 @@
wantErr: true,
}, {
desc: "indirect required field in oneof with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: &pb2.IndirectRequired{
Union: &pb2.IndirectRequired_OneofNested{
OneofNested: &pb2.NestedWithRequired{},
@@ -1006,7 +1006,7 @@
wantErr: true,
}, {
desc: "extension partial with AllowPartial",
- mo: textpb.MarshalOptions{AllowPartial: true},
+ mo: prototext.MarshalOptions{AllowPartial: true},
input: func() proto.Message {
m := &pb2.Extensions{}
setExtension(m, pb2.E_OptExtPartial, &pb2.PartialRequired{
@@ -1167,7 +1167,7 @@
`,
}, {
desc: "Any not expanded",
- mo: textpb.MarshalOptions{
+ mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(),
},
input: func() proto.Message {
@@ -1191,7 +1191,7 @@
`,
}, {
desc: "Any expanded",
- mo: textpb.MarshalOptions{
+ mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: func() proto.Message {
@@ -1219,7 +1219,7 @@
`,
}, {
desc: "Any expanded with missing required error",
- mo: textpb.MarshalOptions{
+ mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})),
},
input: func() proto.Message {
@@ -1245,7 +1245,7 @@
wantErr: true,
}, {
desc: "Any with invalid UTF-8",
- mo: textpb.MarshalOptions{
+ mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb3.Nested{})),
},
input: func() proto.Message {
@@ -1268,7 +1268,7 @@
wantErr: true,
}, {
desc: "Any with invalid value",
- mo: textpb.MarshalOptions{
+ mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: &knownpb.Any{
diff --git a/encoding/textpb/other_test.go b/encoding/prototext/other_test.go
similarity index 95%
rename from encoding/textpb/other_test.go
rename to encoding/prototext/other_test.go
index 008c090..4819f7d 100644
--- a/encoding/textpb/other_test.go
+++ b/encoding/prototext/other_test.go
@@ -1,10 +1,10 @@
-package textpb_test
+package prototext_test
import (
"testing"
protoV1 "github.com/golang/protobuf/proto"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/impl"
pimpl "google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/internal/scalar"
@@ -220,13 +220,13 @@
tt := tt
t.Run(tt.desc, func(t *testing.T) {
t.Parallel()
- b, err := textpb.MarshalOptions{Resolver: tt.resolver}.Marshal(tt.message)
+ b, err := prototext.MarshalOptions{Resolver: tt.resolver}.Marshal(tt.message)
if err != nil {
t.Errorf("Marshal() returned error: %v\n\n", err)
}
gotMessage := new(pb2.KnownTypes)
- err = textpb.UnmarshalOptions{Resolver: tt.resolver}.Unmarshal(gotMessage, b)
+ err = prototext.UnmarshalOptions{Resolver: tt.resolver}.Unmarshal(gotMessage, b)
if err != nil {
t.Errorf("Unmarshal() returned error: %v\n\n", err)
}
diff --git a/encoding/textpb/textpb.go b/encoding/textpb/textpb.go
new file mode 100644
index 0000000..ba2c9ea
--- /dev/null
+++ b/encoding/textpb/textpb.go
@@ -0,0 +1,14 @@
+// Package textpb is deprecated.
+package textpb
+
+import "google.golang.org/protobuf/encoding/prototext"
+
+var (
+ Marshal = prototext.Marshal
+ Unmarshal = prototext.Unmarshal
+)
+
+type (
+ MarshalOptions = prototext.MarshalOptions
+ UnmarshalOptions = prototext.UnmarshalOptions
+)
diff --git a/internal/cmd/conformance/main.go b/internal/cmd/conformance/main.go
index 6783c16..5262376 100644
--- a/internal/cmd/conformance/main.go
+++ b/internal/cmd/conformance/main.go
@@ -12,7 +12,7 @@
"log"
"os"
- "google.golang.org/protobuf/encoding/jsonpb"
+ "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
pb "google.golang.org/protobuf/internal/testprotos/conformance"
@@ -69,7 +69,7 @@
case *pb.ConformanceRequest_ProtobufPayload:
err = proto.Unmarshal(p.ProtobufPayload, msg)
case *pb.ConformanceRequest_JsonPayload:
- err = jsonpb.UnmarshalOptions{
+ err = protojson.UnmarshalOptions{
DiscardUnknown: req.TestCategory == pb.TestCategory_JSON_IGNORE_UNKNOWN_PARSING_TEST,
}.Unmarshal(msg, []byte(p.JsonPayload))
default:
@@ -103,7 +103,7 @@
},
}
case pb.WireFormat_JSON:
- p, err := jsonpb.Marshal(msg)
+ p, err := protojson.Marshal(msg)
if err != nil {
return &pb.ConformanceResponse{
Result: &pb.ConformanceResponse_SerializeError{
diff --git a/internal/cmd/generate-protos/main.go b/internal/cmd/generate-protos/main.go
index 1763a92..3ab6c30 100644
--- a/internal/cmd/generate-protos/main.go
+++ b/internal/cmd/generate-protos/main.go
@@ -21,8 +21,8 @@
gengogrpc "google.golang.org/protobuf/cmd/protoc-gen-go-grpc/internal_gengogrpc"
gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
+ "google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/internal/detrand"
- "google.golang.org/protobuf/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
)
diff --git a/internal/impl/export.go b/internal/impl/export.go
index ae0e9fa..9ea3900 100644
--- a/internal/impl/export.go
+++ b/internal/impl/export.go
@@ -8,7 +8,7 @@
"reflect"
"strconv"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
pref "google.golang.org/protobuf/reflect/protoreflect"
)
@@ -111,6 +111,6 @@
// MessageStringOf returns the message value as a string,
// which is the message serialized in the protobuf text format.
func (Export) MessageStringOf(m pref.ProtoMessage) string {
- b, _ := textpb.MarshalOptions{AllowPartial: true}.Marshal(m)
+ b, _ := prototext.MarshalOptions{AllowPartial: true}.Marshal(m)
return string(b)
}
diff --git a/internal/legacy/enum.go b/internal/legacy/enum.go
index 67a43f9..d750f1e 100644
--- a/internal/legacy/enum.go
+++ b/internal/legacy/enum.go
@@ -152,7 +152,7 @@
// golang/protobuf so the enum may not even be found in the registry.
//
// Instead, create a bogus enum descriptor to ensure that
- // most operations continue to work. For example, textpb and jsonpb
+ // most operations continue to work. For example, prototext and protojson
// will be unable to parse a message with an enum value by name.
e.Syntax = pref.Proto2
e.FullName = deriveFullName(t)
diff --git a/internal/prototype/protofile_type.go b/internal/prototype/protofile_type.go
index cf96277..99b0a53 100644
--- a/internal/prototype/protofile_type.go
+++ b/internal/prototype/protofile_type.go
@@ -230,7 +230,7 @@
func (p *jsonName) lazyInit(f *Field) string {
p.once.Do(func() {
- // TODO: We may need to share this logic with jsonpb for implementation
+ // TODO: We may need to share this logic with protojson for implementation
// of the FieldMask well-known type.
if f.JSONName != "" {
p.name = f.JSONName
diff --git a/proto/decode_test.go b/proto/decode_test.go
index c1810c5..47dfdb4 100644
--- a/proto/decode_test.go
+++ b/proto/decode_test.go
@@ -10,7 +10,7 @@
"testing"
protoV1 "github.com/golang/protobuf/proto"
- "google.golang.org/protobuf/encoding/textpb"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/scalar"
@@ -1271,7 +1271,7 @@
}
func marshalText(m proto.Message) string {
- b, _ := textpb.Marshal(m)
+ b, _ := prototext.Marshal(m)
return string(b)
}
diff --git a/testing/prototest/prototest.go b/testing/prototest/prototest.go
index c9f7c7a..c24a811 100644
--- a/testing/prototest/prototest.go
+++ b/testing/prototest/prototest.go
@@ -12,7 +12,7 @@
"sort"
"testing"
- textpb "google.golang.org/protobuf/encoding/textpb"
+ prototext "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
pref "google.golang.org/protobuf/reflect/protoreflect"
)
@@ -83,7 +83,7 @@
}
func marshalText(m proto.Message) string {
- b, _ := textpb.MarshalOptions{Indent: " "}.Marshal(m)
+ b, _ := prototext.MarshalOptions{Indent: " "}.Marshal(m)
return string(b)
}
@@ -346,7 +346,7 @@
buf.WriteString("]")
return buf.String()
case pref.Message:
- b, err := textpb.Marshal(v.Interface())
+ b, err := prototext.Marshal(v.Interface())
if err != nil {
return fmt.Sprintf("<%v>", err)
}