private static String getUtf8String(ByteBuffer buf) { return getUtf8String(buf, getIntFromUnsignedShort(buf)); }
private byte[] encodePlatformLevelData(Map<Integer, PlatformEncDec> platformEncDecMap, int platformId, ServerSync sync) throws PlatformEncDecException { PlatformEncDec encDec = platformEncDecMap.get(platformId); if (encDec != null) { return platformEncDecMap.get(platformId).encode(sync); } else { throw new PlatformEncDecException( MessageFormat.format("Encoder for platform protocol [{0}] is not defined", platformId)); } }
private ClientSync decodePlatformLevelData(Map<Integer, PlatformEncDec> platformEncDecMap, Integer platformId, byte[] requestRaw) throws PlatformEncDecException { PlatformEncDec encDec = platformEncDecMap.get(platformId); if (encDec != null) { return platformEncDecMap.get(platformId).decode(requestRaw); } else { throw new PlatformEncDecException(MessageFormat.format( "Decoder for platform protocol [{0}] is not defined", platformId)); } }
private void encode(GrowingByteBuffer buf, RedirectServerSync redirectSync) { buildExtensionHeader(buf, EVENT_EXTENSION_ID, NOTHING, NOTHING, 4); buf.putInt(redirectSync.getAccessPointId()); }
/** * Put integer number to byte buffer. * * @param integer is integer number for putting * @return current instance of <code>GrowingByteBuffer</code> */ public GrowingByteBuffer putInt(int integer) { resizeIfNeeded(SIZE_OF_INT); data.putInt(integer); return this; }
@KaaPlatformProtocol public class RawConfigurationSchemaBinaryEncDec extends BinaryEncDec { @Override public int getId() { return Constants.KAA_PLATFORM_PROTOCOL_BINARY_ID_V2; } @Override public ClientSync decode(byte[] data) throws PlatformEncDecException { ClientSync sync = super.decode(data); sync.setUseConfigurationRawSchema(true); return sync; } }
private static byte[] getNewByteArray(ByteBuffer buf, int size) { return getNewByteArray(buf, size, true); }
private static ByteBuffer getNewByteBuffer(ByteBuffer buf, int size) { return getNewByteBuffer(buf, size, true); }
/** * Put key and value, where key is <code>GrowingByteBuffer</code> instance and value is bytes * array. * * @param buf is <code>GrowingByteBuffer</code> instance * @param str is string which put in map as value */ public void putUtf(GrowingByteBuffer buf, String str) { if (str != null) { put(buf, str.getBytes(UTF8)); } }
private static byte[] getNewByteArray(ByteBuffer buf, int size, boolean withPadding) { byte[] array = new byte[size]; buf.get(array); if (withPadding) { handlePadding(buf, size); } return array; }
@Override public ClientSync decode(byte[] data) throws PlatformEncDecException { ClientSync sync = super.decode(data); sync.setUseConfigurationRawSchema(true); return sync; } }
private byte[] encodePlatformLevelData(int platformId, SessionResponse message) throws PlatformEncDecException { PlatformEncDec encDec = platformEncDecMap.get(platformId); if (encDec != null) { return platformEncDecMap.get(platformId).encode(message.getResponse()); } else { throw new PlatformEncDecException( MessageFormat.format("Encoder for platform protocol [{0}] is not defined", platformId)); } }
private void encodeMetaData(GrowingByteBuffer buf, ServerSync sync) { buildExtensionHeader(buf, META_DATA_EXTENSION_ID, NOTHING, NOTHING, 8); buf.putInt(sync.getRequestId()); buf.putInt(sync.getStatus().ordinal()); }
/** * Put array of bytes in buffer. * * @param bytes is array of bytes * @return current instance of <code>GrowingByteBuffer</code> */ public GrowingByteBuffer put(byte[] bytes) { resizeIfNeeded(bytes.length); data.put(bytes); return this; }
@KaaPlatformProtocol public class RawConfigurationSchemaAvroEncDec extends AvroEncDec { @Override public int getId() { return Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID_V2; } @Override public ClientSync decode(byte[] data) throws PlatformEncDecException { ClientSync sync = super.decode(data); sync.setUseConfigurationRawSchema(true); return sync; } }
/** * Put long number to byte buffer. * * @param value is long number for putting * @return current instance of <code>GrowingByteBuffer</code> */ public GrowingByteBuffer putLong(long value) { resizeIfNeeded(SIZE_OF_LONG); data.putLong(value); return this; }
/** * Put byte to byte buffer. * * @param bt is byte for putting * @return current instance of <code>GrowingByteBuffer</code> */ public GrowingByteBuffer put(byte bt) { resizeIfNeeded(SIZE_OF_BYTE); data.put(bt); return this; }
/** * Put short number to byte buffer. * * @param shrt is short for putting * @return current instance of <code>GrowingByteBuffer</code> */ public GrowingByteBuffer putShort(short shrt) { resizeIfNeeded(SIZE_OF_SHORT); data.putShort(shrt); return this; }