golang protobuf SetExtension
对golang protobuf 的扩展字段赋值时候一直提示proto: bad extension value type
clkUrl:="z.cn"
proto.SetExtension(seatbid, rtb.E_Clkurl, clkUrl)
查看源码后发现,对扩展字段赋值的时候会对第二个参数进行反射获取类型,判断第三个参数的类型和第二个是否匹配 ,
func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
epb, ok := extendable(pb)
if !ok {
return errors.New("proto: not an extendable proto")
}
if err := checkExtensionTypes(epb, extension); err != nil {
return err
}
typ := reflect.TypeOf(extension.ExtensionType)
if typ != reflect.TypeOf(value) {
return errors.New("proto: bad extension value type")
}
// nil extension values need to be caught early, because the
// encoder can't distinguish an ErrNil due to a nil extension
// from an ErrNil due to a missing field. Extensions are
// always optional, so the encoder would just swallow the error
// and drop all the extensions from the encoded message.
if reflect.ValueOf(value).IsNil() {
return fmt.Errorf("proto: SetExtension called with nil value of type %T", value)
}
extmap := epb.extensionsWrite()
extmap[extension.Field] = Extension{desc: extension, value: value}
return nil
}
通过打印第二个参数的类型发现 第二个参数类型是*string , 我的第三个参数是sring,问题已经明了。
阅读源码是解决问题的最好途径。
修改后的代码如下:
proto.SetExtension(seatbid, rtb.E_Clkurl, &clkUrl)
golang protobuf SetExtension的更多相关文章
- manjaro 下golang protobuf的使用
1.下载protobuf compiler sudo pacman -S protobuf 2.添加环境变量GOBIN export GOBIN=~/go/bin 3.下载golang依赖的包 go ...
- deepin 安装golang protobuf
1.安装库文件protobuf,地址:https://github.com/protocolbuffers/protobuf/releases 我电脑是deepin 64位的,所以我直接下载https ...
- client: c#+protobuf, server: golang+protobuf
前段时间看到一篇博文<可在广域网部署运行的即时通讯系统 -- GGTalk总览(附源码下载)>,他是用C#实现的即时通讯系统,功能强大,界面漂亮. 就想用golang重写服务端,把代码下载 ...
- golang protobuf
1. proto文件编写的时候,如果用uint32或uint64类型,那么不能用required,必须用optional. 如果用错了,会出现错误:unmarshaling error: proto: ...
- Golang+Protobuf+PixieJS 开发 Web 多人在线射击游戏(原创翻译)
简介 Superstellar 是一款开源的多人 Web 太空游戏,非常适合入门 Golang 游戏服务器开发. 规则很简单:摧毁移动的物体,不要被其他玩家和小行星杀死.你拥有两种资源 - 生命值(h ...
- Golang里面使用protobuf(proto3)
参考文章:https://developers.google.com/protocol-buffers/docs/gotutorial 1.执行指令: go envgo get github.com/ ...
- mac 下配置protobuf 3.0 golang环境
protobuf 3.0 与 之前的 protobuf 2.6 的语法是不一样的.需要重新安装一下,本机的环境是 OS X Yosemite 10.10.2 1. 不采用home brew安装,用 ...
- Updating Protobuf and GRPC in Golang
转自: http://russmatney.com/techsposure/update-protobuf-golang-grpc/ TL;DR: When protobuf updates, all ...
- Golang版protobuf编译
官方网址: https://developers.google.com/protocol-buffers/ (需要FQ) 代码仓库: https://github.com/google/protobu ...
随机推荐
- BZOJ4444 : [Scoi2015]国旗计划
首先将坐标离散化,因为区间互不包含,可以理解为对于每个起点输出最少需要多少个战士. 将环倍长,破环成链,设$f[i]$表示区间左端点不超过$i$时右端点的最大值,可以通过$O(n)$递推求出. 那么如 ...
- Storm与Spark:谁才是我们的实时处理利器
Storm与Spark:谁才是我们的实时处理利器 ——实时商务智能目前已经逐步迈入主流,而Storm与Spark开源项目的支持无疑在其中起到了显著的推动作用.那么问题来了:实时处理到底哪家强? 实时商 ...
- why cpp is a shitty language
// the below is a standard template for any of my writings about c++ cpp_is_a_shitty_language_as { t ...
- [深入浅出WP8.1(Runtime)]浮出控件(Flyout)
4.15 浮出控件(Flyout) 浮出控件(Flyout)是一个轻型的辅助型的弹出控件,通常会作为提示或者要求用户进行相关的交互来使用.Flyout控件与Windows Phone里面的弹出框Mes ...
- MathType的公式在word中跟文字不对齐
引用http://blog.sina.com.cn/s/blog_4d1f40c00100net8.html 部分Mathtype公式与文档文字没有很好的对齐,而是浮起来了,也就是说Mathtype公 ...
- SVN错误:Attempted to lock an already-locked dir
在eclipse里提交和更新文件是报错: Attempted to lock an already-locked dir svn: Working copy 'F:\workspace\WebFram ...
- Solr5.0配置中文分词包
Solr中默认的中文分词是用Lucene的一元分词包. 现在说明在Solr5.0中配置Lucene的SmartCN中文分词包. 1,进入Solr的安装目录,我这里是:/root/nutch/solr- ...
- android 百度地图开发
package sposition.webjoy.net.sendposition; import android.os.Bundle; import android.support.design.w ...
- python rabbitmq
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @author: zengchunyun ""& ...
- 制作、解析带logo的二维码
用DecoderQRCode来解析带logo的二维码,发现报错,解析不了,于是便又查资料,找到了更强大的制作二维码 工具:GooleZXing 首先下GooleZXing的jar包. -------- ...