Exemplo n.º 1
0
        /**
         * 放入一个元素
         * @param <T>
         * @param name
         * @param t
         */
        public void Put <T>(string name, T t)
        {
            if (name == null)
            {
                throw new ArgumentException("put key can not is null");
            }
            if (t == null)
            {
                throw new ArgumentException("put value can not is null");
            }

            TarsOutputStream _out = new TarsOutputStream();

            _out.setServerEncoding(_encodeName);
            _out.Write(t, 0);
            byte[] sBuffer = TarsUtil.getTarsBufArray(_out.getMemoryStream());

            if (_iVer == Const.PACKET_TYPE_TUP3)
            {
                cachedData.Remove(name);

                if (_new_data.ContainsKey(name))
                {
                    _new_data[name] = sBuffer;
                }
                else
                {
                    _new_data.Add(name, sBuffer);
                }
            }
            else
            {
                List <string> listType = new List <string>();
                CheckObjectType(listType, t);
                string className = BasicClassTypeUtil.TransTypeList(listType);

                Dictionary <string, byte[]> pair = new Dictionary <string, byte[]>(1);
                pair.Add(className, sBuffer);
                cachedData.Remove(name);

                if (_data.ContainsKey(name))
                {
                    _data[name] = pair;
                }
                else
                {
                    _data.Add(name, pair);
                }
            }
        }
Exemplo n.º 2
0
        public byte[] Encode()
        {
            TarsOutputStream _os = new TarsOutputStream(0);

            _os.setServerEncoding(_encodeName);
            if (_iVer == Const.PACKET_TYPE_TUP3)
            {
                _os.Write(_new_data, 0);
            }
            else
            {
                _os.Write(_data, 0);
            }
            return(TarsUtil.getTarsBufArray(_os.getMemoryStream()));
        }
Exemplo n.º 3
0
        /**
         * 为兼容最早发布的客户端版本解码使用 iret字段始终为0
         *
         * @return
         */
        public byte[] CreateOldRespEncode()
        {
            TarsOutputStream _os = new TarsOutputStream(0);

            _os.setServerEncoding(EncodeName);
            _os.Write(_data, 0);
            byte[] oldSBuffer = TarsUtil.getTarsBufArray(_os.getMemoryStream());
            _os = new TarsOutputStream(0);
            _os.setServerEncoding(EncodeName);
            _os.Write(_package.iVersion, 1);
            _os.Write(_package.cPacketType, 2);
            _os.Write(_package.iRequestId, 3);
            _os.Write(_package.iMessageType, 4);
            _os.Write(OldRespIRet, 5);
            _os.Write(oldSBuffer, 6);
            _os.Write(_package.status, 7);
            return(TarsUtil.getTarsBufArray(_os.getMemoryStream()));
        }
Exemplo n.º 4
0
        /**
         * 将put的对象进行编码
         */
        public new byte[] Encode()
        {
            if (_package.sServantName.Equals(""))
            {
                throw new ArgumentException("servantName can not is null");
            }
            if (_package.sFuncName.Equals(""))
            {
                throw new ArgumentException("funcName can not is null");
            }

            TarsOutputStream _os = new TarsOutputStream(0);

            _os.setServerEncoding(EncodeName);
            if (_package.iVersion == Const.PACKET_TYPE_TUP)
            {
                _os.Write(_data, 0);
            }
            else
            {
                _os.write(_new_data, 0);
            }

            _package.sBuffer = TarsUtil.getTarsBufArray(_os.getMemoryStream());

            _os = new TarsOutputStream(0);
            _os.setServerEncoding(EncodeName);
            this.WriteTo(_os);
            byte[] bodys = TarsUtil.getTarsBufArray(_os.getMemoryStream());
            int    size  = bodys.Length;

            MemoryStream ms = new MemoryStream(size + UniPacketHeadSize);

            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                // 整个数据包长度
                bw.Write(ByteConverter.ReverseEndian(size + UniPacketHeadSize));
                bw.Write(bodys);
            }

            return(ms.ToArray());
        }