package io.cozmic.usher.plugins.core;

import io.cozmic.usher.core.EncoderPlugin;
import io.cozmic.usher.message.Message;
import io.cozmic.usher.message.PipelinePack;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;

/**
 * Created by chuck on 7/9/15.
 */
public class PayloadEncoder implements EncoderPlugin {
    private JsonObject configObj;
    private Vertx vertx;

    @Override
    public void encode(PipelinePack pipelinePack, Handler<Buffer> bufferHandler) {
        final Message message = pipelinePack.getMessage();
        bufferHandler.handle(message.getPayload());
    }

    @Override
    public EncoderPlugin createNew() {
        return this;
    }

    @Override
    public void init(JsonObject configObj, Vertx vertx) {

        this.configObj = configObj;
        this.vertx = vertx;
    }
}

@@ -291,16 +291,60 @@
 nObject;
+%0Aimport org.apache.commons.codec.binary.Hex;
 %0A%0A/**%0A *
@@ -489,16 +489,41 @@
 x vertx;
+%0A    private boolean hex;
 %0A%0A    @O
@@ -672,16 +672,217 @@
 sage();%0A
+%0A%0A        if (hex) %7B%0A            final char%5B%5D chars = Hex.encodeHex(message.getPayload().getBytes());%0A            bufferHandler.handle(Buffer.buffer(new String(chars)));%0A            return;%0A        %7D%0A%0A
         
@@ -1118,24 +1118,24 @@
  configObj;%0A
-
         this
@@ -1145,21 +1145,77 @@
 rtx = vertx;
+%0A%0A        this.hex = configObj.getBoolean(%22hex%22, false);
 %0A    %7D%0A%7D%0A

Add hex option to the PayloadEncoder