@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;
}