use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class HelloResponse method decodePackage.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static HelloResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_HELLO);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final int protocolVersion = encodedPackage.getInt();
final byte[] capabilityBytes = new byte[PeerCapabilities.CAPABILITY_BYTES];
encodedPackage.get(capabilityBytes, 0, capabilityBytes.length);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final PeerCapabilities peerCapabilities = new PeerCapabilities(capabilityBytes);
peerCapabilities.freeze();
return new HelloResponse(requestId, protocolVersion, peerCapabilities);
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class HelloRequest method decodeRequest.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static HelloRequest decodeRequest(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_HELLO);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final int protocolVersion = encodedPackage.getInt();
final byte[] capabilityBytes = new byte[PeerCapabilities.CAPABILITY_BYTES];
encodedPackage.get(capabilityBytes, 0, capabilityBytes.length);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final PeerCapabilities peerCapabilities = new PeerCapabilities(capabilityBytes);
return new HelloRequest(sequenceNumber, protocolVersion, peerCapabilities);
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloResponse2.
/**
* The the encoding and decoding of the response helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloResponse2() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.setGZipCompression();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloResponse decodedPackage = HelloResponse.decodePackage(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestPeerCapabilities method testPeerCapabilitiesRO2.
/**
* Test the peer capabilities
*/
@Test(expected = IllegalStateException.class)
public void testPeerCapabilitiesRO2() {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.freeze();
peerCapabilities.clearGZipCompression();
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestPeerCapabilities method testPeerCapabilities2.
/**
* Test the peer capabilities
*/
@Test(timeout = 60000)
public void testPeerCapabilities2() {
final PeerCapabilities peerCapabilities1 = new PeerCapabilities();
final PeerCapabilities peerCapabilities2 = new PeerCapabilities();
Assert.assertTrue(peerCapabilities1.equals(peerCapabilities2));
Assert.assertEquals(peerCapabilities1.hashCode(), peerCapabilities2.hashCode());
}
Aggregations