private List<EventListenersRequest> parseListenerRequests(ByteBuffer buf) { int requestsCount = getIntFromUnsignedShort(buf); List<EventListenersRequest> requests = new ArrayList<>(requestsCount); for (int i = 0; i < requestsCount; i++) { int requestId = getIntFromUnsignedShort(buf); int fqnCount = getIntFromUnsignedShort(buf); List<String> fqns = new ArrayList<>(fqnCount); for (int j = 0; j < fqnCount; j++) { int fqnLength = getIntFromUnsignedShort(buf); // reserved buf.getShort(); fqns.add(getUtf8String(buf, fqnLength)); } requests.add(new EventListenersRequest(requestId, fqns)); } return requests; }
private List<TopicState> parseTopicStates(ByteBuffer buf) { int count = getIntFromUnsignedShort(buf); List<TopicState> topicStates = new ArrayList<TopicState>(count); for (int i = 0; i < count; i++) { long topicId = buf.getLong(); int seqNumber = buf.getInt(); topicStates.add(new TopicState(topicId, seqNumber)); } return topicStates; }
private List<EndpointAttachRequest> parseEndpointAttachRequests(ByteBuffer buf) { // reserved buf.get(); int count = getIntFromUnsignedShort(buf); List<EndpointAttachRequest> requests = new ArrayList<EndpointAttachRequest>(count); for (int i = 0; i < count; i++) { int requestId = getIntFromUnsignedShort(buf); String accessToken = getUtf8String(buf); requests.add(new EndpointAttachRequest(requestId, accessToken)); } return requests; }
private static String getUtf8String(ByteBuffer buf) { return getUtf8String(buf, getIntFromUnsignedShort(buf)); }
private List<String> parseUnicastIds(ByteBuffer buf) { int count = getIntFromUnsignedShort(buf); List<String> uids = new ArrayList<>(count); for (int i = 0; i < count; i++) { int uidLength = buf.getInt(); uids.add(getUtf8String(buf, uidLength)); } return uids; }
private List<EndpointDetachRequest> parseEndpointDetachRequests(ByteBuffer buf) { // reserved buf.get(); int count = getIntFromUnsignedShort(buf); List<EndpointDetachRequest> requests = new ArrayList<EndpointDetachRequest>(count); for (int i = 0; i < count; i++) { int requestId = getIntFromUnsignedShort(buf); // reserved buf.getShort(); requests.add(new EndpointDetachRequest( requestId, Base64Util.encode(getNewByteArray(buf, PUBLIC_KEY_HASH_SIZE)))); } return requests; }
private UserAttachRequest parseUserAttachRequest(ByteBuffer buf) { int extIdLength = buf.get() & 0xFF; int tokenLength = getIntFromUnsignedShort(buf); int verifierTokenLength = getIntFromUnsignedShort(buf); // reserved buf.getShort(); String userExternalId = getUtf8String(buf, extIdLength); String userAccessToken = getUtf8String(buf, tokenLength); String userVerifierToken = getUtf8String(buf, verifierTokenLength); return new UserAttachRequest(userVerifierToken, userExternalId, userAccessToken); }
private void parseSubscriptionCommands(NotificationClientSync nfSync, ByteBuffer buf, boolean add) { int count = getIntFromUnsignedShort(buf); if (nfSync.getSubscriptionCommands() == null) { nfSync.setSubscriptionCommands(new ArrayList<>()); } SubscriptionCommandType subscriptionType = add ? SubscriptionCommandType.ADD : SubscriptionCommandType.REMOVE; List<SubscriptionCommand> commands = new ArrayList<>(); for (int i = 0; i < count; i++) { long topicId = buf.getLong(); commands.add(new SubscriptionCommand(topicId, subscriptionType)); } nfSync.getSubscriptionCommands().addAll(commands); }
private void parseLogClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { LogClientSync logSync = new LogClientSync(); logSync.setRequestId(getIntFromUnsignedShort(buf)); int size = getIntFromUnsignedShort(buf); List<LogEntry> logs = new ArrayList<>(size); for (int i = 0; i < size; i++) { logs.add(new LogEntry(getNewByteBuffer(buf, buf.getInt()))); } logSync.setLogEntries(logs); sync.setLogSync(logSync); }
@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; }
private List<Event> parseEvents(ByteBuffer buf) { int eventsCount = getIntFromUnsignedShort(buf); List<Event> events = new ArrayList<>(eventsCount); for (int i = 0; i < eventsCount; i++) { Event event = new Event(); event.setSeqNum(buf.getInt()); int eventOptions = getIntFromUnsignedShort(buf); int fqnLength = getIntFromUnsignedShort(buf); int dataSize = 0; if (hasOption(eventOptions, CLIENT_EVENT_DATA_IS_PRESENT_OPTION)) { dataSize = buf.getInt(); } if (hasOption(eventOptions, 0x01)) { event.setTarget(Base64Util.encode(getNewByteArray(buf, PUBLIC_KEY_HASH_SIZE))); } event.setEventClassFqn(getUtf8String(buf, fqnLength)); if (dataSize > 0) { event.setEventData(getNewByteBuffer(buf, dataSize)); } else { event.setEventData(EMPTY_BUFFER); } events.add(event); } return events; }
private void parseProfileClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { int payloadLimitPosition = buf.position() + payloadLength; ProfileClientSync profileSync = new ProfileClientSync(); profileSync.setProfileBody(getNewByteBuffer(buf, buf.getInt())); while (buf.position() < payloadLimitPosition) { byte fieldId = buf.get(); // reading unused reserved field buf.get(); switch (fieldId) { case PUBLIC_KEY_FIELD_ID: profileSync.setEndpointPublicKey(getNewByteBuffer(buf, getIntFromUnsignedShort(buf))); break; case ACCESS_TOKEN_FIELD_ID: profileSync.setEndpointAccessToken(getUtf8String(buf)); break; default: break; } } sync.setProfileSync(profileSync); }