private Map<String, byte[]> decodeValue(byte[] value) { Map<String, byte[]> data = new HashMap<>(); if (value[0] == EncodeType.NON_TRANSACTIONAL.getType()) { data.put(PAYLOAD_COL, Arrays.copyOfRange(value, 1, value.length)); } else { data.put(TX_COL, Arrays.copyOfRange(value, 1, 1 + Bytes.SIZEOF_LONG)); // Only transactional type has payload, otherwise payload should be null. if (value[0] == EncodeType.TRANSACTIONAL.getType()) { data.put(PAYLOAD_COL, Arrays.copyOfRange(value, 1 + Bytes.SIZEOF_LONG, value.length)); } } return data; } }
private byte[] encodeValue(@Nullable byte[] txWritePtr, @Nullable byte[] payload) { // Non-transactional if (txWritePtr == null) { // For non-tx message, payload cannot be null Preconditions.checkArgument(payload != null, "Payload cannot be null for non-transactional message"); byte[] result = new byte[1 + payload.length]; result[0] = EncodeType.NON_TRANSACTIONAL.getType(); Bytes.putBytes(result, 1, payload, 0, payload.length); return result; } // Transactional if (payload != null) { byte[] result = new byte[1 + Bytes.SIZEOF_LONG + payload.length]; result[0] = EncodeType.TRANSACTIONAL.getType(); Bytes.putBytes(result, 1, txWritePtr, 0, txWritePtr.length); Bytes.putBytes(result, 1 + Bytes.SIZEOF_LONG, payload, 0, payload.length); return result; } // Transactional but without payload, hence it's a payload table reference byte[] result = new byte[1 + Bytes.SIZEOF_LONG]; result[0] = EncodeType.PAYLOAD_REFERENCE.getType(); Bytes.putBytes(result, 1, txWritePtr, 0, txWritePtr.length); return result; }
private byte[] encodeValue(@Nullable byte[] txWritePtr, @Nullable byte[] payload) { // Non-transactional if (txWritePtr == null) { // For non-tx message, payload cannot be null Preconditions.checkArgument(payload != null, "Payload cannot be null for non-transactional message"); byte[] result = new byte[1 + payload.length]; result[0] = EncodeType.NON_TRANSACTIONAL.getType(); Bytes.putBytes(result, 1, payload, 0, payload.length); return result; } // Transactional if (payload != null) { byte[] result = new byte[1 + Bytes.SIZEOF_LONG + payload.length]; result[0] = EncodeType.TRANSACTIONAL.getType(); Bytes.putBytes(result, 1, txWritePtr, 0, txWritePtr.length); Bytes.putBytes(result, 1 + Bytes.SIZEOF_LONG, payload, 0, payload.length); return result; } // Transactional but without payload, hence it's a payload table reference byte[] result = new byte[1 + Bytes.SIZEOF_LONG]; result[0] = EncodeType.PAYLOAD_REFERENCE.getType(); Bytes.putBytes(result, 1, txWritePtr, 0, txWritePtr.length); return result; }
private Map<String, byte[]> decodeValue(byte[] value) { Map<String, byte[]> data = new HashMap<>(); if (value[0] == EncodeType.NON_TRANSACTIONAL.getType()) { data.put(PAYLOAD_COL, Arrays.copyOfRange(value, 1, value.length)); } else { data.put(TX_COL, Arrays.copyOfRange(value, 1, 1 + Bytes.SIZEOF_LONG)); // Only transactional type has payload, otherwise payload should be null. if (value[0] == EncodeType.TRANSACTIONAL.getType()) { data.put(PAYLOAD_COL, Arrays.copyOfRange(value, 1 + Bytes.SIZEOF_LONG, value.length)); } } return data; } }