Exemplo n.º 1
0
        /**
         * Put in an element.
         * @param <T>
         * @param name
         * @param value
         */
        public void Put <T>(string name, T value)
        {
            if (name == null)
            {
                throw new ArgumentException("put key can not is null");
            }
            if (value == null)
            {
                throw new ArgumentException("put value can not is null");
            }

            TarsOutputStream _out = new TarsOutputStream();

            _out.SetServerEncoding(_encodeName);
            _out.Write(value, 0);
            byte[] sBuffer = TarsUtil.GetTarsBufferArray(_out.GetMemoryStream());

            if (_iVer == Const.TUP_VERSION_3)
            {
                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, value);
                string className = BasicClassTypeUtil.TransTypeList(listType);

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

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

            _os.SetServerEncoding(_encodeName);
            if (_iVer == Const.TUP_VERSION_3)
            {
                _os.Write(_new_data, 0);
            }
            else
            {
                _os.Write(_data, 0);
            }
            return(TarsUtil.GetTarsBufferArray(_os.GetMemoryStream()));
        }
Exemplo n.º 3
0
        public byte[] Encode()
        {
            TarsOutputStream os = new TarsOutputStream();

            os.SetServerEncoding(EncodeName);
            if (IsVersionTup3)
            {
                os.Write((IDictionary)newData, 0);
                return(os.ToByteArray());
            }
            else
            {
                os.Write((IDictionary)data, 0);
                return(os.ToByteArray());
            }
        }
Exemplo n.º 4
0
        public void Put <T>(string name, T t)
        {
            if (name == null)
            {
                throw new ArgumentException("put key can not be null");
            }
            if (t == null)
            {
                throw new ArgumentException("put value can not be null");
            }
            TarsOutputStream _out = new TarsOutputStream();

            _out.SetServerEncoding(EncodeName);
            _out.Write(t, 0);
            byte[] sBuffer = _out.ToByteArray();
            if (IsVersionTup3)
            {
                if (newData.ContainsKey(name))
                {
                    newData[name] = sBuffer;
                }
                else
                {
                    newData.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)
                {
                    { className, sBuffer }
                };
                cachedData.Remove(name);
                if (data.ContainsKey(name))
                {
                    data[name] = pair;
                }
                else
                {
                    data.Add(name, pair);
                }
            }
        }
Exemplo n.º 5
0
        /**
         * Encode the put object.
         */
        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.TUP_VERSION_2)
            {
                _os.Write(_data, 0);
            }
            else
            {
                _os.Write(_new_data, 0);
            }

            _package.sBuffer = TarsUtil.GetTarsBufferArray(_os.GetMemoryStream());

            _os = new TarsOutputStream(0);
            _os.SetServerEncoding(EncodeName);
            this.WriteTo(_os);

            byte[] bodys = TarsUtil.GetTarsBufferArray(_os.GetMemoryStream());
            int    size  = bodys.Length;

            MemoryStream stream = new MemoryStream(size + UniPacketHeadSize);

            using (BinaryWriter writer = new BinaryWriter(stream))
            {
                // Entire packet length.
                writer.Write(ByteConverter.ReverseEndian(size + UniPacketHeadSize));
                writer.Write(bodys);
            }

            return(stream.ToArray());
        }
Exemplo n.º 6
0
        /**
         * The 'iret' field is always 0, for compatibility with the earliest published client version.
         *
         * @return
         */
        public byte[] CreateOldResponseEncode()
        {
            TarsOutputStream _os = new TarsOutputStream(0);

            _os.SetServerEncoding(EncodeName);
            _os.Write(_data, 0);

            byte[] oldSBuffer = TarsUtil.GetTarsBufferArray(_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(OldResponseIRet, 5);
            _os.Write(oldSBuffer, 6);
            _os.Write(_package.status, 7);

            return(TarsUtil.GetTarsBufferArray(_os.GetMemoryStream()));
        }