Question

I want to do following: feed a binary string of protobuf message encoded to base 64 in Python to server and then decode it back to entity via Protobuf for Javascript. I have the following code in view:

...
result = data_sample.SerializeToString()
result = base64.b64encode(result)
return render(request, 'pr22/index.html', {'result': result})

in template:

<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>

what's next?

Was it helpful?

Solution

Read the docs! :P

... but basically you'll want something like this:

var YourMessage = builder.build("YourMessage");
var myMessage = YourMessage.decode64("{{result|safe}}");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top