private static ByteBuffer getNewByteBuffer(ByteBuffer buf, int size) { return getNewByteBuffer(buf, size, true); }
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); }
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); }
private void parseClientSyncMetaData(ClientSync sync, ByteBuffer buf, int options, int payloadLength) throws PlatformEncDecException { sync.setRequestId(buf.getInt()); ClientSyncMetaData md = new ClientSyncMetaData(); if (hasOption(options, CLIENT_META_SYNC_TIMEOUT_OPTION)) { md.setTimeout((long) buf.getInt()); } if (hasOption(options, CLIENT_META_SYNC_KEY_HASH_OPTION)) { md.setEndpointPublicKeyHash(getNewByteBuffer(buf, PUBLIC_KEY_HASH_SIZE)); } if (hasOption(options, CLIENT_META_SYNC_PROFILE_HASH_OPTION)) { md.setProfileHash(getNewByteBuffer(buf, PROFILE_HASH_SIZE)); } if (hasOption(options, CLIENT_META_SYNC_SDK_TOKEN_OPTION)) { md.setSdkToken(getUtf8String(buf, Constants.SDK_TOKEN_SIZE)); } sync.setClientSyncMetaData(md); }
private void parseConfigurationClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { ConfigurationClientSync confSync = new ConfigurationClientSync(); if (hasOption(options, CONFIGURATION_HASH_OPTION)) { confSync.setConfigurationHash(getNewByteBuffer(buf, CONFIGURATION_HASH_SIZE)); } if (hasOption(options, CONFIGURATION_RESYNC_OPTION)) { confSync.setResyncOnly(true); } sync.setConfigurationSync(confSync); }
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; }