class LumberjackFrameHandler {

    public void handle(final LumberjackFrame frame, final ChannelResponder<SocketChannel> responder, final String sender)
            throws IOException, InterruptedException {

        final Map<String, String> metadata = EventFactoryUtil.createMapWithSender(sender.toString());
        metadata.put(LumberjackMetadata.SEQNUMBER_KEY, String.valueOf(frame.getSeqNumber()));
        String line = "";

        /* If frameType is a data Frame, Handle the Lumberjack data payload, iterating over it and extracting
        keys and values into metadata.

        All keys are inserted into metadata with the exception of line that gets added into the body of the event
        */
        if (frame.getFrameType() == 0x44) {
            ByteBuffer currentData = ByteBuffer.wrap(frame.getPayload());
            long pairCount = currentData.getInt() & 0x00000000ffffffffL;
            Map<String,String> fields = new HashMap<>();
            for (int i = 0; i < pairCount; i++) {
                long keyLength = currentData.getInt() & 0x00000000ffffffffL;
                byte[] bytes = new byte[(int) keyLength];
                currentData.get(bytes);
                String key = new String(bytes);
                long valueLength = currentData.getInt() & 0x00000000ffffffffL;
                bytes = new byte[(int) valueLength];
                currentData.get(bytes);
                String value = new String(bytes);

                if (key.equals("line")) {
                    line = value;
                } else {
                    fields.put(key, value);
                }
            }
            // Serialize the fields into a String to push it via metdate
            Gson serialFields = new Gson();

            metadata.put("lumberjack.fields", serialFields.toJson(fields).toString());

            // queue the raw event blocking until space is available, reset the buffer
            final E event = eventFactory.create(line.getBytes(), metadata, responder);
            events.offer(event);
        } else if (frame.getFrameType() == 0x4A ) {
            logger.error("Data type was JSON. JSON payload aren't yet supported, pending the documentation of Lumberjack protocol v2");
        }
    }

    public  LumberjackFrameHandler(final SelectionKey selectionKey,
                                  final Charset charset,
                                  final EventFactory<E> eventFactory,
                                  final BlockingQueue<E> events,
                                  final AsyncChannelDispatcher dispatcher,
                                  final ComponentLog logger);

}