private static byte[] getNewByteArray(ByteBuffer buf, int size) { return getNewByteArray(buf, size, true); }
private static String getUtf8String(ByteBuffer buf, int size) { return new String(getNewByteArray(buf, size), UTF8); }
private static ByteBuffer getNewByteBuffer(ByteBuffer buf, int size, boolean withPadding) { return ByteBuffer.wrap(getNewByteArray(buf, size, withPadding)); }
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 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; }