public LinkedBuffer packLong(long v, WriteSession session, LinkedBuffer lb)
            throws IOException
    {
        if (v < -(1L << 5))
        {
            if (v < -(1L << 15))
            {
                if (v < -(1L << 31))
                {
                    return writeByteAndLong(INT64, v, session, lb);
                }
                else
                {
                    return writeByteAndInt(INT32, (int) v, session, lb);
                }
            }
            else
            {
                if (v < -(1 << 7))
                {
                    return writeByteAndShort(INT16, (short) v, session, lb);
                }
                else
                {
                    return writeByteAndByte(INT8, (byte) v, session, lb);
                }
            }
        }
        else if (v < (1 << 7))
        {
            // fixnum
            return sink.writeByte((byte) v, session, lb);
        }
        else
        {
            if (v < (1L << 16))
            {
                if (v < (1 << 8))
                {
                    return writeByteAndByte(UINT8, (byte) v, session, lb);
                }
                else
                {
                    return writeByteAndShort(UINT16, (short) v, session, lb);
                }
            }
            else
            {
                if (v < (1L << 32))
                {
                    return writeByteAndInt(UINT32, (int) v, session, lb);
                }
                else
                {
                    return writeByteAndLong(UINT64, v, session, lb);
                }
            }
        }
    }
Simple wrapper around WriteSink with methods specific for MessagePacker

@author Alex Shvid
protostuff-msgpack/src/main/java/io/protostuff/MsgpackWriteSink.java