Wener Site

Protobuf Go

约 1 分钟阅读
标签:Go语言

APIv2

  • v2 protoreflect.ProtoMessage
  • v1 protoiface.MessageV1
protoreflect
// 基于反射的主要接口
type ProtoMessage interface{ ProtoReflect() Message }

// v2
// 反射信息
type Message interface {
	Descriptor() MessageDescriptor
	Type() MessageType

	New() Message
	Interface() ProtoMessage
	Range(f func(FieldDescriptor, Value) bool)
	Has(FieldDescriptor) bool
	Clear(FieldDescriptor)
	Get(FieldDescriptor) Value
	Set(FieldDescriptor, Value)
	Mutable(FieldDescriptor) Value
	NewField(FieldDescriptor) Value
	WhichOneof(OneofDescriptor) FieldDescriptor
	GetUnknown() RawFields
	SetUnknown(RawFields)

	IsValid() bool
	ProtoMethods() *methods
}

// v1
type MessageV1 interface {
	Reset()
	String() string
	ProtoMessage()
}

proto

  • golang proto v2 基于反射
  • github.com/golang/protobuf/proto
  • 反射
    • 全局注册 - google.golang.org/protobuf/reflect/protoregistry
      • GlobalFiles
      • GlobalTypes

关联信息

反向链接和本文引用的外部资料。

反向链接

  • protobuf
    笔记 · Go

    protocolbuffers/protobuf · Protocol Buffers - Google's data interchange format · 包含实现: C++, Java, Python, Objective-C, C#, Ruby, PHP

References

GitHub

1 条

其他外链

1 条
最近更新commit e0af4bbEdit

On this page