jsonpb: Fix spelling of Marshaler.
The single "l" form is used throughout the adjacent proto package
and the Go standard library.
diff --git a/jsonpb/jsonpb.go b/jsonpb/jsonpb.go
index ef8dff5..fb5e087 100644
--- a/jsonpb/jsonpb.go
+++ b/jsonpb/jsonpb.go
@@ -30,7 +30,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*
-Package jsonpb provides marshalling/unmarshalling functionality between
+Package jsonpb provides marshaling/unmarshaling functionality between
protocol buffer and JSON objects.
Compared to encoding/json, this library:
@@ -56,9 +56,9 @@
byteArrayType = reflect.TypeOf([]byte{})
)
-// Marshaller is a configurable object for converting between
+// Marshaler is a configurable object for converting between
// protocol buffer objects and a JSON representation for them
-type Marshaller struct {
+type Marshaler struct {
// Use string values for enums (as opposed to integer values)
EnumsAsString bool
@@ -70,13 +70,13 @@
}
// Marshal marshals a protocol buffer into JSON.
-func (m *Marshaller) Marshal(out io.Writer, pb proto.Message) error {
+func (m *Marshaler) Marshal(out io.Writer, pb proto.Message) error {
writer := &errWriter{writer: out}
return m.marshalObject(writer, pb, "")
}
// MarshalToString converts a protocol buffer object to JSON string.
-func (m *Marshaller) MarshalToString(pb proto.Message) (string, error) {
+func (m *Marshaler) MarshalToString(pb proto.Message) (string, error) {
var buf bytes.Buffer
if err := m.Marshal(&buf, pb); err != nil {
return "", err
@@ -85,7 +85,7 @@
}
// marshalObject writes a struct to the Writer.
-func (m *Marshaller) marshalObject(out *errWriter, v proto.Message, indent string) error {
+func (m *Marshaler) marshalObject(out *errWriter, v proto.Message, indent string) error {
out.write("{")
if m.Indent != "" {
out.write("\n")
@@ -143,7 +143,7 @@
}
// marshalValue writes the value to the Writer.
-func (m *Marshaller) marshalValue(out *errWriter, v reflect.Value,
+func (m *Marshaler) marshalValue(out *errWriter, v reflect.Value,
structField reflect.StructField, indent string) error {
var err error
@@ -272,7 +272,7 @@
// Unmarshal unmarshals a JSON object stream into a protocol
// buffer. This function is lenient and will decode any options
-// permutations of the related Marshaller.
+// permutations of the related Marshaler.
func Unmarshal(r io.Reader, pb proto.Message) error {
inputValue := json.RawMessage{}
if err := json.NewDecoder(r).Decode(&inputValue); err != nil {
@@ -283,7 +283,7 @@
// UnmarshalString will populate the fields of a protocol buffer based
// on a JSON string. This function is lenient and will decode any options
-// permutations of the related Marshaller.
+// permutations of the related Marshaler.
func UnmarshalString(str string, pb proto.Message) error {
return Unmarshal(bytes.NewReader([]byte(str)), pb)
}
diff --git a/jsonpb/jsonpb_test.go b/jsonpb/jsonpb_test.go
index fe8cd3f..180d5d2 100644
--- a/jsonpb/jsonpb_test.go
+++ b/jsonpb/jsonpb_test.go
@@ -39,9 +39,9 @@
)
var (
- marshaller = Marshaller{}
+ marshaler = Marshaler{}
- marshallerAllOptions = Marshaller{
+ marshalerAllOptions = Marshaler{
EnumsAsString: true,
Indent: " ",
}
@@ -255,56 +255,56 @@
}`
)
-var marshallingTests = []struct {
- desc string
- marshaller Marshaller
- pb proto.Message
- json string
+var marshalingTests = []struct {
+ desc string
+ marshaler Marshaler
+ pb proto.Message
+ json string
}{
- {"simple flat object", marshaller, simpleObject, simpleObjectJSON},
- {"simple pretty object", marshallerAllOptions, simpleObject, simpleObjectPrettyJSON},
- {"repeated fields flat object", marshaller, repeatsObject, repeatsObjectJSON},
- {"repeated fields pretty object", marshallerAllOptions, repeatsObject, repeatsObjectPrettyJSON},
- {"nested message/enum flat object", marshaller, complexObject, complexObjectJSON},
- {"nested message/enum pretty object", marshallerAllOptions, complexObject, complexObjectPrettyJSON},
- {"enum-string flat object", Marshaller{EnumsAsString: true},
+ {"simple flat object", marshaler, simpleObject, simpleObjectJSON},
+ {"simple pretty object", marshalerAllOptions, simpleObject, simpleObjectPrettyJSON},
+ {"repeated fields flat object", marshaler, repeatsObject, repeatsObjectJSON},
+ {"repeated fields pretty object", marshalerAllOptions, repeatsObject, repeatsObjectPrettyJSON},
+ {"nested message/enum flat object", marshaler, complexObject, complexObjectJSON},
+ {"nested message/enum pretty object", marshalerAllOptions, complexObject, complexObjectPrettyJSON},
+ {"enum-string flat object", Marshaler{EnumsAsString: true},
&pb.Widget{Color: pb.Widget_BLUE.Enum()}, `{"color":"BLUE"}`},
- {"enum-value pretty object", Marshaller{Indent: " "},
+ {"enum-value pretty object", Marshaler{Indent: " "},
&pb.Widget{Color: pb.Widget_BLUE.Enum()}, colorPrettyJSON},
- {"unknown enum value object", marshallerAllOptions,
+ {"unknown enum value object", marshalerAllOptions,
&pb.Widget{Color: pb.Widget_Color(1000).Enum(), RColor: []pb.Widget_Color{pb.Widget_RED}}, colorListPrettyJSON},
- {"proto3 object with empty value", marshaller, &pb.Simple3{}, `{"dub":0}`},
- {"map<int64, int32>", marshaller, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`},
- {"map<int64, int32>", marshallerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON},
- {"map<string, string>", marshaller,
+ {"proto3 object with empty value", marshaler, &pb.Simple3{}, `{"dub":0}`},
+ {"map<int64, int32>", marshaler, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`},
+ {"map<int64, int32>", marshalerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON},
+ {"map<string, string>", marshaler,
&pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}},
`{"strry":{"\"one\"":"two","three":"four"}}`},
- {"map<int32, Object>", marshaller,
+ {"map<int32, Object>", marshaler,
&pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}, `{"objjy":{"1":{"dub":1}}}`},
- {"map<int32, Object>", marshallerAllOptions,
+ {"map<int32, Object>", marshalerAllOptions,
&pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}, objjyPrettyJSON},
- {"map<int64, string>", marshaller, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}},
+ {"map<int64, string>", marshaler, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}},
`{"buggy":{"1234":"yup"}}`},
- {"map<bool, bool>", marshaller, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`},
- {"proto2 map<int64, string>", marshaller, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}},
+ {"map<bool, bool>", marshaler, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`},
+ {"proto2 map<int64, string>", marshaler, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}},
`{"m_int64_str":{"213":"cat"}}`},
- {"proto2 map<bool, Object>", marshaller,
+ {"proto2 map<bool, Object>", marshaler,
&pb.Maps{MBoolSimple: map[bool]*pb.Simple{true: &pb.Simple{OInt32: proto.Int32(1)}}},
`{"m_bool_simple":{"true":{"o_int32":1}}}`},
}
-func TestMarshalling(t *testing.T) {
- for _, tt := range marshallingTests {
- json, err := tt.marshaller.MarshalToString(tt.pb)
+func TestMarshaling(t *testing.T) {
+ for _, tt := range marshalingTests {
+ json, err := tt.marshaler.MarshalToString(tt.pb)
if err != nil {
- t.Errorf("%s: marshalling error: %v", tt.desc, err)
+ t.Errorf("%s: marshaling error: %v", tt.desc, err)
} else if tt.json != json {
t.Errorf("%s: got [%v] want [%v]", tt.desc, json, tt.json)
}
}
}
-var unmarshallingTests = []struct {
+var unmarshalingTests = []struct {
desc string
json string
pb proto.Message
@@ -327,8 +327,8 @@
{"map<int32, Object>", `{"objjy":{"1":{"dub":1}}}`, &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}},
}
-func TestUnmarshalling(t *testing.T) {
- for _, tt := range unmarshallingTests {
+func TestUnmarshaling(t *testing.T) {
+ for _, tt := range unmarshalingTests {
// Make a new instance of the type of our expected object.
p := proto.Clone(tt.pb)
p.Reset()
@@ -348,7 +348,7 @@
}
}
-var unmarshallingShouldError = []struct {
+var unmarshalingShouldError = []struct {
desc string
in string
}{
@@ -356,8 +356,8 @@
{"gibberish", "{adskja123;l23=-="},
}
-func TestUnmarshallingBadInput(t *testing.T) {
- for _, tt := range unmarshallingShouldError {
+func TestUnmarshalingBadInput(t *testing.T) {
+ for _, tt := range unmarshalingShouldError {
obj := &pb.Simple{}
err := UnmarshalString(tt.in, obj)
if err == nil {