go处理protobuf文件

protobuf提供两个包
(1)proto
(2)protoc-gen-go
前者负责处理处理protobuf的goprotocbuf编码、解码,后者作为编译器插件使用。
(1)使用方式
        error:= proto.Unmarshal([]byte(media_request_str), &bidreq)负责把字符串流解析解码到一个结构体bidreq。如果有错,err不为nil
       data, err := proto.Marshal(test)编码结构题
(2)使用
protoc --go_out=plugins=grpc:. *.proto会编译所有的proto文件,以文件名作为转换后go文件的包名。如果需要指定名,就需要传参数使用import_path
protoc --go_out=plugins=grpc,import_path=mypackage:. *.proto


https://github.com/golang/protobuf

猜你喜欢

转载自hhg08.iteye.com/blog/2286736