package edu.cmu.cs.diamond.opendiamond;

import java.nio.ByteBuffer;

public final class MiniRPCMessage {
    public final static int MINIRPC_OK = 0;
    public final static int MINIRPC_PENDING = -1;
    public final static int MINIRPC_ENCODING_ERR = -2;
    public final static int MINIRPC_PROCEDURE_UNAVAIL = -3;
    public final static int MINIRPC_INVALID_ARGUMENT = -4;
    public final static int MINIRPC_INVALID_PROTOCOL = -5;
    public final static int MINIRPC_NETWORK_FAILURE = -6;

    private final long sequence;

    private final int status;

    private final int cmd;

    private final ByteBuffer data;

    public MiniRPCMessage(long sequence, int status, int cmd, ByteBuffer data) {
        if ((sequence < 0) || (sequence > 0xFFFFFFFFL)) {
            throw new IllegalArgumentException(
                    "sequence must be between 0 and " + 0xFFFFFFFFL
                            + ", given: " + sequence);
        }

        this.sequence = sequence;
        this.status = status;
        this.cmd = cmd;
        this.data = data.asReadOnlyBuffer();
    }

    public long getSequence() {
        return sequence;
    }

    public int getStatus() {
        return status;
    }

    public int getCmd() {
        return cmd;
    }

    public ByteBuffer getData() {
        return data;
    }
}

@@ -1311,11 +1311,891 @@
 a;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        return %22sequence: %22 + sequence + %22, status: %22 + statusToString(status)%0A                + %22, cmd: %22 + cmd + %22, data: %22 + data;%0A    %7D%0A%0A    private static String statusToString(int s) %7B%0A        switch (s) %7B%0A        case MINIRPC_OK:%0A            return %22MINIRPC_OK%22;%0A        case MINIRPC_PENDING:%0A            return %22MINIRPC_PENDING%22;%0A        case MINIRPC_ENCODING_ERR:%0A            return %22MINIRPC_ENCODING_ERR%22;%0A        case MINIRPC_PROCEDURE_UNAVAIL:%0A            return %22MINIRPC_PROCEDURE_UNAVAIL%22;%0A        case MINIRPC_INVALID_ARGUMENT:%0A            return %22MINIRPC_INVALID_ARGUMENT%22;%0A        case MINIRPC_INVALID_PROTOCOL:%0A            return %22MINIRPC_INVALID_PROTOCOL%22;%0A        case MINIRPC_NETWORK_FAILURE:%0A            return %22MINIRPC_NETWORK_FAILURE%22;%0A        default:%0A            return Integer.toString(s);%0A%0A        %7D%0A    %7D
 %0A%7D%0A

Add toString to MiniRPCMessage