@Test public void testParsePurgeAll() throws Exception { byte[] msg = new byte[] {0, 0, 0, 8, 0, 0, 0, 5}; ByteBuf message = PooledByteBufAllocator.DEFAULT.buffer(msg.length); message.writeBytes(msg); Notification notification = MessageFactory.parse(Version.Version4, message); message.release(); assertTrue(notification instanceof PurgeAllMessage); assertEquals(MessageType.PurgeAll, ((PurgeAllMessage) notification).getType()); msg = new byte[] {0, 0, 0, 8, 0, 0, 0, 5}; message = PooledByteBufAllocator.DEFAULT.buffer(msg.length); message.writeBytes(msg); notification = MessageFactory.parse(Version.Version3, message); message.release(); assertTrue(notification instanceof PurgeAllMessage); assertEquals(MessageType.PurgeAll, ((PurgeAllMessage) notification).getType()); }
public static Notification parse(Version version, ByteBuf request) throws ErrorMessageException, UnknownSxpMessageTypeException, AddressLengthException, UnknownHostException, AttributeLengthException, TlvNotFoundException, UnknownPrefixException, UnknownNodeIdException, AttributeVariantException { request.resetReaderIndex(); byte[] headerLength, headerType, payload; int messageLength; try { headerLength = new byte[MESSAGE_HEADER_LENGTH_LENGTH]; request = request.readBytes(headerLength); headerType = new byte[MESSAGE_HEADER_TYPE_LENGTH]; request = request.readBytes(headerType); messageLength = ArraysUtil.bytes2int(headerLength); int payloadLength = messageLength - (MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH); payload = new byte[payloadLength]; request = request.readBytes(payload); } catch (IndexOutOfBoundsException | NegativeArraySizeException e) { throw new ErrorMessageException(ErrorCode.MessageHeaderError, e); } validate(headerLength.length + headerType.length, payload.length, messageLength); return decode(version, headerType, payload); }
MessageFactory { public static Notification parse(Version version, ByteBuf request) throws ErrorMessageException, UnknownSxpMessageTypeException, AddressLengthException, UnknownHostException, AttributeLengthException, TlvNotFoundException, UnknownPrefixException, UnknownNodeIdException, AttributeVariantException { request.resetReaderIndex(); byte[] headerLength, headerType, payload; int messageLength; try { headerLength = new byte[MESSAGE_HEADER_LENGTH_LENGTH]; request = request.readBytes(headerLength); headerType = new byte[MESSAGE_HEADER_TYPE_LENGTH]; request = request.readBytes(headerType); messageLength = ArraysUtil.bytes2int(headerLength); int payloadLength = messageLength - (MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH); payload = new byte[payloadLength]; request = request.readBytes(payload); } catch (IndexOutOfBoundsException | NegativeArraySizeException e) { throw new ErrorMessageException(ErrorCode.MessageHeaderError, e); } validate(headerLength.length + headerType.length, payload.length, messageLength); return decode(version, headerType, payload); } }
MessageFactory { public static Notification parse(Version version, ByteBuf request) throws ErrorMessageException, UnknownSxpMessageTypeException, AddressLengthException, UnknownHostException, AttributeLengthException, TlvNotFoundException, UnknownPrefixException, UnknownNodeIdException, AttributeVariantException { request.resetReaderIndex(); byte[] headerLength, headerType, payload; int messageLength; try { headerLength = new byte[MESSAGE_HEADER_LENGTH_LENGTH]; request = request.readBytes(headerLength); headerType = new byte[MESSAGE_HEADER_TYPE_LENGTH]; request = request.readBytes(headerType); messageLength = ArraysUtil.bytes2int(headerLength); int payloadLength = messageLength - (MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH); payload = new byte[payloadLength]; request = request.readBytes(payload); } catch (IndexOutOfBoundsException | NegativeArraySizeException e) { throw new ErrorMessageException(ErrorCode.MessageHeaderError, e); } validate(headerLength.length + headerType.length, payload.length, messageLength); return decode(version, headerType, payload); }  }
MessageFactory { public static Notification parse(Version version, ByteBuf request) throws ErrorMessageException, UnknownSxpMessageTypeException, AddressLengthException, UnknownHostException, AttributeLengthException, TlvNotFoundException, UnknownPrefixException, UnknownNodeIdException, AttributeVariantException { request.resetReaderIndex(); byte[] headerLength, headerType, payload; int messageLength; try { headerLength = new byte[MESSAGE_HEADER_LENGTH_LENGTH]; request = request.readBytes(headerLength); headerType = new byte[MESSAGE_HEADER_TYPE_LENGTH]; request = request.readBytes(headerType); messageLength = ArraysUtil.bytes2int(headerLength); int payloadLength = messageLength - (MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH); payload = new byte[payloadLength]; request = request.readBytes(payload); } catch (IndexOutOfBoundsException | NegativeArraySizeException e) { throw new ErrorMessageException(ErrorCode.MessageHeaderError, e); } validate(headerLength.length + headerType.length, payload.length, messageLength); return decode(version, headerType, 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 Notification parse(Version version, ByteBuf request) throws ErrorMessageException, UnknownSxpMessageTypeException, AddressLengthException, UnknownHostException, AttributeLengthException, TlvNotFoundException, UnknownPrefixException, UnknownNodeIdException, AttributeVariantException { request.resetReaderIndex(); byte[] headerLength, headerType, payload; int messageLength; try { headerLength = new byte[MESSAGE_HEADER_LENGTH_LENGTH]; request = request.readBytes(headerLength); headerType = new byte[MESSAGE_HEADER_TYPE_LENGTH]; request = request.readBytes(headerType); messageLength = ArraysUtil.bytes2int(headerLength); int payloadLength = messageLength - (MESSAGE_HEADER_LENGTH_LENGTH + MESSAGE_HEADER_TYPE_LENGTH); payload = new byte[payloadLength]; request = request.readBytes(payload); } catch (IndexOutOfBoundsException | NegativeArraySizeException e) { throw new ErrorMessageException(ErrorCode.MessageHeaderError, e); } validate(headerLength.length + headerType.length, payload.length, messageLength); return decode(version, headerType, 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);  }