Bläddra i källkod

goprotobuf: Completely omit XXX_ fields from proto JSON output.

R=r
CC=golang-dev
http://codereview.appspot.com/5885053
David Symonds 14 år sedan
förälder
incheckning
fd08ece8ed

+ 2 - 3
protoc-gen-go/generator/generator.go

@@ -1167,11 +1167,10 @@ func (g *Generator) generateMessage(message *Descriptor) {
 		g.P(fieldname, "\t", typename, "\t", tag)
 		g.P(fieldname, "\t", typename, "\t", tag)
 		g.RecordTypeUse(proto.GetString(field.TypeName))
 		g.RecordTypeUse(proto.GetString(field.TypeName))
 	}
 	}
-	// TODO: Use `json:"-"` for these XXX_ fields when that makes it into a Go release.
 	if len(message.ExtensionRange) > 0 {
 	if len(message.ExtensionRange) > 0 {
-		g.P("XXX_extensions\t\tmap[int32]", g.ProtoPkg, ".Extension `json:\",omitempty\"`")
+		g.P("XXX_extensions\t\tmap[int32]", g.ProtoPkg, ".Extension `json:\"-\"`")
 	}
 	}
-	g.P("XXX_unrecognized\t[]byte `json:\",omitempty\"`")
+	g.P("XXX_unrecognized\t[]byte `json:\"-\"`")
 	g.Out()
 	g.Out()
 	g.P("}")
 	g.P("}")
 
 

+ 8 - 8
protoc-gen-go/testdata/my_test/test.pb.go

@@ -121,7 +121,7 @@ type Request struct {
 	Deadline         *float32           `protobuf:"fixed32,7,opt,name=deadline,def=inf" json:"deadline,omitempty"`
 	Deadline         *float32           `protobuf:"fixed32,7,opt,name=deadline,def=inf" json:"deadline,omitempty"`
 	Somegroup        *Request_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
 	Somegroup        *Request_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
 	Reset_           *int32             `protobuf:"varint,12,opt,name=reset" json:"reset,omitempty"`
 	Reset_           *int32             `protobuf:"varint,12,opt,name=reset" json:"reset,omitempty"`
-	XXX_unrecognized []byte             `json:",omitempty"`
+	XXX_unrecognized []byte             `json:"-"`
 }
 }
 
 
 func (this *Request) Reset()         { *this = Request{} }
 func (this *Request) Reset()         { *this = Request{} }
@@ -133,7 +133,7 @@ var Default_Request_Deadline float32 = float32(math.Inf(1))
 
 
 type Request_SomeGroup struct {
 type Request_SomeGroup struct {
 	GroupField       *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
 	GroupField       *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
-	XXX_unrecognized []byte `json:",omitempty"`
+	XXX_unrecognized []byte `json:"-"`
 }
 }
 
 
 func (this *Request_SomeGroup) Reset()         { *this = Request_SomeGroup{} }
 func (this *Request_SomeGroup) Reset()         { *this = Request_SomeGroup{} }
