cognitect / transit-java

transit-format implementation for Java
Apache License 2.0
62 stars 21 forks source link

MsgpackEmitter encodes byte[] as a base64 string #17

Closed chris-zen closed 8 years ago

chris-zen commented 8 years ago

When writing an array of bytes Transit uses the BinaryWriteHandler which gives the b tag. Then for that tag, the AbstractEmitter calls the function emitBinary. Its implementation in MsgpackEmitter encodes the array of bytes as Base64 and emits an string as follows:

byte[] encodedBytes = Base64.encodeBase64((byte[])b);
emitString(Constants.ESC_STR, "b", new String(encodedBytes), asMapKey, cache);

Reading the specs of MessagePack I see that they have native support for encoding binary data without having to use strings encoded as Base64. I can understand this strategy for the JSON emitters but not for the Msgpack one.

chris-zen commented 8 years ago

I just realised that the Transit specs mandate to encode binary data as a base64 string. I don't really understand this decision, and makes me realise that using the MSGPACK format is not that much better than using the JSON one.

puredanger commented 8 years ago

FYI, there is more discussion of this here: https://github.com/cognitect/transit-format/issues/2