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(); } } } }
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(); } } } }
public override object Decode(ProtocolBuffer protocolBuffer) { int count = LengthCodecHelper.DecodeLength(protocolBuffer.Reader); byte[] bytes = protocolBuffer.Reader.ReadBytes(count); return(Encoding.GetString(bytes)); }
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(); } } } }
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); }
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)); } }
public object Decode(ProtocolBuffer protocolBuffer) { IList list = (IList)Activator.CreateInstance(this.type); int num = LengthCodecHelper.DecodeLength(protocolBuffer.Reader); if (num > 0) { for (int i = 0; i < num; i++) { object obj2 = this.elementCodec.Decode(protocolBuffer); list.Add(obj2); } } return(list); }
public object Decode(ProtocolBuffer protocolBuffer) { object obj2 = Activator.CreateInstance(this.type); int num = LengthCodecHelper.DecodeLength(protocolBuffer.Reader); if (num > 0) { for (int i = 0; i < num; i++) { object obj3 = this.elementCodec.Decode(protocolBuffer); object[] parameters = new object[] { obj3 }; this.addMethod.Invoke(obj2, parameters); } } return(obj2); }
public object Decode(ProtocolBuffer protocolBuffer) { int num = LengthCodecHelper.DecodeLength(protocolBuffer.Reader); IDictionary dictionary = (IDictionary)Activator.CreateInstance(this.type, (object[])null); if (num > 0) { for (int i = 0; i < num; i++) { object key = this.keyCodec.Decode(protocolBuffer); object obj3 = this.valueCodec.Decode(protocolBuffer); dictionary.Add(key, obj3); } } return(dictionary); }
public object Decode(ProtocolBuffer protocolBuffer) { object obj3; int index = 0; Array array = null; int length = 0; try { length = LengthCodecHelper.DecodeLength(protocolBuffer.Reader); array = Array.CreateInstance(this.elementType, length); while (true) { if (index >= length) { obj3 = array; break; } object obj2 = this.elementCodec.Decode(protocolBuffer); array.SetValue(obj2, index); index++; } } catch (Exception exception) { StringBuilder builder = new StringBuilder(); for (int i = 0; i <= index; i++) { object obj4 = array.GetValue(i); builder.Append(i); builder.Append(") "); builder.Append(obj4); builder.Append("\n"); } object[] objArray1 = new object[] { "Array decode failed; ElementType: ", this.elementType.Name, " length: ", length, " decodedElements: ", builder }; throw new Exception(string.Concat(objArray1), exception); } return(obj3); }