package net.openhft.performance.tests.network;

import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.network.WireTcpHandler;
import net.openhft.chronicle.network.api.session.SessionDetailsProvider;
import net.openhft.chronicle.wire.Wire;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

/**
 * This code is used to read the tid and payload from a wire message,
 * and send the same tid and message back to the client
 */
public class WireEchoRequestHandler extends WireTcpHandler {

    public WireEchoRequestHandler(@NotNull Function<Bytes, Wire> bytesToWire) {
        super(bytesToWire);
    }


    /**
     * simply reads the csp,tid and payload and sends back the tid and payload
     *
     * @param inWire  the wire from the client
     * @param outWire the wire to be sent back to the server
     * @param sd      details about this session
     */
    @Override
    protected void process(@NotNull WireIn inWire,
                           @NotNull WireOut outWire,
                           @NotNull SessionDetailsProvider sd) {
        inWire.readDocument(null, d -> outWire.writeDocument(false, data -> data
                .writeEventName(() -> "payloadResponse").text(inWire.readEventName(new StringBuilder()).text())));
    }
}

@@ -1200,18 +1200,26 @@
 ent(
-null, d -%3E
+m -%3E %7B%0A           
  out
@@ -1241,140 +1241,286 @@
 ent(
-false, data -%3E data%0A                .writeEventName(() -%3E %22payloadResponse%22).text(inWire.readEventName(new StringBuilder()).text()))
+true, meta -%3E meta.write(() -%3E %22tid%22)%0A                    .int64(inWire.read(() -%3E %22tid%22).int64()));%0A        %7D, d -%3E %7B%0A            outWire.writeDocument(false, data -%3E data.write(() -%3E %22payloadResponse%22)%0A                    .text(inWire.read(() -%3E %22payload%22).text()));%0A        %7D
 );%0A 

Fix bug WireEchoRH