/** * Helper for serializing the header. * * @param buf The {@link ByteBuf} to serialize the header into. * @param messageType The {@link MessageType} of the message this header refers to. */ private static void writeHeader(final ByteBuf buf, final MessageType messageType) { buf.writeInt(VERSION); buf.writeInt(messageType.ordinal()); }
/** * De-serializes the header and returns the {@link MessageType}. * <pre> * <b>The buffer is expected to be at the header position.</b> * </pre> * @param buf The {@link ByteBuf} containing the serialized header. * @return The message type. * @throws IllegalStateException If unexpected message version or message type. */ public static MessageType deserializeHeader(final ByteBuf buf) { // checking the version int version = buf.readInt(); Preconditions.checkState(version == VERSION, "Version Mismatch: Found " + version + ", Expected: " + VERSION + '.'); // fetching the message type int msgType = buf.readInt(); MessageType[] values = MessageType.values(); Preconditions.checkState(msgType >= 0 && msgType < values.length, "Illegal message type with index " + msgType + '.'); return values[msgType]; }
/** * Helper for serializing the header. * * @param buf The {@link ByteBuf} to serialize the header into. * @param messageType The {@link MessageType} of the message this header refers to. */ private static void writeHeader(final ByteBuf buf, final MessageType messageType) { buf.writeInt(VERSION); buf.writeInt(messageType.ordinal()); }
/** * De-serializes the header and returns the {@link MessageType}. * <pre> * <b>The buffer is expected to be at the header position.</b> * </pre> * @param buf The {@link ByteBuf} containing the serialized header. * @return The message type. * @throws IllegalStateException If unexpected message version or message type. */ public static MessageType deserializeHeader(final ByteBuf buf) { // checking the version int version = buf.readInt(); Preconditions.checkState(version == VERSION, "Version Mismatch: Found " + version + ", Expected: " + VERSION + '.'); // fetching the message type int msgType = buf.readInt(); MessageType[] values = MessageType.values(); Preconditions.checkState(msgType >= 0 && msgType < values.length, "Illegal message type with index " + msgType + '.'); return values[msgType]; }
/** * Helper for serializing the header. * * @param buf The {@link ByteBuf} to serialize the header into. * @param messageType The {@link MessageType} of the message this header refers to. */ private static void writeHeader(final ByteBuf buf, final MessageType messageType) { buf.writeInt(VERSION); buf.writeInt(messageType.ordinal()); }
/** * De-serializes the header and returns the {@link MessageType}. * <pre> * <b>The buffer is expected to be at the header position.</b> * </pre> * @param buf The {@link ByteBuf} containing the serialized header. * @return The message type. * @throws IllegalStateException If unexpected message version or message type. */ public static MessageType deserializeHeader(final ByteBuf buf) { // checking the version int version = buf.readInt(); Preconditions.checkState(version == VERSION, "Version Mismatch: Found " + version + ", Expected: " + VERSION + '.'); // fetching the message type int msgType = buf.readInt(); MessageType[] values = MessageType.values(); Preconditions.checkState(msgType >= 0 && msgType < values.length, "Illegal message type with index " + msgType + '.'); return values[msgType]; }