Pārlūkot izejas kodu

goprotobuf: Generate []byte for weak fields.

R=r
CC=golang-dev
http://codereview.appspot.com/5883057
David Symonds 14 gadi atpakaļ
vecāks
revīzija
36a6b55518

+ 4 - 6
protoc-gen-go/generator/generator.go

@@ -1150,12 +1150,6 @@ func (g *Generator) generateMessage(message *Descriptor) {
 	g.P("type ", ccTypeName, " struct {")
 	g.In()
 	for _, field := range message.Field {
-		// TODO: One day we may need to generate RawMessage fields for weak fields;
-		// for now it is sufficient to skip them.
-		if field.Options != nil && proto.GetBool(field.Options.Weak) {
-			g.P("// skipping weak field ", *field.Name)
-			continue
-		}
 		fieldname := CamelCase(*field.Name)
 		for usedNames[fieldname] {
 			fieldname += "_"
@@ -1163,6 +1157,10 @@ func (g *Generator) generateMessage(message *Descriptor) {
 		usedNames[fieldname] = true
 		typename, wiretype := g.GoType(message, field)
 		jsonName := *field.Name
+		// This is a hack that is going away. TODO: remove this.
+		if field.Options != nil && proto.GetBool(field.Options.Weak) {
+			typename = "[]byte"
+		}
 		tag := fmt.Sprintf("`protobuf:%s json:%q`", g.goTag(field, wiretype), jsonName+",omitempty")
 		g.P(fieldname, "\t", typename, "\t", tag)
 		g.RecordTypeUse(proto.GetString(field.TypeName))

+ 1 - 1
protoc-gen-go/testdata/my_test/test.proto

@@ -64,7 +64,7 @@ message Request {
 
   // This foreign message type is in imp2.proto,
   // which is publicly imported by imp.proto.
-  // optional imp.PubliclyImportedMessage pub = 10;
+//  optional imp.PubliclyImportedMessage pub = 10;
 
 
   optional int32 reset = 12;