package ch.ethz.syslab.telesto.common.protocol; import java.nio.ByteBuffer; import ch.ethz.syslab.telesto.common.util.ErrorType; import ch.ethz.syslab.telesto.common.protocol.handler.PacketProcessingException; import ch.ethz.syslab.telesto.common.protocol.handler.ProtocolHandler; /* * Do not edit this file! * * Edit the template at tools/protocol/telesto/templates/packet.java instead. */ public class ErrorPacket extends Packet { public ErrorType errorType; public String details; public ErrorPacket() { } public ErrorPacket(ErrorType errorType, String details) { this.errorType = errorType; this.details = details; } public ErrorPacket(int packetId, ErrorType errorType, String details) { this.packetId = packetId; this.errorType = errorType; this.details = details; } @Override public byte methodId() { return 5; } @Override public void emit(ByteBuffer buffer) { int lengthIndex = buffer.position(); buffer.position(lengthIndex + 2); buffer.put(methodId()); buffer.putInt(packetId); buffer.put((byte) errorType.ordinal()); putString(buffer, details); buffer.putShort(lengthIndex, (short) (buffer.position() - lengthIndex - 2)); } @Override public void parse(ByteBuffer buffer) { packetId = buffer.getInt(); errorType = ErrorType.values()[buffer.get()]; details = getString(buffer); } @Override public ErrorPacket newInstance() { return new ErrorPacket(); } public Packet getHandled(ProtocolHandler handler) throws PacketProcessingException { return handler.handle((ErrorPacket) this); } public String toString() { return "ErrorPacket"; } }