// Path: src/org/gearman/core/GearmanPacket.java
// public static enum Magic {
// 	/**
// 	 * A request packet is sent to the server to request a service.<br>
// 	 * Magic code = "\0REQ" = 5391697
// 	 */
// 	REQ(5391697),
//     	
// 	/**
// 	 * A response packet is sent from the server to a client or worker as a response
// 	 * from handling a request.<br>
// 	 * Magic code = "\0RES" = 5391699
// 	 */
// 	RES(5391699);
//     	
// 	/** The magic number */
// 	private final int code;
//     	
// 	private Magic(int code) {
// 		this.code = code;
// 	}
//     	
// 	/**
// 	 * Returns the magic code
// 	 * @return
// 	 * 		The magic code.
// 	 */
// 	public final int getMagicCode() {
// 		return code;
// 	}
//     	
// 	/**
// 	 * Gets the <code>Magic</code> enumerator based on the magic code 
// 	 * @param code
// 	 * 		The magic code.
// 	 * @return
// 	 * 		The Magic object. If the code is invalid, null is returned
// 	 */
// 	public static final Magic fromMagicCode(final int code) {
// 		switch(code) {
// 		case 5391697:
// 			return REQ;
// 		case 5391699:
// 			return RES;
// 		default:
// 			return null;
// 		}
// 	}
// }
// 
// Path: src/org/gearman/core/GearmanPacket.java
// public static enum Type{
// 	TEXT(0,1), CAN_DO(1,1), CANT_DO(2,1), RESET_ABILITIES(3,0), PRE_SLEEP(4,0), UNUSED(5,0),
// 	NOOP(6,0), SUBMIT_JOB(7,3), JOB_CREATED(8,1), GRAB_JOB(9,0), NO_JOB(10,0), JOB_ASSIGN(11,3),
// 	WORK_STATUS(12, 3), WORK_COMPLETE(13,2), WORK_FAIL(14,1), GET_STATUS(15,1), ECHO_REQ(16,1),
// 	ECHO_RES(17,1), SUBMIT_JOB_BG(18,3), ERROR(19, 2), STATUS_RES(20, 5), SUBMIT_JOB_HIGH(21,3),
// 	SET_CLIENT_ID(22,1), CAN_DO_TIMEOUT(23,2), ALL_YOURS(24,0), WORK_EXCEPTION(25,2),
// 	OPTION_REQ(26,1), OPTION_RES(27,1), WORK_DATA(28,2), WORK_WARNING(29, 2), GRAB_JOB_UNIQ(30,0),
// 	JOB_ASSIGN_UNIQ(31,4), SUBMIT_JOB_HIGH_BG(32,3), SUBMIT_JOB_LOW(33,3), SUBMIT_JOB_LOW_BG(34,3),
// 	SUBMIT_JOB_SCHED(35,8), SUBMIT_JOB_EPOCH(36,4);
//     	
// 	private final int type;
// 	private final int args;
// 	private Type(final int type, final int args) {
// 		this.type = type;
// 		this.args = args;
// 	}
//     	
// 	public final int getTypeValue() {
// 		return type;
// 	}
// 	public final int getArgumentCount() {
// 		return args;
// 	}
//     	
// 	public static final Type fromTypeValue(final int value) {
// 		switch(value) {
// 		case(0): return TEXT; 				case(1): return CAN_DO;			case(2): return CANT_DO;
// 		case(3): return RESET_ABILITIES; 	case(4): return PRE_SLEEP;			case(5): return UNUSED;
// 		case(6): return NOOP;				case(7): return SUBMIT_JOB;		case(8): return JOB_CREATED;
// 		case(9): return GRAB_JOB;			case(10): return NO_JOB; 			case(11): return JOB_ASSIGN;
// 		case(12): return WORK_STATUS;		case(13): return WORK_COMPLETE;	case(14): return WORK_FAIL;
// 		case(15): return GET_STATUS;		case(16): return ECHO_REQ;			case(17): return ECHO_RES;
// 		case(18): return SUBMIT_JOB_BG;	case(19): return ERROR;			case(20): return STATUS_RES;
// 		case(21): return SUBMIT_JOB_HIGH;	case(22): return SET_CLIENT_ID;	case(23): return CAN_DO_TIMEOUT;
// 		case(24): return ALL_YOURS;		case(25): return WORK_EXCEPTION;	case(26): return OPTION_REQ;
// 		case(27): return OPTION_RES;		case(28): return WORK_DATA;		case(29): return WORK_WARNING;
// 		case(30): return GRAB_JOB_UNIQ;	case(31): return JOB_ASSIGN_UNIQ;	case(32): return SUBMIT_JOB_HIGH_BG;
// 		case(33): return SUBMIT_JOB_LOW;	case(34): return SUBMIT_JOB_LOW_BG;case(35): return SUBMIT_JOB_SCHED; 
// 		case(36): return SUBMIT_JOB_EPOCH;
// 		default:
// 			return null;
// 		}
// 	}
// }


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.gearman.core.GearmanPacket.Magic;
import org.gearman.core.GearmanPacket.Type;
		return packet.toBytes();
	}

	@Override
	public final void init(final GearmanCodecChannel<Integer> channel) {
		channel.setCodecAttachement(FORMAT);
	}
	
	private final void format(final GearmanCodecChannel<Integer> channel) {
		final ByteBuffer buffer = channel.getBuffer();
		if(buffer.hasRemaining()) return;
		
		if(buffer.get(0)==0) {
			buffer.limit(HEADER_SIZE);
			channel.setCodecAttachement(HEADER);
		} else {
			channel.setCodecAttachement(TEXT);
			text(channel);
		}
	}
	
	private final void header(final GearmanCodecChannel<Integer> channel) {
		ByteBuffer buffer = channel.getBuffer();
		if(buffer.hasRemaining()) return;
		
		final int size = buffer.getInt(SIZE_POS);
		
		if(size==0) {
			buffer.flip();
			
// Path: src/org/gearman/core/GearmanPacket.java
// public static enum Magic {
// 	/**
// 	 * A request packet is sent to the server to request a service.<br>
// 	 * Magic code = "\0REQ" = 5391697
// 	 */
// 	REQ(5391697),
//     	
// 	/**
// 	 * A response packet is sent from the server to a client or worker as a response
// 	 * from handling a request.<br>
// 	 * Magic code = "\0RES" = 5391699
// 	 */
// 	RES(5391699);
//     	
// 	/** The magic number */
// 	private final int code;
//     	
// 	private Magic(int code) {
// 		this.code = code;
// 	}
//     	
// 	/**
// 	 * Returns the magic code
// 	 * @return
// 	 * 		The magic code.
// 	 */
// 	public final int getMagicCode() {
// 		return code;
// 	}
//     	
// 	/**
// 	 * Gets the <code>Magic</code> enumerator based on the magic code 
// 	 * @param code
// 	 * 		The magic code.
// 	 * @return
// 	 * 		The Magic object. If the code is invalid, null is returned
// 	 */
// 	public static final Magic fromMagicCode(final int code) {
// 		switch(code) {
// 		case 5391697:
// 			return REQ;
// 		case 5391699:
// 			return RES;
// 		default:
// 			return null;
// 		}
// 	}
// }
// 
// Path: src/org/gearman/core/GearmanPacket.java
// public static enum Type{
// 	TEXT(0,1), CAN_DO(1,1), CANT_DO(2,1), RESET_ABILITIES(3,0), PRE_SLEEP(4,0), UNUSED(5,0),
// 	NOOP(6,0), SUBMIT_JOB(7,3), JOB_CREATED(8,1), GRAB_JOB(9,0), NO_JOB(10,0), JOB_ASSIGN(11,3),
// 	WORK_STATUS(12, 3), WORK_COMPLETE(13,2), WORK_FAIL(14,1), GET_STATUS(15,1), ECHO_REQ(16,1),
// 	ECHO_RES(17,1), SUBMIT_JOB_BG(18,3), ERROR(19, 2), STATUS_RES(20, 5), SUBMIT_JOB_HIGH(21,3),
// 	SET_CLIENT_ID(22,1), CAN_DO_TIMEOUT(23,2), ALL_YOURS(24,0), WORK_EXCEPTION(25,2),
// 	OPTION_REQ(26,1), OPTION_RES(27,1), WORK_DATA(28,2), WORK_WARNING(29, 2), GRAB_JOB_UNIQ(30,0),
// 	JOB_ASSIGN_UNIQ(31,4), SUBMIT_JOB_HIGH_BG(32,3), SUBMIT_JOB_LOW(33,3), SUBMIT_JOB_LOW_BG(34,3),
// 	SUBMIT_JOB_SCHED(35,8), SUBMIT_JOB_EPOCH(36,4);
//     	
// 	private final int type;
// 	private final int args;
// 	private Type(final int type, final int args) {
// 		this.type = type;
// 		this.args = args;
// 	}
//     	
// 	public final int getTypeValue() {
// 		return type;
// 	}
// 	public final int getArgumentCount() {
// 		return args;
// 	}
//     	
// 	public static final Type fromTypeValue(final int value) {
// 		switch(value) {
// 		case(0): return TEXT; 				case(1): return CAN_DO;			case(2): return CANT_DO;
// 		case(3): return RESET_ABILITIES; 	case(4): return PRE_SLEEP;			case(5): return UNUSED;
// 		case(6): return NOOP;				case(7): return SUBMIT_JOB;		case(8): return JOB_CREATED;
// 		case(9): return GRAB_JOB;			case(10): return NO_JOB; 			case(11): return JOB_ASSIGN;
// 		case(12): return WORK_STATUS;		case(13): return WORK_COMPLETE;	case(14): return WORK_FAIL;
// 		case(15): return GET_STATUS;		case(16): return ECHO_REQ;			case(17): return ECHO_RES;
// 		case(18): return SUBMIT_JOB_BG;	case(19): return ERROR;			case(20): return STATUS_RES;
// 		case(21): return SUBMIT_JOB_HIGH;	case(22): return SET_CLIENT_ID;	case(23): return CAN_DO_TIMEOUT;
// 		case(24): return ALL_YOURS;		case(25): return WORK_EXCEPTION;	case(26): return OPTION_REQ;
// 		case(27): return OPTION_RES;		case(28): return WORK_DATA;		case(29): return WORK_WARNING;
// 		case(30): return GRAB_JOB_UNIQ;	case(31): return JOB_ASSIGN_UNIQ;	case(32): return SUBMIT_JOB_HIGH_BG;
// 		case(33): return SUBMIT_JOB_LOW;	case(34): return SUBMIT_JOB_LOW_BG;case(35): return SUBMIT_JOB_SCHED; 
// 		case(36): return SUBMIT_JOB_EPOCH;
// 		default:
// 			return null;
// 		}
// 	}
// }


// Path: src/org/gearman/core/StandardCodec.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.gearman.core.GearmanPacket.Magic;
import org.gearman.core.GearmanPacket.Type;

		return packet.toBytes();
	}

	@Override
	public final void init(final GearmanCodecChannel<Integer> channel) {
		channel.setCodecAttachement(FORMAT);
	}
	
	private final void format(final GearmanCodecChannel<Integer> channel) {
		final ByteBuffer buffer = channel.getBuffer();
		if(buffer.hasRemaining()) return;
		
		if(buffer.get(0)==0) {
			buffer.limit(HEADER_SIZE);
			channel.setCodecAttachement(HEADER);
		} else {
			channel.setCodecAttachement(TEXT);
			text(channel);
		}
	}
	
	private final void header(final GearmanCodecChannel<Integer> channel) {
		ByteBuffer buffer = channel.getBuffer();
		if(buffer.hasRemaining()) return;
		
		final int size = buffer.getInt(SIZE_POS);
		
		if(size==0) {
			buffer.flip();
			
			final Magic magic = Magic.fromMagicCode(buffer.getInt());