python代码
buf = struct.pack('>%sf' % len(floatlist), *floatlist)
b = base64.b64encode(buf)
s = str(b, encoding = "utf-8")
与下面的java代码等价
public static String encodeData(float[] data){
ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4);
for (float f : data) {
byteBuffer.putFloat(f);
}
byte[] dst = byteBuffer.array();
return new sun.misc.BASE64Encoder().encode(dst);
}
- >是为了调节大小端,使其和java一致
- b是byte型,需要转成str型