public LinkedBuffer packInt(final int r,
            WriteSession session, LinkedBuffer lb) throws IOException
    {
        if (r < -(1 << 5))
        {
            if (r < -(1 << 15))
            {
                return writeByteAndInt(INT32, r, session, lb);
            }
            else if (r < -(1 << 7))
            {
                return writeByteAndShort(INT16, (short) r, session, lb);
            }
            else
            {
                return writeByteAndByte(INT8, (byte) r, session, lb);
            }
        }
        else if (r < (1 << 7))
        {
            return sink.writeByte((byte) r, session, lb);
        }
        else
        {
            if (r < (1 << 8))
            {
                return writeByteAndByte(UINT8, (byte) r, session, lb);
            }
            else if (r < (1 << 16))
            {
                return writeByteAndShort(UINT16, (short) r, session, lb);
            }
            else
            {
                // unsigned 32
                return writeByteAndInt(UINT32, r, session, lb);
            }
        }
    }
Simple wrapper around WriteSink with methods specific for MessagePacker

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