Esempio n. 1
0
        /** 实际执行写request到stream */
        private void toWriteRequestToStream(BytesWriteStream stream, BaseRequest request, int index)
        {
            stream.clearBooleanPos();

            int limit = request.getMessageLimit();

            stream.setWriteLenLimit(limit);
            int mid = request.getDataID();

            int startPos = stream.getPosition();

            //写协议ID(原生写)
            stream.natureWriteUnsignedShort(mid);

            if (!BytesControl.isIgnoreMessage(mid))
            {
                stream.natureWriteShort(index);
            }

            request.writeToStream(stream);

            int endPos = stream.getPosition();
            int len    = endPos - startPos;

            if (limit > 0 && len >= limit)
            {
                Ctrl.errorLog("request长度超出上限", len);
            }

            if (ShineSetting.needCustomLengthBasedFrameDecoder)
            {
                stream.insertLenToPos(startPos, len);
            }
            else
            {
                stream.setPosition(startPos);

                stream.insertVoidBytes(4, len);

                stream.natureWriteInt(len);

                stream.setPosition(endPos);
            }

            //写完的标记
            request.sended = true;
        }