public static LinkedBuffer writeTagAndByteArray(int tag, final byte[] value,
            int offset, int valueLen,
            final WriteSession session, LinkedBuffer lb)
    {
        if (valueLen == 0)
        {
            // write only the tag and delimiter
            return writeTagAndRawVarInt32(tag, valueLen, session, lb);
        }

        lb = writeTagAndRawVarInt32(tag, valueLen, session, lb);

        session.size += valueLen;

        final int available = lb.buffer.length - lb.offset;
        if (valueLen > available)
        {
            if (available + session.nextBufferSize < valueLen)
            {
                // too large ... so we wrap and insert (zero-copy)
                if (available == 0)
                {
                    // buffer was actually full ... return a fresh buffer
                    return new LinkedBuffer(session.nextBufferSize,
                            new LinkedBuffer(value, offset, offset + valueLen, lb));
                }

                // continue with the existing byte array of the previous buffer
                return new LinkedBuffer(lb,
                        new LinkedBuffer(value, offset, offset + valueLen, lb));
            }

            // copy what can fit
            System.arraycopy(value, offset, lb.buffer, lb.offset, available);

            lb.offset += available;

            // grow
            lb = new LinkedBuffer(session.nextBufferSize, lb);

            final int leftover = valueLen - available;

            // copy what's left
            System.arraycopy(value, offset + available, lb.buffer, 0, leftover);

            lb.offset += leftover;

            return lb;
        }

        // it fits
        System.arraycopy(value, offset, lb.buffer, lb.offset, valueLen);

        lb.offset += valueLen;

        return lb;
    }
Returns the buffer encoded with the tag and byte array
protostuff-core/src/main/java/io/protostuff/ProtobufOutput.java