当使用 readModifyWrite 方法增加一个数字时,它会抛出异常,该值必须在 Java 中存储为 64 位编码的有符号整数。如何将其存储为 64 位大端?我尝试了reversebytes方法和Base64编码但没有帮助。
通过 Google 支持找到:
long number = 456712L;
ByteString encodedLong = ByteString.copyFrom(
ByteBuffer.allocate(Long.BYTES).putLong(number).array()
);
Mutation mutation = Mutation.create(tableId, rowKey)
.setCell(columnFamily, columnQualifier, encodedLong);
dataClient.mutateRow(mutation);
Row row = dataClient.readRow(tableId, rowKey);
if (row != null && row.getCells(columnFamily, columnQualifier).size() > 0) {
ByteString longBytes = row.getCells(columnFamily, columnQualifier).get(0).getValue();
long longValue = ByteBuffer.wrap(longBytes.toByteArray()).getLong();
System.out.println("Retrieved long value: " + longValue);
} else {
System.out.println("Long value not found for row key: " + rowKey);
}