@Test public void testDecodeErrorMessage() throws Exception { ErrorMessage message = (ErrorMessage) MessageFactory.decodeErrorMessage(new byte[] {-127, 1, 0, 0}); assertNotNull(message); assertEquals(ErrorType.Extended, message.getErrorType()); assertEquals(ErrorCode.MessageHeaderError, message.getErrorCode()); assertEquals(ErrorSubCode.MalformedAttributeList, message.getErrorSubCode()); message = (ErrorMessage) MessageFactory.decodeErrorMessage(new byte[] {-126, 2, 0, 0}); assertNotNull(message); assertEquals(ErrorType.Extended, message.getErrorType()); assertEquals(ErrorCode.OpenMessageError, message.getErrorCode()); assertEquals(ErrorSubCode.UnrecognizedWellKnownAttribute, message.getErrorSubCode()); message = (ErrorMessage) MessageFactory.decodeErrorMessage(new byte[] {-125, 3, 0, 0}); assertNotNull(message); assertEquals(ErrorType.Extended, message.getErrorType()); assertEquals(ErrorCode.UpdateMessageError, message.getErrorCode()); assertEquals(ErrorSubCode.MissingWellKnownAttribute, message.getErrorSubCode()); for (byte i = 4; i < 11; i++) { message = (ErrorMessage) MessageFactory.decodeErrorMessage(new byte[] {-125, i, 0, 0}); assertNotNull(message); assertEquals(ErrorType.Extended, message.getErrorType()); assertEquals(ErrorCode.UpdateMessageError, message.getErrorCode()); assertEquals(ErrorSubCode.forValue(i), message.getErrorSubCode()); } }
public static Notification decodeErrorMessage(byte[] payload) { ErrorMessageBuilder messageBuilder = new ErrorMessageBuilder(); messageBuilder.setType(MessageType.Error); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); if (ArraysUtil.getBit(payload[0], 8) == 1) { messageBuilder.setErrorType(ErrorType.Extended); messageBuilder.setErrorCode(ErrorCode.forValue(payload[0] & 0x7F)); messageBuilder.setErrorSubCode(ErrorSubCode.forValue(payload[1])); messageBuilder.setData(ArraysUtil.readBytes(payload, 2)); messageBuilder.setInformation( messageBuilder.getErrorCode() + " | " + messageBuilder.getErrorSubCode() + getInformation( messageBuilder.getData())); return messageBuilder.build(); } messageBuilder.setErrorType(ErrorType.Legacy); messageBuilder.setErrorCodeNonExtended( ErrorCodeNonExtended.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 2, 2)))); messageBuilder.setData(ArraysUtil.readBytes(payload, 4)); messageBuilder.setInformation( messageBuilder.getErrorCodeNonExtended() + getInformation(messageBuilder.getData())); return messageBuilder.build(); }
MessageFactory { public static Notification decodeErrorMessage(byte[] payload) { ErrorMessageBuilder messageBuilder = new ErrorMessageBuilder(); messageBuilder.setType(MessageType.Error); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); if (ArraysUtil.getBit(payload[0], 8) == 1) { messageBuilder.setErrorType(ErrorType.Extended); messageBuilder.setErrorCode(ErrorCode.forValue(payload[0] & 0x7F)); messageBuilder.setErrorSubCode(ErrorSubCode.forValue(payload[1])); messageBuilder.setData(ArraysUtil.readBytes(payload, 2)); messageBuilder.setInformation( messageBuilder.getErrorCode() + " | " + messageBuilder.getErrorSubCode() + getInformation( messageBuilder.getData())); return messageBuilder.build(); } messageBuilder.setErrorType(ErrorType.Legacy); messageBuilder.setErrorCodeNonExtended( ErrorCodeNonExtended.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 2, 2)))); messageBuilder.setData(ArraysUtil.readBytes(payload, 4)); messageBuilder.setInformation( messageBuilder.getErrorCodeNonExtended() + getInformation(messageBuilder.getData())); return messageBuilder.build(); } }
MessageFactory { public static Notification decodeErrorMessage(byte[] payload) { ErrorMessageBuilder messageBuilder = new ErrorMessageBuilder(); messageBuilder.setType(MessageType.Error); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); if (ArraysUtil.getBit(payload[0], 8) == 1) { messageBuilder.setErrorType(ErrorType.Extended); messageBuilder.setErrorCode(ErrorCode.forValue(payload[0] & 0x7F)); messageBuilder.setErrorSubCode(ErrorSubCode.forValue(payload[1])); messageBuilder.setData(ArraysUtil.readBytes(payload, 2)); messageBuilder.setInformation( messageBuilder.getErrorCode() + " | " + messageBuilder.getErrorSubCode() + getInformation( messageBuilder.getData())); return messageBuilder.build(); } messageBuilder.setErrorType(ErrorType.Legacy); messageBuilder.setErrorCodeNonExtended( ErrorCodeNonExtended.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 2, 2)))); messageBuilder.setData(ArraysUtil.readBytes(payload, 4)); messageBuilder.setInformation( messageBuilder.getErrorCodeNonExtended() + getInformation(messageBuilder.getData())); return messageBuilder.build(); }  }
MessageFactory { public static Notification decodeErrorMessage(byte[] payload) { ErrorMessageBuilder messageBuilder = new ErrorMessageBuilder(); messageBuilder.setType(MessageType.Error); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); if (ArraysUtil.getBit(payload[0], 8) == 1) { messageBuilder.setErrorType(ErrorType.Extended); messageBuilder.setErrorCode(ErrorCode.forValue(payload[0] & 0x7F)); messageBuilder.setErrorSubCode(ErrorSubCode.forValue(payload[1])); messageBuilder.setData(ArraysUtil.readBytes(payload, 2)); messageBuilder.setInformation( messageBuilder.getErrorCode() + " | " + messageBuilder.getErrorSubCode() + getInformation( messageBuilder.getData())); return messageBuilder.build(); } messageBuilder.setErrorType(ErrorType.Legacy); messageBuilder.setErrorCodeNonExtended( ErrorCodeNonExtended.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 2, 2)))); messageBuilder.setData(ArraysUtil.readBytes(payload, 4)); messageBuilder.setInformation( messageBuilder.getErrorCodeNonExtended() + getInformation(messageBuilder.getData())); 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 decodeErrorMessage(byte[] payload) { ErrorMessageBuilder messageBuilder = new ErrorMessageBuilder(); messageBuilder.setType(MessageType.Error); messageBuilder.setLength(MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH + payload.length); messageBuilder.setPayload(payload); if (ArraysUtil.getBit(payload[0], 8) == 1) { messageBuilder.setErrorType(ErrorType.Extended); messageBuilder.setErrorCode(ErrorCode.forValue(payload[0] & 0x7F)); messageBuilder.setErrorSubCode(ErrorSubCode.forValue(payload[1])); messageBuilder.setData(ArraysUtil.readBytes(payload, 2)); messageBuilder.setInformation( messageBuilder.getErrorCode() + " | " + messageBuilder.getErrorSubCode() + getInformation( messageBuilder.getData())); return messageBuilder.build(); } messageBuilder.setErrorType(ErrorType.Legacy); messageBuilder.setErrorCodeNonExtended( ErrorCodeNonExtended.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(payload, 2, 2)))); messageBuilder.setData(ArraysUtil.readBytes(payload, 4)); messageBuilder.setInformation( messageBuilder.getErrorCodeNonExtended() + getInformation(messageBuilder.getData())); 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);  }