private ClientSync validate(ClientSync sync) throws PlatformEncDecException { if (sync.getClientSyncMetaData() == null) { throw new PlatformEncDecException( MessageFormat.format("Input data does not have client sync meta data: {0}!", sync)); } return sync; } }
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 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 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 ClientSync decodePlatformLevelData(Integer platformId, byte[] requestRaw) throws PlatformEncDecException { PlatformEncDec encDec = platformEncDecMap.get(platformId); if (encDec != null) { ClientSync syncRequest = platformEncDecMap.get(platformId).decode(requestRaw); addAppTokenToClientSyncMetaData(syncRequest.getClientSyncMetaData()); return syncRequest; } else { throw new PlatformEncDecException( MessageFormat.format("Decoder for platform protocol [{0}] is not defined", platformId)); } }
@Override public byte[] encode(ServerSync sync) throws PlatformEncDecException { if (sync == null) { return null; } LOG.trace("Encoding server sync {}", sync); SyncResponse response = convert(sync); LOG.trace("Encoded server sync {}", response); try { byte[] data = serverSyncConverter.toByteArray(response); if (LOG.isTraceEnabled()) { LOG.trace("Encoded avro data {}", Arrays.toString(data)); } return data; } catch (IOException exception) { throw new PlatformEncDecException(exception); } } }
@Override public ClientSync decode(byte[] data) throws PlatformEncDecException { try { if (LOG.isTraceEnabled()) { LOG.trace("Decoding avro data {}", Arrays.toString(data)); } SyncRequest source = clientSyncConverter.fromByteArray(data); LOG.trace("Decoding client sync {}", source); if (source == null) { return null; } ClientSync sync = convert(source); sync.setUseConfigurationRawSchema(false); LOG.trace("Decoded client sync {}", sync); return sync; } catch (IOException exception) { throw new PlatformEncDecException(exception); } }
@Override public ClientSync decode(byte[] data) throws PlatformEncDecException { if (LOG.isTraceEnabled()) { LOG.trace("Decoding binary data {}", Arrays.toString(data)); } ByteBuffer buf = ByteBuffer.wrap(data); if (buf.remaining() < MIN_SIZE_OF_MESSAGE_HEADER) { throw new PlatformEncDecException( MessageFormat.format("Message header is to small {0} to be kaa binary message!", buf.capacity())); } int protocolId = buf.getInt(); if (protocolId != getId()) { throw new PlatformEncDecException( MessageFormat.format("Unknown protocol id {0}!", protocolId)); } int protocolVersion = getIntFromUnsignedShort(buf); if (protocolVersion < MIN_SUPPORTED_VERSION || protocolVersion > MAX_SUPPORTED_VERSION) { throw new PlatformEncDecException( MessageFormat.format("Can't decode data using protocol version {0}!", protocolVersion)); } int extensionsCount = getIntFromUnsignedShort(buf); LOG.trace("received data for protocol id {} and version {} that contain {} extensions", protocolId, protocolVersion, extensionsCount); ClientSync sync = parseExtensions(buf, protocolVersion, extensionsCount); sync.setUseConfigurationRawSchema(false); LOG.trace("Decoded binary data {}", sync); return sync; }
for (short extPos = 0; extPos < extensionsCount; extPos++) { if (buf.remaining() < MIN_SIZE_OF_EXTENSION_HEADER) { throw new PlatformEncDecException(MessageFormat.format( "Extension header is to small. Available {0}, current possition is {1}!", buf.remaining(), buf.position())); int payloadLength = buf.getInt(); if (buf.remaining() < payloadLength) { throw new PlatformEncDecException(MessageFormat.format( "Extension payload is to small. Available {0}, expected {1} current possition is {2}!", buf.remaining(),