protobuf/

directory
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT

README

protobuf相关操作包

功能列表

protoreflect

  • GetFields 获取目标proto消息的字段信息
  • GetFieldsByProperties 根据StructProperties获取proto消息字段信息,注意,该函数使用了github.com/golang/protobuf/proto的弃用函数GetProperties
  • IsGeneratedAutoFields 判断字段是否是proto-gen-go自动生成的特殊字段

GetFields与GetFieldsByProperties功能相同,不同之处在于GetFieldsByProperties使用了已经被弃用的函数GetProperties

目前建议使用protobuf reflection代替GetProperties,但在google.golang.org/protobuf/protoprotobuf reflection中并未提供与其功能类似的函数, 无法获取对应的Go字段名(只能获取到protobuf定义名与json定义名。。。)

因此GetFields直接使用golang原生的反射实现了类似GetProperties的功能,但性能方面,比GetProperties慢大约50%。

protobuffer

将老版本的"github.com/golang/protobuf"替换为新版本的"google.golang.org/protobuf"时,原来的proto.Buffer被移除,这里提供了protobuffer.Buffer用于替代原来的proto.Buffer

Directories

Path Synopsis
myproto-go
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL