protobuf-go/cmd/protoc-gen-go/testdata/proto3/enum.pb.go
Joe Tsai b6405bd782 cmd/protoc-gen-go: add support for protobuf reflection
Implement support in protoc-gen-go for generating messages and enums
that satisfy the v2 protobuf reflection interfaces. Specifically, the following
are added:
* top-level variable representing the file descriptor
* ProtoReflect method on enums (to implement protoV2.Enum)
* ProtoReflect method on messages (to implement protoV2.Message)

The following are not supported yet:
* resolving transitive dependencies for file imports
* Extension descriptors
* Service descriptors

The implementation approach creates a single array for all the message and enum
declarations and references sections of that array to complete dependencies.
Since protobuf declarations can form a graph (a message may depend on itself),
it is difficult to construct a graph as a single literal. One way is to use
placeholder descriptors, but that is not efficient as it requires encoding
the full name of each dependent enum and message and then later resolving it;
thus, both expanding the binary size and also increasing initialization cost.
Instead, we add a prototype.{Enum,Message}.Reference method to obtain a
descriptor reference for the purposes for satisfying dependencies.
As such, nested declarations and dependencies are populated in an init function.

Other changes to support the implementation:
* Added a protoimpl package to expose the MessageType type and also the
MessageTypeOf and EnumTypeOf helper functions.
* Added a protogen.File.GoIdent field to provide a suggested variable name
for the file descriptor.
* Added prototype.{Enum,Message}.Reference that provides a descriptor reference
for the purposes for satisfying cyclic dependencies.
* Added protoreflect.{Syntax,Cardinality,Kind}.GoString to obtain a Go source
identifier that represents the given constant.

Change-Id: I9455764882dee6ad10f251901e7d419091e8bf1d
Reviewed-on: https://go-review.googlesource.com/c/150074
Reviewed-by: Damien Neil <dneil@google.com>
2018-12-05 19:32:12 +00:00

121 lines
3.5 KiB
Go

// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto3/enum.proto
package proto3
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
prototype "github.com/golang/protobuf/v2/reflect/prototype"
protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Enum int32
const (
Enum_ZERO Enum = 0
Enum_ONE Enum = 1
Enum_TWO Enum = 2
)
type xxx_Enum Enum
func (e Enum) ProtoReflect() protoreflect.Enum {
return (xxx_Enum)(e)
}
func (e xxx_Enum) Type() protoreflect.EnumType {
return xxx_Enum_ProtoFile_EnumTypes[0]
}
func (e xxx_Enum) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(e)
}
var Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
2: "TWO",
}
var Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
"TWO": 2,
}
func (x Enum) String() string {
return proto.EnumName(Enum_name, int32(x))
}
func (Enum) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_b4b9b1e8d161a9a6, []int{0}
}
func init() {
proto.RegisterEnum("goproto.protoc.proto3.Enum", Enum_name, Enum_value)
}
func init() { proto.RegisterFile("proto3/enum.proto", fileDescriptor_b4b9b1e8d161a9a6) }
var fileDescriptor_b4b9b1e8d161a9a6 = []byte{
// 144 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2c, 0x28, 0xca, 0x2f,
0xc9, 0x37, 0xd6, 0x4f, 0xcd, 0x2b, 0xcd, 0xd5, 0x03, 0xb3, 0x85, 0x44, 0xd3, 0xf3, 0xc1, 0x0c,
0x08, 0x37, 0x19, 0x42, 0x19, 0x6b, 0x29, 0x71, 0xb1, 0xb8, 0xe6, 0x95, 0xe6, 0x0a, 0x71, 0x70,
0xb1, 0x44, 0xb9, 0x06, 0xf9, 0x0b, 0x30, 0x08, 0xb1, 0x73, 0x31, 0xfb, 0xfb, 0xb9, 0x0a, 0x30,
0x82, 0x18, 0x21, 0xe1, 0xfe, 0x02, 0x4c, 0x4e, 0x8e, 0x51, 0xf6, 0xe9, 0x99, 0x25, 0x19, 0xa5,
0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0x39, 0x89, 0x79, 0xe9, 0xfa, 0x60, 0xfd, 0x49,
0xa5, 0x69, 0xfa, 0x65, 0x46, 0xfa, 0xc9, 0xb9, 0x29, 0x10, 0x7e, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e,
0x6e, 0x7a, 0xbe, 0x7e, 0x49, 0x6a, 0x71, 0x49, 0x4a, 0x62, 0x49, 0x22, 0x44, 0xd8, 0x38, 0x89,
0x0d, 0x42, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x96, 0x4a, 0x7d, 0xc7, 0x99, 0x00, 0x00, 0x00,
}
func init() {
xxx_Enum_ProtoFile_FileDesc.Enums = xxx_Enum_ProtoFile_EnumDescs[0:1]
var err error
Enum_ProtoFile, err = prototype.NewFile(&xxx_Enum_ProtoFile_FileDesc)
if err != nil {
panic(err)
}
}
const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
var Enum_ProtoFile protoreflect.FileDescriptor
var xxx_Enum_ProtoFile_FileDesc = prototype.File{
Syntax: protoreflect.Proto3,
Path: "proto3/enum.proto",
Package: "goproto.protoc.proto3",
}
var xxx_Enum_ProtoFile_EnumTypes = [1]protoreflect.EnumType{
prototype.GoEnum(
xxx_Enum_ProtoFile_EnumDescs[0].Reference(),
func(_ protoreflect.EnumType, n protoreflect.EnumNumber) protoreflect.ProtoEnum {
return Enum(n)
},
),
}
var xxx_Enum_ProtoFile_EnumDescs = [1]prototype.Enum{
{
Name: "Enum",
Values: []prototype.EnumValue{
{Name: "ZERO", Number: 0},
{Name: "ONE", Number: 1},
{Name: "TWO", Number: 2},
},
},
}