Chronicle Bytes:如何在小端机器上以大端顺序写入字节?

Chronicle Bytes: How to write bytes in big endian order on a little endian machine?

我正在使用 hereBytes<U> 界面。底层缓冲区创建如下:

Bytes<?> buf = Bytes.elasticHeapByteBuffer(MAX_SIZE);
buf.writeLong(l);   // writes in little endian

鉴于我的机器字节顺序是小端,我怎样才能改为大端写入字节?

谢谢。

编辑: 根据这个chart,chronicle bytes好像不支持这个功能

底层实现使用 CPU 的本机字节顺序。即在 amd64 和 ARM 上 little-endian,在 Sparc 上 big-endian。

您可以与

调换顺序
Bytes<?> buf = Bytes.elasticHeapByteBuffer(MAX_SIZE);
buf.writeLong(Long.reverseLong(l));

long l2 = Long.reverseLong(buf.readLong(l));

如今大多数计算机都是 little-endian,因此只有在与 big-endian 系统共享数据时才会出现问题。