@Test public void testCreateError() throws Exception { ByteBuf message = MessageFactory.createError(ErrorCode.MessageHeaderError, ErrorSubCode.MalformedAttributeList, null); assertNotNull(message); assertArrayEquals(new byte[] {0, 0, 0, 12, 0, 0, 0, 4, -127, 1, 0, 0}, toBytes(message)); message = MessageFactory.createError(ErrorCode.OpenMessageError, ErrorSubCode.UnrecognizedWellKnownAttribute, null); assertArrayEquals(new byte[] {0, 0, 0, 12, 0, 0, 0, 4, -126, 2, 0, 0}, toBytes(message)); message = MessageFactory.createError(ErrorCode.UpdateMessageError, ErrorSubCode.MissingWellKnownAttribute, null); assertArrayEquals(new byte[] {0, 0, 0, 12, 0, 0, 0, 4, -125, 3, 0, 0}, toBytes(message)); for (byte i = 4; i < 11; i++) { message = MessageFactory.createError(ErrorCode.UpdateMessageError, ErrorSubCode.forValue(i), null); assertArrayEquals(new byte[] {0, 0, 0, 12, 0, 0, 0, 4, -125, i, 0, 0}, toBytes(message)); } MessageFactory.createError(ErrorCode.OpenMessageError, ErrorSubCode.MalformedAttribute, new byte[5]); exception.expect(ErrorCodeDataLengthException.class); MessageFactory.createError(ErrorCode.MessageHeaderError, ErrorSubCode.MalformedAttributeList, new byte[11]); }
public static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data) throws ErrorCodeDataLengthException { if (data == null) { data = new byte[0]; } else if (data.length > 10) { throw new ErrorCodeDataLengthException("Variable message length - 10 bytes."); } byte _errorCode = errorCode != null ? (byte) errorCode.getIntValue() : 0x00; byte _errorSubCode = errorSubCode != null ? (byte) errorSubCode.getIntValue() : 0x00; byte[] payload = ArraysUtil.combine(new byte[] {ArraysUtil.setBit(_errorCode, 8, true), _errorSubCode, 0x00, 0x00}, data); return getMessage(MessageType.Error, payload); }
MessageFactory { public static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data) throws ErrorCodeDataLengthException { if (data == null) { data = new byte[0]; } else if (data.length > 10) { throw new ErrorCodeDataLengthException("Variable message length - 10 bytes."); } byte _errorCode = errorCode != null ? (byte) errorCode.getIntValue() : 0x00; byte _errorSubCode = errorSubCode != null ? (byte) errorSubCode.getIntValue() : 0x00; byte[] payload = ArraysUtil.combine(new byte[] {ArraysUtil.setBit(_errorCode, 8, true), _errorSubCode, 0x00, 0x00}, data); return getMessage(MessageType.Error, payload); } }
MessageFactory { public static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data) throws ErrorCodeDataLengthException { if (data == null) { data = new byte[0]; } else if (data.length > 10) { throw new ErrorCodeDataLengthException("Variable message length - 10 bytes."); } byte _errorCode = errorCode != null ? (byte) errorCode.getIntValue() : 0x00; byte _errorSubCode = errorSubCode != null ? (byte) errorSubCode.getIntValue() : 0x00; byte[] payload = ArraysUtil.combine(new byte[] {ArraysUtil.setBit(_errorCode, 8, true), _errorSubCode, 0x00, 0x00}, data); return getMessage(MessageType.Error, payload); }  }
MessageFactory { public static ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data) throws ErrorCodeDataLengthException { if (data == null) { data = new byte[0]; } else if (data.length > 10) { throw new ErrorCodeDataLengthException("Variable message length - 10 bytes."); } byte _errorCode = errorCode != null ? (byte) errorCode.getIntValue() : 0x00; byte _errorSubCode = errorSubCode != null ? (byte) errorSubCode.getIntValue() : 0x00; byte[] payload = ArraysUtil.combine(new byte[] {ArraysUtil.setBit(_errorCode, 8, true), _errorSubCode, 0x00, 0x00}, data); return getMessage(MessageType.Error, payload); }  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 ByteBuf createError(ErrorCode errorCode, ErrorSubCode errorSubCode, byte[] data) throws ErrorCodeDataLengthException { if (data == null) { data = new byte[0]; } else if (data.length > 10) { throw new ErrorCodeDataLengthException("Variable message length - 10 bytes."); } byte _errorCode = errorCode != null ? (byte) errorCode.getIntValue() : 0x00; byte _errorSubCode = errorSubCode != null ? (byte) errorSubCode.getIntValue() : 0x00; byte[] payload = ArraysUtil.combine(new byte[] {ArraysUtil.setBit(_errorCode, 8, true), _errorSubCode, 0x00, 0x00}, data); return getMessage(MessageType.Error, payload); }  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);  }