我想做以下操作:将Python中编码为base 64的protobuf消息的二进制字符串提供给服务器,然后通过Protobuf for Javascript将其解码回实体。我在视图中有以下代码:
...
result = data_sample.SerializeToString()
result = base64.b64encode(result)
return render(request, 'pr22/index.html', {'result': result})
模板中的:
<script src="static/Long.min.js"></script>
<script src="static/ByteBuffer.min.js"></script>
<script src="static/ProtoBuf.min.js"></script>
<script type="text/javascript">
var ProtoBuf = dcodeIO.ProtoBuf;
var builder = ProtoBuf.loadProtoFile("static/schema.proto");
</script>
下一步是什么?
答案 0 :(得分:1)
阅读docs! :P
...但基本上你会想要这样的东西:
var YourMessage = builder.build("YourMessage");
var myMessage = YourMessage.decode64("{{result|safe}}");