@@ -142,8 +142,8 @@ func (this *Request_SomeGroup) String() string { return proto.CompactTextString(
 type Reply struct {
 type Reply struct {
 	Found            []*Reply_Entry            `protobuf:"bytes,1,rep,name=found" json:"found,omitempty"`
 	Found            []*Reply_Entry            `protobuf:"bytes,1,rep,name=found" json:"found,omitempty"`
 	CompactKeys      []int32                   `protobuf:"varint,2,rep,packed,name=compact_keys" json:"compact_keys,omitempty"`
 	CompactKeys      []int32                   `protobuf:"varint,2,rep,packed,name=compact_keys" json:"compact_keys,omitempty"`
-	XXX_extensions   map[int32]proto.Extension `json:",omitempty"`
-	XXX_unrecognized []byte                    `json:",omitempty"`
+	XXX_extensions   map[int32]proto.Extension `json:"-"`
+	XXX_unrecognized []byte                    `json:"-"`
 }
 }
 
 
 func (this *Reply) Reset()         { *this = Reply{} }
 func (this *Reply) Reset()         { *this = Reply{} }
@@ -167,7 +167,7 @@ type Reply_Entry struct {
 	KeyThatNeeds_1234Camel_CasIng *int64 `protobuf:"varint,1,req,name=key_that_needs_1234camel_CasIng" json:"key_that_needs_1234camel_CasIng,omitempty"`
 	KeyThatNeeds_1234Camel_CasIng *int64 `protobuf:"varint,1,req,name=key_that_needs_1234camel_CasIng" json:"key_that_needs_1234camel_CasIng,omitempty"`
 	Value                         *int64 `protobuf:"varint,2,opt,name=value,def=7" json:"value,omitempty"`
 	Value                         *int64 `protobuf:"varint,2,opt,name=value,def=7" json:"value,omitempty"`
 	XMyFieldName_2                *int64 `protobuf:"varint,3,opt,name=_my_field_name_2" json:"_my_field_name_2,omitempty"`
 	XMyFieldName_2                *int64 `protobuf:"varint,3,opt,name=_my_field_name_2" json:"_my_field_name_2,omitempty"`
-	XXX_unrecognized              []byte `json:",omitempty"`
+	XXX_unrecognized              []byte `json:"-"`
 }
 }
 
 
 func (this *Reply_Entry) Reset()         { *this = Reply_Entry{} }
 func (this *Reply_Entry) Reset()         { *this = Reply_Entry{} }
@@ -176,7 +176,7 @@ func (this *Reply_Entry) String() string { return proto.CompactTextString(this)
 const Default_Reply_Entry_Value int64 = 7
 const Default_Reply_Entry_Value int64 = 7
 
 
 type ReplyExtensions struct {
 type ReplyExtensions struct {
-	XXX_unrecognized []byte `json:",omitempty"`
+	XXX_unrecognized []byte `json:"-"`
 }
 }
 
 
 func (this *ReplyExtensions) Reset()         { *this = ReplyExtensions{} }
 func (this *ReplyExtensions) Reset()         { *this = ReplyExtensions{} }
@@ -191,8 +191,8 @@ var E_ReplyExtensions_Time = &proto.ExtensionDesc{
 }
 }
 
 
 type OldReply struct {
 type OldReply struct {
-	XXX_extensions   map[int32]proto.Extension `json:",omitempty"`
-	XXX_unrecognized []byte                    `json:",omitempty"`
+	XXX_extensions   map[int32]proto.Extension `json:"-"`
+	XXX_unrecognized []byte                    `json:"-"`
 }
 }
 
 
 func (this *OldReply) Reset()         { *this = OldReply{} }
 func (this *OldReply) Reset()         { *this = OldReply{} }

+ 8 - 8
protoc-gen-go/testdata/my_test/test.pb.go.golden

@@ -121,7 +121,7 @@ type Request struct {
 	Deadline         *float32           `protobuf:"fixed32,7,opt,name=deadline,def=inf" json:"deadline,omitempty"`
 	Deadline         *float32           `protobuf:"fixed32,7,opt,name=deadline,def=inf" json:"deadline,omitempty"`
 	Somegroup        *Request_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
 	Somegroup        *Request_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
 	Reset_           *int32             `protobuf:"varint,12,opt,name=reset" json:"reset,omitempty"`
 	Reset_           *int32             `protobuf:"varint,12,opt,name=reset" json:"reset,omitempty"`
-	XXX_unrecognized []byte             `json:",omitempty"`
+	XXX_unrecognized []byte             `json:"-"`
 }
 }
 
 
 func (this *Request) Reset()         { *this = Request{} }
 func (this *Request) Reset()         { *this = Request{} }
@@ -133,7 +133,7 @@ var Default_Request_Deadline float32 = float32(math.Inf(1))
 
 
 type Request_SomeGroup struct {
 type Request_SomeGroup struct {
 	GroupField       *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
 	GroupField       *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
-	XXX_unrecognized []byte `json:",omitempty"`
+	XXX_unrecognized []byte `json:"-"`
 }
 }
 
 
 func (this *Request_SomeGroup) Reset()         { *this = Request_SomeGroup{} }
 func (this *Request_SomeGroup) Reset()         { *this = Request_SomeGroup{} }
