Search in sources :

Example 1 with TupleAndTable

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);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 2 with TupleAndTable

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());
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable)

Example 3 with TupleAndTable

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);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple)

Example 4 with TupleAndTable

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());
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable)

Aggregations

TupleAndTable (org.bboxdb.storage.entity.TupleAndTable)4 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)3 Tuple (org.bboxdb.storage.entity.Tuple)2 ArrayList (java.util.ArrayList)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)1 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)1 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)1 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1