public void Serialize(NetDataWriter writer, T[,,] value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); var i = value.GetLength(0); var j = value.GetLength(1); var k = value.GetLength(2); INetDataFormatter <T> formatter = options.Resolver.GetFormatter <T>(); writer.Write(ArrayLength); writer.Write(i); writer.Write(j); writer.Write(k); writer.Write((int)value.Length); foreach (T item in value) { formatter.Serialize(writer, item, options); } } }
public TDictionary Deserialize(NetDataReader reader, NetDataSerializerOptions options) { if (reader.ReadBoolean() == false) { return(default(TDictionary)); } else { INetDataFormatterResolver resolver = options.Resolver; INetDataFormatter <TKey> keyFormatter = resolver.GetFormatter <TKey>(); INetDataFormatter <TValue> valueFormatter = resolver.GetFormatter <TValue>(); var len = reader.ReadInt32(); TIntermediate dict = this.Create(len, options); for (int i = 0; i < len; i++) { TKey key = keyFormatter.Deserialize(reader, options); TValue value = valueFormatter.Deserialize(reader, options); this.Add(dict, i, key, value, options); } return(this.Complete(dict)); } }
public T[,,,] Deserialize(NetDataReader reader, NetDataSerializerOptions options) { if (reader.ReadBoolean() == false) { return(null); } else { INetDataFormatter <T> formatter = options.Resolver.GetFormatter <T>(); var len = reader.ReadByte(); if (len != ArrayLength) { throw new NetDataSerializationException("Invalid T[,,,] format"); } var iLength = reader.ReadInt32(); var jLength = reader.ReadInt32(); var kLength = reader.ReadInt32(); var lLength = reader.ReadInt32(); var maxLen = reader.ReadInt32(); var array = new T[iLength, jLength, kLength, lLength]; var i = 0; var j = 0; var k = 0; var l = -1; for (int loop = 0; loop < maxLen; loop++) { if (l < lLength - 1) { l++; } else if (k < kLength - 1) { l = 0; k++; } else if (j < jLength - 1) { l = 0; k = 0; j++; } else { l = 0; k = 0; j = 0; i++; } array[i, j, k, l] = formatter.Deserialize(reader, options); } return(array); } }
public void Serialize(NetDataWriter writer, ValueTuple <T1> value, NetDataSerializerOptions options) { writer.Write((byte)1); INetDataFormatterResolver resolver = options.Resolver; resolver.GetFormatter <T1>().Serialize(writer, value.Item1, options); }
public void Serialize(NetDataWriter writer, TDictionary value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); INetDataFormatterResolver resolver = options.Resolver; INetDataFormatter <TKey> keyFormatter = resolver.GetFormatter <TKey>(); INetDataFormatter <TValue> valueFormatter = resolver.GetFormatter <TValue>(); int count; { var col = value as ICollection <KeyValuePair <TKey, TValue> >; if (col != null) { count = col.Count; } else { var col2 = value as IReadOnlyCollection <KeyValuePair <TKey, TValue> >; if (col2 != null) { count = col2.Count; } else { throw new NetDataSerializationException("DictionaryFormatterBase's TDictionary supports only ICollection<KVP> or IReadOnlyCollection<KVP>"); } } } writer.Write(count); TEnumerator e = this.GetSourceEnumerator(value); try { while (e.MoveNext()) { KeyValuePair <TKey, TValue> item = e.Current; keyFormatter.Serialize(writer, item.Key, options); valueFormatter.Serialize(writer, item.Value, options); } } finally { e.Dispose(); } } }
public void Serialize(NetDataWriter writer, Int16?value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); writer.Write(value.Value); } }
public void Serialize(NetDataWriter writer, Tuple <T1> value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); writer.Write((byte)1); INetDataFormatterResolver resolver = options.Resolver; resolver.GetFormatter <T1>().Serialize(writer, value.Item1, options); } }
public ValueTuple <T1> Deserialize(NetDataReader reader, NetDataSerializerOptions options) { var count = reader.ReadByte(); if (count != 1) { throw new NetDataSerializationException("Invalid ValueTuple count"); } INetDataFormatterResolver resolver = options.Resolver; T1 item1 = resolver.GetFormatter <T1>().Deserialize(reader, options); return(new ValueTuple <T1>(item1)); }
public void Serialize(NetDataWriter writer, String[] value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); writer.Write((int)value.Length); for (int i = 0; i < value.Length; i++) { writer.Write(value[i]); } } }
public KeyValuePair <TKey, TValue> Deserialize(NetDataReader reader, NetDataSerializerOptions options) { var count = reader.ReadByte(); if (count != 2) { throw new NetDataSerializationException("Invalid KeyValuePair format."); } INetDataFormatterResolver resolver = options.Resolver; TKey key = resolver.GetFormatter <TKey>().Deserialize(reader, options); TValue value = resolver.GetFormatter <TValue>().Deserialize(reader, options); return(new KeyValuePair <TKey, TValue>(key, value)); }
public static T Deserialize <T>(NetDataReader reader, NetDataSerializerOptions options = null) { options = options ?? DefaultOptions; try { return(options.Resolver.GetFormatter <T>().Deserialize(reader, options)); } catch (TypeInitializationException ex) { var type = typeof(T); string exString = $"*** Ex) new {type.GetPureName()}Formatter{type.GetGenericParameters()}(); ***\n*** Please see https://docs.unity3d.com/kr/2020.2/Manual/ScriptingRestrictions.html ***"; throw new NetDataSerializationException($"Failed to deserialize {type.GetSymbolDisplay(true)} value.\n*** If you are using IL2PP, you need to specify the Generic Type. ***\n{exString}", ex); } catch (Exception ex) { throw new NetDataSerializationException($"Failed to deserialize {typeof(T).GetSymbolDisplay(true)} value.\n*** If you haven't generated code, please do it! ***\n*** If you have generated it, please register with the following code. CustomResolver.Register(GeneratedResolver.Instance); ***", ex); } }
public void Serialize(NetDataWriter writer, T[] value, NetDataSerializerOptions options) { if (value == null) { writer.Write(false); } else { writer.Write(true); INetDataFormatter <T> formatter = options.Resolver.GetFormatter <T>(); writer.Write(value.Length); for (int i = 0; i < value.Length; i++) { formatter.Serialize(writer, value[i], options); } } }
public String[] Deserialize(NetDataReader reader, NetDataSerializerOptions options) { if (reader.ReadBoolean() == false) { return(null); } var len = reader.ReadInt32(); if (len == 0) { return(Array.Empty <String>()); } var array = new String[len]; for (int i = 0; i < array.Length; i++) { array[i] = reader.ReadString(); } return(array); }
public void Serialize(NetDataWriter writer, T value, NetDataSerializerOptions options) { serializer(writer, ref value); }
public string Deserialize(NetDataReader reader, NetDataSerializerOptions options) { return(reader.ReadString()); }
public byte[] Deserialize(NetDataReader reader, NetDataSerializerOptions options) { return(reader.ReadByteArray()); }
protected override ConcurrentDictionary <TKey, TValue> Create(int count, NetDataSerializerOptions options) { // concurrent dictionary can't access defaultConcurrecyLevel so does not use count overload. return(new ConcurrentDictionary <TKey, TValue>()); }
protected override void Add(ConcurrentDictionary <TKey, TValue> collection, int index, TKey key, TValue value, NetDataSerializerOptions options) { collection.TryAdd(key, value); }
protected override Dictionary <TKey, TValue> Create(int count, NetDataSerializerOptions options) { return(new Dictionary <TKey, TValue>(count)); }
public void Serialize(NetDataWriter writer, Int16 value, NetDataSerializerOptions options) { writer.Write(value); }
protected override TDictionary Create(int count, NetDataSerializerOptions options) { return(new TDictionary()); }
protected override void Add(TDictionary collection, int index, TKey key, TValue value, NetDataSerializerOptions options) { collection.Add(key, value); }
protected abstract void Add(TIntermediate collection, int index, TKey key, TValue value, NetDataSerializerOptions options);
// abstraction for deserialize protected abstract TIntermediate Create(int count, NetDataSerializerOptions options);
public void Serialize(NetDataWriter writer, KeyValuePair <TKey, TValue> value, NetDataSerializerOptions options) { writer.Write((byte)2); INetDataFormatterResolver resolver = options.Resolver; resolver.GetFormatter <TKey>().Serialize(writer, value.Key, options); resolver.GetFormatter <TValue>().Serialize(writer, value.Value, options); return; }
public T Deserialize(NetDataReader reader, NetDataSerializerOptions options) { return(deserializer(reader)); }
public Int16 Deserialize(NetDataReader reader, NetDataSerializerOptions options) { return(reader.ReadInt16()); }
protected override void Add(SortedList <TKey, TValue> collection, int index, TKey key, TValue value, NetDataSerializerOptions options) { collection.Add(key, value); }
public Int16?Deserialize(NetDataReader reader, NetDataSerializerOptions options) { if (reader.ReadBoolean() == false) { return(default);
protected override SortedList <TKey, TValue> Create(int count, NetDataSerializerOptions options) { return(new SortedList <TKey, TValue>(count)); }