Пример #1
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            IList list = (IList)data;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, list.Count);
            if (list.Count > 0)
            {
                IEnumerator enumerator = list.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.elementCodec.Encode(protocolBuffer, current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Пример #2
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            IDictionary dictionary = (IDictionary)data;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, dictionary.Count);
            if (dictionary.Count > 0)
            {
                IEnumerator enumerator = dictionary.Keys.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.keyCodec.Encode(protocolBuffer, current);
                        this.valueCodec.Encode(protocolBuffer, dictionary[current]);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Пример #3
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            int length = (int)this.countProperty.GetValue(data, BindingFlags.Default, null, null, null);

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, length);
            if (length > 0)
            {
                IEnumerator enumerator = ((IEnumerable)data).GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        this.elementCodec.Encode(protocolBuffer, current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
Пример #4
0
        public override void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            base.Encode(protocolBuffer, data);
            string s         = (string)data;
            int    byteCount = Encoding.GetByteCount(s);

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, byteCount);
            protocolBuffer.Writer.Write(Encoding.GetBytes(s), 0, byteCount);
        }
Пример #5
0
        public void Encode(ProtocolBuffer protocolBuffer, object data)
        {
            Array array  = (Array)data;
            int   length = array.Length;

            LengthCodecHelper.EncodeLength(protocolBuffer.Data.Stream, length);
            for (int i = 0; i < length; i++)
            {
                this.elementCodec.Encode(protocolBuffer, array.GetValue(i));
            }
        }