【发布时间】:2017-11-01 08:19:01
【问题描述】:
我正在使用 protobuf 传递一个散列字节数组。但是在尝试反序列化它时,我收到以下错误:
“utf-8”编解码器无法解码位置 1 中的字节 0xd6:“utf-8”编解码器 无法解码位置 1 中的字节 0xd6:无效的继续字节 字段:master.hash1
代码很简单:
a = message.ParseFromString(data)
我相信这是一个简单的编码\解码问题,但我不知道该怎么做。
这是在c#中对数据进行编码的代码:
public byte[] HmacSign(string key, string message)
{
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(key);
HMACSHA1 hmacsha1 = new HMACSHA1(keyByte);
byte[] messageBytes = encoding.GetBytes(message);
byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
return hashmessage;
}
【问题讨论】:
-
您的数据是否使用 utf-8 编码?
-
这个问题帮助解决了我的问题:stackoverflow.com/questions/46675090/…
标签: python protocol-buffers decode encode