public int encode() {
		byte[] keyByte = transcoder.encode(key);
		byte[] dataByte = Json.serialize(data);

		if (dataByte == null)
			return 3; // serialize failed
		
		if (keyByte.length >= TairConstant.TAIR_KEY_MAX_LENTH) {
			return 1;
		}

		if (dataByte.length >= TairConstant.TAIR_VALUE_MAX_LENGTH) {
			return 2;
		}

		writePacketBegin(keyByte.length + dataByte.length);

		// body
		byteBuffer.put((byte) 0);
		byteBuffer.putShort(namespace);
		byteBuffer.putShort(version);
		byteBuffer.putInt(expired);
		
		fillMetas();
		DataEntry.encodeMeta(byteBuffer);
		byteBuffer.putInt(keyByte.length);
		byteBuffer.put(keyByte);

		fillMetas();
		DataEntry.encodeMeta(byteBuffer);
		byteBuffer.putInt(dataByte.length);
		byteBuffer.put(dataByte);
		
		byteBuffer.putInt(maxCount);

		writePacketEnd();

		return 0;
	}