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>
This commit is contained in:
Damien Neil 2019-05-14 12:44:37 -07:00
parent 934520f5b2
commit 5c5b531562
32 changed files with 169 additions and 141 deletions

View File

@ -10,7 +10,7 @@ import (
"strconv"
"strings"
"google.golang.org/protobuf/protogen"
"google.golang.org/protobuf/compiler/protogen"
descriptorpb "google.golang.org/protobuf/types/descriptor"
)

View File

@ -8,7 +8,7 @@ package main
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() {

View File

@ -16,9 +16,9 @@ import (
"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 @@ func deprecationComment(deprecated bool) string {
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()] {

View File

@ -10,8 +10,8 @@ import (
"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"

View File

@ -11,7 +11,7 @@ import (
"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() {

View File

@ -28,7 +28,7 @@ import (
"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 @@ func (g *GeneratedFile) metaFile(content []byte) (string, error) {
}
}
b, err := textpb.Marshal(info)
b, err := prototext.Marshal(info)
if err != nil {
return "", err
}

View File

@ -11,8 +11,8 @@ import (
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 @@ func BenchmarkTextEncode(b *testing.B) {
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 BenchmarkTextEncode(b *testing.B) {
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 @@ func BenchmarkTextDecode(b *testing.B) {
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 @@ func BenchmarkJSONEncode(b *testing.B) {
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 BenchmarkJSONEncode(b *testing.B) {
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 @@ func BenchmarkJSONDecode(b *testing.B) {
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)

14
encoding/jsonpb/jsonpb.go Normal file
View File

@ -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
)

View File

@ -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 @@ func BenchmarkUnmarshal_Duration(b *testing.B) {
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)
}

View File

@ -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"

View File

@ -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 @@ import (
"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 registerExtension(xd *protoiface.ExtensionDescV1) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
},
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
desc: "Any with missing @type",
umo: jsonpb.UnmarshalOptions{},
umo: protojson.UnmarshalOptions{},
inputMessage: &knownpb.Any{},
inputText: `{
"value": {}
@ -2334,7 +2334,7 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
},
}, {
desc: "DiscardUnknown: regular messages",
umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb3.Nests{},
inputText: `{
"sNested": {
@ -2504,7 +2504,7 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
},
}, {
desc: "DiscardUnknown: map",
umo: jsonpb.UnmarshalOptions{DiscardUnknown: true},
umo: protojson.UnmarshalOptions{DiscardUnknown: true},
inputMessage: &pb3.Maps{},
inputText: `{
"strToNested": {
@ -2536,7 +2536,7 @@ func TestUnmarshal(t *testing.T) {
},
}, {
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 @@ func TestUnmarshal(t *testing.T) {
}(),
}, {
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 @@ func TestUnmarshal(t *testing.T) {
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 @@ func TestUnmarshal(t *testing.T) {
},
}, {
desc: "DiscardUnknown: Any with Empty",
umo: jsonpb.UnmarshalOptions{
umo: protojson.UnmarshalOptions{
DiscardUnknown: true,
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&knownpb.Empty{})),
},

View File

@ -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

View File

@ -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"

View File

@ -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 @@ import (
"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 dhex(s string) []byte {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
}`,
}, {
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 @@ func TestMarshal(t *testing.T) {
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{

View File

@ -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"

View File

@ -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 @@ func (o UnmarshalOptions) Unmarshal(m proto.Message, b []byte) error {
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)

View File

@ -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 @@ import (
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 @@ req_enum: ONE
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 @@ req_nested: {}
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 @@ rpt_nested: {}
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 @@ str_to_nested: {
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 @@ str_to_nested: {
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 @@ value: "some bytes"
},
}, {
desc: "Any expanded",
umo: textpb.UnmarshalOptions{
umo: prototext.UnmarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
inputMessage: &knownpb.Any{},
@ -1420,7 +1420,7 @@ value: "some bytes"
}(),
}, {
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 @@ value: "some bytes"
},
}, {
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 @@ value: "some bytes"
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 @@ value: "some bytes"
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 @@ value: "some bytes"
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 @@ unknown: ""
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{},

View File

@ -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

View File

@ -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"

View File

@ -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 @@ import (
"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 dhex(s string) []byte {
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 @@ req_enum: ONE
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 @@ req_nested: {}
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 @@ req_nested: {}
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 @@ req_nested: {}
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 @@ req_nested: {}
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 @@ opt_int32: 42
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 @@ opt_int32: 42
`,
}, {
desc: "Any not expanded",
mo: textpb.MarshalOptions{
mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(),
},
input: func() proto.Message {
@ -1191,7 +1191,7 @@ value: "\n\x13embedded inside Any\x12\x0b\n\tinception"
`,
}, {
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 @@ value: "\n\x13embedded inside Any\x12\x0b\n\tinception"
`,
}, {
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 @@ value: "\n\x13embedded inside Any\x12\x0b\n\tinception"
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 @@ value: "\n\x13embedded inside Any\x12\x0b\n\tinception"
wantErr: true,
}, {
desc: "Any with invalid value",
mo: textpb.MarshalOptions{
mo: prototext.MarshalOptions{
Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})),
},
input: &knownpb.Any{

View File

@ -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 @@ func TestRoundTrip(t *testing.T) {
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)
}

14
encoding/textpb/textpb.go Normal file
View File

@ -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
)

View File

@ -12,7 +12,7 @@ import (
"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 @@ func handle(req *pb.ConformanceRequest) *pb.ConformanceResponse {
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 @@ func handle(req *pb.ConformanceRequest) *pb.ConformanceResponse {
},
}
case pb.WireFormat_JSON:
p, err := jsonpb.Marshal(msg)
p, err := protojson.Marshal(msg)
if err != nil {
return &pb.ConformanceResponse{
Result: &pb.ConformanceResponse_SerializeError{

View File

@ -21,8 +21,8 @@ import (
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"
)

View File

@ -8,7 +8,7 @@ import (
"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 @@ func (Export) MessageDescriptorOf(m message) pref.MessageDescriptor {
// 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)
}

View File

@ -152,7 +152,7 @@ func LoadEnumDesc(t reflect.Type) pref.EnumDescriptor {
// 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)

View File

@ -230,7 +230,7 @@ type jsonName struct {
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

View File

@ -10,7 +10,7 @@ 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/encoding/pack"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/scalar"
@ -1271,7 +1271,7 @@ func extend(desc *protoV1.ExtensionDesc, value interface{}) buildOpt {
}
func marshalText(m proto.Message) string {
b, _ := textpb.Marshal(m)
b, _ := prototext.Marshal(m)
return string(b)
}

View File

@ -12,7 +12,7 @@ import (
"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 TestMessage(t testing.TB, message proto.Message) {
}
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 @@ func formatValue(v pref.Value) string {
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)
}