private Type DeserializeDictionaryType(StreamBuffer reader, out byte keyTypeCode, out byte valTypeCode) { keyTypeCode = (byte)reader.ReadByte(); valTypeCode = (byte)reader.ReadByte(); Protocol16.GpType gpType = (Protocol16.GpType)keyTypeCode; Protocol16.GpType gpType2 = (Protocol16.GpType)valTypeCode; bool flag = gpType == Protocol16.GpType.Unknown; Type type; if (flag) { type = typeof(object); } else { type = this.GetTypeOfCode(keyTypeCode); } bool flag2 = gpType2 == Protocol16.GpType.Unknown; Type type2; if (flag2) { type2 = typeof(object); } else { type2 = this.GetTypeOfCode(valTypeCode); } return(typeof(Dictionary <,>).MakeGenericType(new Type[] { type, type2 })); }
private void SerializeDictionaryHeader(StreamBuffer writer, object dict, out bool setKeyType, out bool setValueType) { Type[] genericArguments = dict.GetType().GetGenericArguments(); setKeyType = (genericArguments[0] == typeof(object)); setValueType = (genericArguments[1] == typeof(object)); bool flag = setKeyType; if (flag) { writer.WriteByte(0); } else { Protocol16.GpType codeOfType = this.GetCodeOfType(genericArguments[0]); bool flag2 = codeOfType == Protocol16.GpType.Unknown || codeOfType == Protocol16.GpType.Dictionary; if (flag2) { throw new Exception("Unexpected - cannot serialize Dictionary with key type: " + genericArguments[0]); } writer.WriteByte((byte)codeOfType); } bool flag3 = setValueType; if (flag3) { writer.WriteByte(0); } else { Protocol16.GpType codeOfType2 = this.GetCodeOfType(genericArguments[1]); bool flag4 = codeOfType2 == Protocol16.GpType.Unknown; if (flag4) { throw new Exception("Unexpected - cannot serialize Dictionary with value type: " + genericArguments[0]); } writer.WriteByte((byte)codeOfType2); bool flag5 = codeOfType2 == Protocol16.GpType.Dictionary; if (flag5) { this.SerializeDictionaryHeader(writer, genericArguments[1]); } } }
private void SerializeArray(StreamBuffer dout, Array serObject, bool setType) { if (setType) { dout.WriteByte(121); } bool flag = serObject.Length > 32767; if (flag) { throw new NotSupportedException("String[] that exceed 32767 (short.MaxValue) entries are not supported. Yours is: " + serObject.Length); } this.SerializeShort(dout, (short)serObject.Length, false); Type elementType = serObject.GetType().GetElementType(); Protocol16.GpType codeOfType = this.GetCodeOfType(elementType); bool flag2 = codeOfType > Protocol16.GpType.Unknown; if (flag2) { dout.WriteByte((byte)codeOfType); bool flag3 = codeOfType == Protocol16.GpType.Dictionary; if (flag3) { bool setKeyType; bool setValueType; this.SerializeDictionaryHeader(dout, serObject, out setKeyType, out setValueType); for (int i = 0; i < serObject.Length; i++) { object value = serObject.GetValue(i); this.SerializeDictionaryElements(dout, value, setKeyType, setValueType); } } else { for (int j = 0; j < serObject.Length; j++) { object value2 = serObject.GetValue(j); this.Serialize(dout, value2, false); } } } else { CustomType customType; bool flag4 = Protocol.TypeDict.TryGetValue(elementType, out customType); if (!flag4) { throw new NotSupportedException("cannot serialize array of type " + elementType); } dout.WriteByte(99); dout.WriteByte(customType.Code); for (int k = 0; k < serObject.Length; k++) { object value3 = serObject.GetValue(k); bool flag5 = customType.SerializeStreamFunction == null; if (flag5) { byte[] array = customType.SerializeFunction(value3); this.SerializeShort(dout, (short)array.Length, false); dout.Write(array, 0, array.Length); } else { long position = dout.Position; dout.Position += 2L; short num = customType.SerializeStreamFunction(dout, value3); long position2 = dout.Position; dout.Position = position; this.SerializeShort(dout, num, false); dout.Position += (long)num; bool flag6 = dout.Position != position2; if (flag6) { throw new Exception(string.Concat(new object[] { "Serialization failed. Stream position corrupted. Should be ", position2, " is now: ", dout.Position, " serializedLength: ", num })); } } } } }
public override void Serialize(StreamBuffer dout, object serObject, bool setType) { bool flag = serObject == null; if (flag) { if (setType) { dout.WriteByte(42); } } else { Protocol16.GpType codeOfType = this.GetCodeOfType(serObject.GetType()); Protocol16.GpType gpType = codeOfType; if (gpType != Protocol16.GpType.Dictionary) { switch (gpType) { case Protocol16.GpType.Byte: this.SerializeByte(dout, (byte)serObject, setType); return; case Protocol16.GpType.Double: this.SerializeDouble(dout, (double)serObject, setType); return; case Protocol16.GpType.EventData: this.SerializeEventData(dout, (EventData)serObject, setType); return; case Protocol16.GpType.Float: this.SerializeFloat(dout, (float)serObject, setType); return; case Protocol16.GpType.Hashtable: this.SerializeHashTable(dout, (Hashtable)serObject, setType); return; case Protocol16.GpType.Integer: this.SerializeInteger(dout, (int)serObject, setType); return; case Protocol16.GpType.Short: this.SerializeShort(dout, (short)serObject, setType); return; case Protocol16.GpType.Long: this.SerializeLong(dout, (long)serObject, setType); return; case Protocol16.GpType.Boolean: this.SerializeBoolean(dout, (bool)serObject, setType); return; case Protocol16.GpType.OperationResponse: this.SerializeOperationResponse(dout, (OperationResponse)serObject, setType); return; case Protocol16.GpType.OperationRequest: this.SerializeOperationRequest(dout, (OperationRequest)serObject, setType); return; case Protocol16.GpType.String: this.SerializeString(dout, (string)serObject, setType); return; case Protocol16.GpType.ByteArray: this.SerializeByteArray(dout, (byte[])serObject, setType); return; case Protocol16.GpType.Array: { bool flag2 = serObject is int[]; if (flag2) { this.SerializeIntArrayOptimized(dout, (int[])serObject, setType); } else { bool flag3 = serObject.GetType().GetElementType() == typeof(object); if (flag3) { this.SerializeObjectArray(dout, serObject as object[], setType); } else { this.SerializeArray(dout, (Array)serObject, setType); } } return; } } bool flag4 = serObject is ArraySegment <byte>; if (flag4) { ArraySegment <byte> arraySegment = (ArraySegment <byte>)serObject; this.SerializeByteArraySegment(dout, arraySegment.Array, arraySegment.Offset, arraySegment.Count, setType); } else { bool flag5 = !this.SerializeCustom(dout, serObject); if (flag5) { throw new Exception("cannot serialize(): " + serObject.GetType()); } } } else { this.SerializeDictionary(dout, (IDictionary)serObject, setType); } } }