private void buildExtensionHeader(GrowingByteBuffer buf, short extensionId, byte optionA, byte optionB, int length) { buf.putShort(extensionId); buf.put(optionA); buf.put(optionB); buf.putInt(length); }
private void encode(GrowingByteBuffer buf, BootstrapServerSync bootstrapSync) { buildExtensionHeader(buf, BOOTSTRAP_EXTENSION_ID, NOTHING, NOTHING, 0); final int extPosition = buf.position(); buf.putShort((short) bootstrapSync.getRequestId()); buf.putShort((short) bootstrapSync.getProtocolList().size()); for (ProtocolConnectionData data : bootstrapSync.getProtocolList()) { buf.putInt(data.getAccessPointId()); buf.putInt(data.getProtocolId()); buf.putShort((short) data.getProtocolVersion()); buf.putShort((short) data.getConnectionData().length); put(buf, data.getConnectionData()); } buf.putInt(extPosition - SIZE_OF_INT, buf.position() - extPosition); }
private void encode(GrowingByteBuffer buf, LogServerSync logSync) { List<LogDeliveryStatus> statusList = logSync.getDeliveryStatuses(); int extensionSize = 4; if (statusList != null) { extensionSize += 4 * statusList.size(); } buildExtensionHeader(buf, LOGGING_EXTENSION_ID, NOTHING, NOTHING, extensionSize); if (statusList != null && !statusList.isEmpty()) { buf.putInt(statusList.size()); for (LogDeliveryStatus status : statusList) { buf.putShort((short) status.getRequestId()); buf.put(status.getResult() == SyncStatus.SUCCESS ? SUCCESS : FAILURE); buf.put(status.getErrorCode() != null ? (byte) status.getErrorCode().ordinal() : NOTHING); } } else { buf.putInt(0); } }
buf.put(EVENT_LISTENERS_RESPONSE_FIELD_ID); buf.put(NOTHING); buf.putShort((short) eventSync.getEventListenersResponses().size()); for (EventListenersResponse response : eventSync.getEventListenersResponses()) { buf.putShort((short) response.getRequestId()); buf.putShort(response.getResult() == SyncStatus.SUCCESS ? SUCCESS : FAILURE); if (response.getListeners() != null) { buf.putInt(response.getListeners().size()); buf.put(EVENT_LIST_RESPONSE_FIELD_ID); buf.put(NOTHING); buf.putShort((short) eventSync.getEvents().size()); for (Event event : eventSync.getEvents()) { boolean eventDataIsEmpty = event.getEventData() == null || event.getEventData().array().length == 0; if (!eventDataIsEmpty) { buf.putShort(EVENT_DATA_IS_EMPTY_OPTION); } else { buf.putShort(NOTHING); buf.putShort((short) event.getEventClassFqn().length()); if (!eventDataIsEmpty) { buf.putInt(event.getEventData().array().length);
buf.putShort((short) (uaResponse.getErrorCode() != null ? uaResponse.getErrorCode().ordinal() : 0)); if (uaResponse.getErrorReason() != null) { byte[] data = uaResponse.getErrorReason().getBytes(UTF8); buf.putShort((short) data.length); put(buf, data); } else { buf.putShort((short) 0); buf.put(USER_ATTACH_NOTIFICATION_FIELD_ID); buf.put((byte) nf.getUserExternalId().length()); buf.putShort((short) nf.getEndpointAccessToken().length()); putUtf(buf, nf.getUserExternalId()); putUtf(buf, nf.getEndpointAccessToken()); buf.put(USER_DETACH_NOTIFICATION_FIELD_ID); buf.put(NOTHING); buf.putShort((short) nf.getEndpointAccessToken().length()); putUtf(buf, nf.getEndpointAccessToken()); buf.put(ENDPOINT_ATTACH_RESPONSE_FIELD_ID); buf.put(NOTHING); buf.putShort((short) userSync.getEndpointAttachResponses().size()); for (EndpointAttachResponse response : userSync.getEndpointAttachResponses()) { buf.put(response.getResult() == SyncStatus.SUCCESS ? SUCCESS : FAILURE); buf.putShort((short) response.getRequestId()); if (response.getEndpointKeyHash() != null) {
buf.put(NF_TOPICS_FIELD_ID); buf.put(NOTHING); buf.putShort((short) notificationSync.getAvailableTopics().size()); for (Topic t : notificationSync.getAvailableTopics()) { buf.putLong(t.getIdAsLong()); buf.put(t.getSubscriptionType() == SubscriptionType.MANDATORY ? MANDATORY : OPTIONAL); buf.put(NOTHING); buf.putShort((short) t.getName().getBytes(UTF8).length); putUtf(buf, t.getName()); buf.put(NF_NOTIFICATIONS_FIELD_ID); buf.put(NOTHING); buf.putShort((short) notificationSync.getNotifications().size()); for (Notification nf : notificationSync.getNotifications()) { buf.putInt((nf.getSeqNumber() != null) ? nf.getSeqNumber() : 0); buf.put(nf.getType() == NotificationType.SYSTEM ? SYSTEM : CUSTOM); buf.put(NOTHING); buf.putShort(nf.getUid() != null ? (short) nf.getUid().length() : (short) 0); buf.putInt(nf.getBody().array().length); long topicId = nf.getTopicId() != null ? nf.getTopicIdAsLong() : 0L;
GrowingByteBuffer buf = new GrowingByteBuffer(DEFAULT_BUFFER_SIZE); buf.putInt(getId()); buf.putShort(PROTOCOL_VERSION); buf.putShort(NOTHING); // will be updated later encodeMetaData(buf, sync); short extensionCount = 1; buf.putShort(EXTENSIONS_COUNT_POSITION, extensionCount); byte[] result = buf.toByteArray(); if (LOG.isTraceEnabled()) {