class ScriptedIncomingMapping implements MappingFunction<ExternalMessage, List<Adaptable>> {

    static NativeObject mapExternalMessageToNativeObject(final ExternalMessage message) {
        final NativeObject headersObj = new NativeObject();
        message.getHeaders().forEach((key, value) -> headersObj.put(key, headersObj, value));

        final NativeArrayBuffer bytePayload =
                message.getBytePayload()
                        .map(bb -> {
                            final NativeArrayBuffer nativeArrayBuffer = new NativeArrayBuffer(bb.remaining());
                            bb.get(nativeArrayBuffer.getBuffer());
                            return nativeArrayBuffer;
                        })
                        .orElse(null);

        final String contentType = message.getHeaders().get(ExternalMessage.CONTENT_TYPE_HEADER);
        final String textPayload = message.getTextPayload().orElse(null);

        final NativeObject externalMessage = new NativeObject();
        externalMessage.put(EXTERNAL_MESSAGE_HEADERS, externalMessage, headersObj);
        externalMessage.put(EXTERNAL_MESSAGE_TEXT_PAYLOAD, externalMessage, textPayload);
        externalMessage.put(EXTERNAL_MESSAGE_BYTE_PAYLOAD, externalMessage, bytePayload);
        externalMessage.put(EXTERNAL_MESSAGE_CONTENT_TYPE, externalMessage, contentType);
        return externalMessage;
    }

      ScriptedIncomingMapping(@Nullable final ContextFactory contextFactory, @Nullable final Scriptable scope);

}