Inheritance: ITypeSerializers, ITypeSerializerMappingFactory
        static void StoreObjectCore(TypeSerializers typeSerializers, AbstractBufferedWriter writer, object obj, InfoForType infoForType, ITypeSerializersLightMapping mapping)
        {
            writer.WriteVUInt32((uint)infoForType.Id);
            if (!infoForType.KnownSimpleSaver)
            {
                infoForType.SimpleSaver      = typeSerializers.GetSimpleSaver(infoForType.Descriptor);
                infoForType.KnownSimpleSaver = true;
            }
            var simpleSaver = infoForType.SimpleSaver;

            if (simpleSaver != null)
            {
                simpleSaver(writer, obj);
                return;
            }
            if (!infoForType.KnownComplexSaver)
            {
                infoForType.ComplexSaver      = typeSerializers.GetComplexSaver(infoForType.Descriptor);
                infoForType.KnownComplexSaver = true;
            }
            var complexSaver = infoForType.ComplexSaver;
            var ctx          = new TypeBinarySerializerContext(mapping, writer, obj);

            complexSaver(writer, ctx, obj);
        }
        public InfoForType GetInfoFromObject(object obj, out TypeSerializers typeSerializers)
        {
            InfoForType infoForType;
            var         iKnowDescriptor = obj as IKnowDescriptor;

            if (iKnowDescriptor != null)
            {
                var descriptor = iKnowDescriptor.GetDescriptor();
                _typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType);
            }
            else
            {
                var objType = obj.GetType();
                if (!_typeOrDescriptor2Info.TryGetValue(objType, out infoForType))
                {
                    var descriptor = _typeSerializers.DescriptorOf(objType);
                    if (_typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                    {
                        _typeOrDescriptor2Info[objType] = infoForType;
                    }
                }
            }
            typeSerializers = _typeSerializers;
            if (infoForType == null)
            {
                throw new InvalidOperationException(
                          $"Type {obj.GetType().FullName} was not registered using StoreNewDescriptors");
            }
            return(infoForType);
        }
 public DictionaryTypeDescriptor(TypeSerializers typeSerializers, Type type)
 {
     _typeSerializers = typeSerializers;
     _type = type;
     var genericArguments = type.GetGenericArguments();
     _keyType = genericArguments[0];
     _valueType = genericArguments[1];
 }
Exemple #4
0
 public EnumTypeDescriptor(TypeSerializers typeSerializers, AbstractBufferedReader reader)
 {
     _typeSerializers = typeSerializers;
     _name = reader.ReadString();
     var header = reader.ReadVUInt32();
     _signed = (header & 1) != 0;
     _flags = (header & 2) != 0;
     var count = header >> 2;
     _pairs = new List<KeyValuePair<string, ulong>>((int)count);
     for (int i = 0; i < count; i++)
     {
         _pairs.Add(_signed
                        ? new KeyValuePair<string, ulong>(reader.ReadString(), (ulong)reader.ReadVInt64())
                        : new KeyValuePair<string, ulong>(reader.ReadString(), reader.ReadVUInt64()));
     }
 }
Exemple #5
0
 public EnumTypeDescriptor(TypeSerializers typeSerializers, Type type)
 {
     _typeSerializers = typeSerializers;
     _type = type;
     _name = typeSerializers.TypeToName(type);
     _signed = IsSignedEnum(type);
     _flags = IsFlagsEnum(type);
     var undertype = type.GetEnumUnderlyingType();
     var enumValues = type.GetEnumValues();
     IEnumerable<ulong> enumValuesUlongs;
     if (undertype == typeof(int)) enumValuesUlongs = enumValues.Cast<int>().Select(i => (ulong)i);
     else if (undertype == typeof(uint)) enumValuesUlongs = enumValues.Cast<uint>().Select(i => (ulong)i);
     else if (undertype == typeof(sbyte)) enumValuesUlongs = enumValues.Cast<sbyte>().Select(i => (ulong)i);
     else if (undertype == typeof(byte)) enumValuesUlongs = enumValues.Cast<byte>().Select(i => (ulong)i);
     else if (undertype == typeof(short)) enumValuesUlongs = enumValues.Cast<short>().Select(i => (ulong)i);
     else if (undertype == typeof(ushort)) enumValuesUlongs = enumValues.Cast<ushort>().Select(i => (ulong)i);
     else if (undertype == typeof(long)) enumValuesUlongs = enumValues.Cast<long>().Select(i => (ulong)i);
     else enumValuesUlongs = enumValues.Cast<ulong>();
     _pairs = type.GetEnumNames().Zip(enumValuesUlongs.ToArray(), (s, v) => new KeyValuePair<string, ulong>(s, v)).ToList();
 }
Exemple #6
0
 public ListTypeDescriptor(TypeSerializers typeSerializers, AbstractBufferedReader reader, Func<AbstractBufferedReader, ITypeDescriptor> nestedDescriptorReader)
 {
     _typeSerializers = typeSerializers;
     InitFromItemDescriptor(nestedDescriptorReader(reader));
 }
Exemple #7
0
 public ListTypeDescriptor(TypeSerializers typeSerializers, Type type)
 {
     _typeSerializers = typeSerializers;
     _type = type;
     _itemType = GetItemType(type);
 }
Exemple #8
0
 public BuildFromTypeCtx(TypeSerializers typeSerializers, ConcurrentDictionary <Type, ITypeDescriptor> type2DescriptorMap)
 {
     _typeSerializers    = typeSerializers;
     _type2DescriptorMap = type2DescriptorMap;
 }
 public DescriptorSerializerContext(TypeSerializersMapping typeSerializersMapping, AbstractBufferedWriter writer)
 {
     _typeSerializersMapping = typeSerializersMapping;
     _writer          = writer;
     _typeSerializers = _typeSerializersMapping._typeSerializers;
 }
 public TypeSerializersMapping(TypeSerializers typeSerializers)
 {
     _typeSerializers = typeSerializers;
     AddBuildInTypes();
 }
 public DictionaryTypeDescriptor(TypeSerializers typeSerializers, AbstractBufferedReader reader, Func<AbstractBufferedReader, ITypeDescriptor> nestedDescriptorReader)
 {
     _typeSerializers = typeSerializers;
     InitFromKeyValueDescriptors(nestedDescriptorReader(reader), nestedDescriptorReader(reader));
 }
Exemple #12
0
 public BuildFromTypeCtx(TypeSerializers typeSerializers, ConcurrentDictionary<Type, ITypeDescriptor> type2DescriptorMap)
 {
     _typeSerializers = typeSerializers;
     _type2DescriptorMap = type2DescriptorMap;
 }
 public TypeSerializersMapping(TypeSerializers typeSerializers)
 {
     _typeSerializers = typeSerializers;
     _symmetricCipher = _typeSerializers.GetSymmetricCipher();
     AddBuildInTypes();
 }
Exemple #14
0
 public ObjectTypeDescriptor(TypeSerializers typeSerializers, Type type)
 {
     _type = type;
     Sealed = _type.IsSealed;
     _name = typeSerializers.TypeToName(type);
 }