Fix binary data encoding when serializing