public Frame(int channelPtr,
                 int ctype,
                 int op,
                 int flag,
                 ByteBuffer data) {
        super();
		
        short length = HEADER_SIZE;
		
        if (data != null) {
            if (data.capacity() > PAYLOAD_MAX_LIMIT) {
                throw new IllegalArgumentException("Payload max limit reached");
            } else {
                length += (short)(data.capacity());
            }
        }
		
        m_bytes = ByteBuffer.allocate(length + 2);
        m_bytes.order(ByteOrder.BIG_ENDIAN);
		
        m_bytes.putShort(length);
        m_bytes.putInt(channelPtr);
        m_bytes.put((byte)((ctype << CTYPE_BITPOS) | (op << OP_BITPOS) | flag));
		
        if (data != null) {
            m_bytes.put(data);
        }

        m_bytes.flip();
    }