@@ -142,8 +142,8 @@ func (this *Request_SomeGroup) String() string { return proto.CompactTextString(
 type Reply struct {
 type Reply struct {
 	Found            []*Reply_Entry            `protobuf:"bytes,1,rep,name=found" json:"found,omitempty"`
 	Found            []*Reply_Entry            `protobuf:"bytes,1,rep,name=found" json:"found,omitempty"`
 	CompactKeys      []int32                   `protobuf:"varint,2,rep,packed,name=compact_keys" json:"compact_keys,omitempty"`
 	CompactKeys      []int32                   `protobuf:"varint,2,rep,packed,name=compact_keys" json:"compact_keys,omitempty"`
-	XXX_extensions   map[int32]proto.Extension `json:",omitempty"`
-	XXX_unrecognized []byte                    `json:",omitempty"`
+	XXX_extensions   map[int32]proto.Extension `json:"-"`
+	XXX_unrecognized []byte                    `json:"-"`
 }
 }
 
 
 func (this *Reply) Reset()         { *this = Reply{} }
 func (this *Reply) Reset()         { *this = Reply{} }
@@ -167,7 +167,7 @@ type Reply_Entry struct {
 	KeyThatNeeds_1234Camel_CasIng *int64 `protobuf:"varint,1,req,name=key_that_needs_1234camel_CasIng" json:"key_that_needs_1234camel_CasIng,omitempty"`
 	KeyThatNeeds_1234Camel_CasIng *int64 `protobuf:"varint,1,req,name=key_that_needs_1234camel_CasIng" json:"key_that_needs_1234camel_CasIng,omitempty"`
 	Value                         *int64 `protobuf:"varint,2,opt,name=value,def=7" json:"value,omitempty"`
 	Value                         *int64 `protobuf:"varint,2,opt,name=value,def=7" json:"value,omitempty"`
 	XMyFieldName_2                *int64 `protobuf:"varint,3,opt,name=_my_field_name_2" json:"_my_field_name_2,omitempty"`
 	XMyFieldName_2                *int64 `protobuf:"varint,3,opt,name=_my_field_name_2" json:"_my_field_name_2,omitempty"`
-	XXX_unrecognized              []byte `json:",omitempty"`
+	XXX_unrecognized              []byte `json:"-"`
 }
 }
 
 
 func (this *Reply_Entry) Reset()         { *this = Reply_Entry{} }
 func (this *Reply_Entry) Reset()         { *this = Reply_Entry{} }
@@ -176,7 +176,7 @@ func (this *Reply_Entry) String() string { return proto.CompactTextString(this)
 const Default_Reply_Entry_Value int64 = 7
 const Default_Reply_Entry_Value int64 = 7
 
 
 type ReplyExtensions struct {
 type ReplyExtensions struct {
-	XXX_unrecognized []byte `json:",omitempty"`
+	XXX_unrecognized []byte `json:"-"`
 }
 }
 
 
 func (this *ReplyExtensions) Reset()         { *this = ReplyExtensions{} }
 func (this *ReplyExtensions) Reset()         { *this = ReplyExtensions{} }
@@ -191,8 +191,8 @@ var E_ReplyExtensions_Time = &proto.ExtensionDesc{
 }
 }
 
 
 type OldReply struct {
 type OldReply struct {
-	XXX_extensions   map[int32]proto.Extension `json:",omitempty"`
-	XXX_unrecognized []byte                    `json:",omitempty"`
+	XXX_extensions   map[int32]proto.Extension `json:"-"`
+	XXX_unrecognized []byte                    `json:"-"`
 }
 }
 
 
 func (this *OldReply) Reset()         { *this = OldReply{} }
 func (this *OldReply) Reset()         { *this = OldReply{} }