in protoc-gen-go/generator/generator.go [1583:1638]
func (g *Generator) GoType(message *Descriptor, field *descriptor.FieldDescriptorProto) (typ string, wire string) {
// TODO: Options.
switch *field.Type {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
typ, wire = "float64", "fixed64"
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
typ, wire = "float32", "fixed32"
case descriptor.FieldDescriptorProto_TYPE_INT64:
typ, wire = "int64", "varint"
case descriptor.FieldDescriptorProto_TYPE_UINT64:
typ, wire = "uint64", "varint"
case descriptor.FieldDescriptorProto_TYPE_INT32:
typ, wire = "int32", "varint"
case descriptor.FieldDescriptorProto_TYPE_UINT32:
typ, wire = "uint32", "varint"
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
typ, wire = "uint64", "fixed64"
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
typ, wire = "uint32", "fixed32"
case descriptor.FieldDescriptorProto_TYPE_BOOL:
typ, wire = "bool", "varint"
case descriptor.FieldDescriptorProto_TYPE_STRING:
typ, wire = "string", "bytes"
case descriptor.FieldDescriptorProto_TYPE_GROUP:
desc := g.ObjectNamed(field.GetTypeName())
typ, wire = "*"+g.TypeName(desc), "group"
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
desc := g.ObjectNamed(field.GetTypeName())
typ, wire = "*"+g.TypeName(desc), "bytes"
case descriptor.FieldDescriptorProto_TYPE_BYTES:
typ, wire = "[]byte", "bytes"
case descriptor.FieldDescriptorProto_TYPE_ENUM:
desc := g.ObjectNamed(field.GetTypeName())
typ, wire = g.TypeName(desc), "varint"
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
typ, wire = "int32", "fixed32"
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
typ, wire = "int64", "fixed64"
case descriptor.FieldDescriptorProto_TYPE_SINT32:
typ, wire = "int32", "zigzag32"
case descriptor.FieldDescriptorProto_TYPE_SINT64:
typ, wire = "int64", "zigzag64"
default:
g.Fail("unknown type for", field.GetName())
}
if isRepeated(field) {
typ = "[]" + typ
} else if message != nil && message.proto3() {
return
} else if field.OneofIndex != nil && message != nil {
return
} else if needsStar(*field.Type) {
typ = "*" + typ
}
return
}