@Test public void testDecodeOpen() throws Exception { OpenMessage message = (OpenMessage) MessageFactory.decodeOpen( new byte[] {0, 0, 0, 4, 0, 0, 0, 2, 80, 6, 6, 3, 0, 2, 0, 1, 0, 80, 7, 4, 0, 120, 0, -106}); assertNotNull(message); assertEquals(ConnectionMode.Listener, message.getSxpMode()); assertEquals(Version.Version4, message.getVersion()); assertEquals(MessageType.Open, message.getType()); message = (OpenMessage) MessageFactory.decodeOpen( new byte[] {0, 0, 0, 4, 0, 0, 0, 1, 80, 5, 4, -64, -88, 0, 1, 80, 7, 4, 0, 120, 0, -106}); assertNotNull(message); assertEquals(ConnectionMode.Speaker, message.getSxpMode()); assertEquals(Version.Version4, message.getVersion()); assertEquals(MessageType.Open, message.getType()); }
public static Notification decodeOpen(byte[] payload) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { OpenMessageBuilder messageBuilder = new OpenMessageBuilder(); messageBuilder.setType(MessageType.Open); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); Version version = extractVersion(payload); ConnectionMode nodeMode = ConnectionMode.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 4, 4))); AttributeList attributes = AttributeList.decode(ArraysUtil.readBytes(payload, 8)); messageBuilder.setVersion(version); messageBuilder.setSxpMode(nodeMode); messageBuilder.setAttribute(attributes); return messageBuilder.build(); }
MessageFactory { public static Notification decodeOpen(byte[] payload) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { OpenMessageBuilder messageBuilder = new OpenMessageBuilder(); messageBuilder.setType(MessageType.Open); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); Version version = extractVersion(payload); ConnectionMode nodeMode = ConnectionMode.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 4, 4))); AttributeList attributes = AttributeList.decode(ArraysUtil.readBytes(payload, 8)); messageBuilder.setVersion(version); messageBuilder.setSxpMode(nodeMode); messageBuilder.setAttribute(attributes); return messageBuilder.build(); } }
MessageFactory { public static Notification decodeOpen(byte[] payload) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { OpenMessageBuilder messageBuilder = new OpenMessageBuilder(); messageBuilder.setType(MessageType.Open); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); Version version = extractVersion(payload); ConnectionMode nodeMode = ConnectionMode.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 4, 4))); AttributeList attributes = AttributeList.decode(ArraysUtil.readBytes(payload, 8)); messageBuilder.setVersion(version); messageBuilder.setSxpMode(nodeMode); messageBuilder.setAttribute(attributes); return messageBuilder.build(); }  }
MessageFactory { public static Notification decodeOpen(byte[] payload) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { OpenMessageBuilder messageBuilder = new OpenMessageBuilder(); messageBuilder.setType(MessageType.Open); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); Version version = extractVersion(payload); ConnectionMode nodeMode = ConnectionMode.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 4, 4))); AttributeList attributes = AttributeList.decode(ArraysUtil.readBytes(payload, 8)); messageBuilder.setVersion(version); messageBuilder.setSxpMode(nodeMode); messageBuilder.setAttribute(attributes); return messageBuilder.build(); }  static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data); static ByteBuf createKeepalive(); static ByteBuf createOpen(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMinAcceptable); static ByteBuf createOpen(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMin,
            int holdTimeMax); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID,
            int holdTimeMinAcceptable); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMin,
            int holdTimeMax); static ByteBuf createPurgeAll(); static ByteBuf createUpdate(List<R> deleteBindings,
            List<T> addBindings, NodeId nodeId, List<CapabilityType> capabilities, SxpBindingFilter bindingFilter); static Notification decodeErrorMessage(byte[] payload); static Notification decodeKeepalive(byte[] payload); static Notification decodeOpen(byte[] payload); static Notification decodeOpenResp(byte[] payload); static Version extractVersion(final byte[] payload); static Notification decodePurgeAll(byte[] payload); static Notification decodeUpdate(byte[] payload); static Notification parse(Version version, ByteBuf request); static String toString(byte[] message); static String toString(ByteBuf message); static String toString(Notification message); static List<CapabilityType> decodeCapabilities(OpenMessage message); }
MessageFactory { public static Notification decodeOpen(byte[] payload) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { OpenMessageBuilder messageBuilder = new OpenMessageBuilder(); messageBuilder.setType(MessageType.Open); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); Version version = extractVersion(payload); ConnectionMode nodeMode = ConnectionMode.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 4, 4))); AttributeList attributes = AttributeList.decode(ArraysUtil.readBytes(payload, 8)); messageBuilder.setVersion(version); messageBuilder.setSxpMode(nodeMode); messageBuilder.setAttribute(attributes); return messageBuilder.build(); }  static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data); static ByteBuf createKeepalive(); static ByteBuf createOpen(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMinAcceptable); static ByteBuf createOpen(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMin,
            int holdTimeMax); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID,
            int holdTimeMinAcceptable); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode, NodeId nodeID, int holdTimeMin,
            int holdTimeMax); static ByteBuf createPurgeAll(); static ByteBuf createUpdate(List<R> deleteBindings,
            List<T> addBindings, NodeId nodeId, List<CapabilityType> capabilities, SxpBindingFilter bindingFilter); static Notification decodeErrorMessage(byte[] payload); static Notification decodeKeepalive(byte[] payload); static Notification decodeOpen(byte[] payload); static Notification decodeOpenResp(byte[] payload); static Version extractVersion(final byte[] payload); static Notification decodePurgeAll(byte[] payload); static Notification decodeUpdate(byte[] payload); static Notification parse(Version version, ByteBuf request); static String toString(byte[] message); static String toString(ByteBuf message); static String toString(Notification message); static List<CapabilityType> decodeCapabilities(OpenMessage message);  }