use of org.bboxdb.storage.entity.TupleAndTable in project bboxdb by jnidzwetzki.
the class JoinedTupleResponse method decodePackage.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static JoinedTupleResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_JOINED_TUPLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final List<String> tupleStoreNames = new ArrayList<>();
final List<Tuple> tuples = new ArrayList<>();
final int numberOfTuples = encodedPackage.getInt();
for (int i = 0; i < numberOfTuples; i++) {
final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
tupleStoreNames.add(tupleAndTable.getTable());
tuples.add(tupleAndTable.getTuple());
}
final JoinedTuple joinedTuple = new JoinedTuple(tuples, tupleStoreNames);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after encoding: " + encodedPackage.remaining());
}
return new JoinedTupleResponse(requestId, joinedTuple);
}
use of org.bboxdb.storage.entity.TupleAndTable in project bboxdb by jnidzwetzki.
the class TupleResponse method decodePackage.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static TupleResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_TUPLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after encoding: " + encodedPackage.remaining());
}
return new TupleResponse(requestId, tupleAndTable.getTable(), tupleAndTable.getTuple());
}
use of org.bboxdb.storage.entity.TupleAndTable in project bboxdb by jnidzwetzki.
the class NetworkTupleEncoderDecoder method decode.
/**
* Convert a ByteBuffer into a TupleAndTable object
* @param encodedPackage
* @return
*/
public static TupleAndTable decode(final ByteBuffer encodedPackage) {
final short tableLength = encodedPackage.getShort();
final short keyLength = encodedPackage.getShort();
final int bBoxLength = encodedPackage.getInt();
final int dataLength = encodedPackage.getInt();
final long timestamp = encodedPackage.getLong();
final byte[] tableBytes = new byte[tableLength];
encodedPackage.get(tableBytes, 0, tableBytes.length);
final String table = new String(tableBytes);
final byte[] keyBytes = new byte[keyLength];
encodedPackage.get(keyBytes, 0, keyBytes.length);
final String key = new String(keyBytes);
final byte[] boxBytes = new byte[bBoxLength];
encodedPackage.get(boxBytes, 0, boxBytes.length);
final byte[] dataBytes = new byte[dataLength];
encodedPackage.get(dataBytes, 0, dataBytes.length);
final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
Tuple tuple = null;
if (TupleHelper.isDeletedTuple(boxBytes, dataBytes)) {
tuple = new DeletedTuple(key, timestamp);
} else {
tuple = new Tuple(key, boundingBox, dataBytes, timestamp);
}
return new TupleAndTable(tuple, table);
}
use of org.bboxdb.storage.entity.TupleAndTable in project bboxdb by jnidzwetzki.
the class InsertTupleRequest method decodeTuple.
/**
* Decode the encoded tuple into a object
*
* @param encodedPackage
* @return
* @throws IOException
* @throws PackageEncodeException
*/
public static InsertTupleRequest decodeTuple(final ByteBuffer encodedPackage) throws IOException, PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_INSERT_TUPLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
final TupleStoreName ssTableName = new TupleStoreName(tupleAndTable.getTable());
return new InsertTupleRequest(sequenceNumber, routingHeader, ssTableName, tupleAndTable.getTuple());
}
Aggregations