Ejemplo n.º 1
0
        private static unsafe void WrongSerialize(SpacingValuesClass value)
        {
            BssomSerializeContext context = new BssomSerializeContext(BssomSerializerOptions.IntKeyCompositedResolverOption, default);

            using (ExpandableBufferWriter buffer = ExpandableBufferWriter.CreateGlobar())
            {
                BssomWriter writer = new BssomWriter(buffer);
                if (value == null)
                {
                    writer.WriteNull();
                    return;
                }
                long num = writer.WriteArray3Header(6);
                uint num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0, num7 = 0;

                num2 = (uint)(writer.Position - num);
                writer.Write(value.A);
                num3 = (uint)(writer.Position - num);
                writer.WriteNull();
                num4 = (uint)(writer.Position - num);
                writer.WriteNull();
                num5 = (uint)(writer.Position - num);
                writer.Write(value.B);
                num6 = (uint)(writer.Position - num);
                writer.WriteNull();
                num7 = (uint)(writer.Position - num);
                writer.Write(value.C);

                //writer.WriteBackArray3Header(num, ref num2, 6);
            }
        }
Ejemplo n.º 2
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, BssomDateTime value)
 {
     if (value == null)
     {
         writer.WriteNull();
         return;
     }
     writer.Write(value.GetDateTime(), context.Option.IsUseStandardDateTime);
 }
Ejemplo n.º 3
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, BssomBoolean value)
 {
     if (value == null)
     {
         writer.WriteNull();
         return;
     }
     writer.Write(value.GetBoolean());
 }
Ejemplo n.º 4
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, Version value)
 {
     if (value == null)
     {
         writer.WriteNull();
         return;
     }
     writer.Write(value.ToString());
 }
Ejemplo n.º 5
0
        static Array3Cache()
        {
            ExpandableBufferWriter bw = ExpandableBufferWriter.CreateTemporary();
            BssomWriter            cw = new BssomWriter(bw);

            cw.WriteBuildInType(BssomType.Array3);
            cw.WriteVariableNumber(BssomBinaryPrimitives.FixUInt32NumberSize); //len
            cw.WriteUInt32FixNumber(0);                                        //count
            Empty = bw.GetBufferedArray();
        }
Ejemplo n.º 6
0
        static BssMapObjMarshal()
        {
            ExpandableBufferWriter bw = ExpandableBufferWriter.CreateTemporary();
            BssomWriter            cw = new BssomWriter(bw);

            cw.WriteUInt32FixNumber(7);//reference DefaultMapLengthFieldSize
            cw.WriteVariableNumber(0);
            cw.WriteVariableNumber(0);
            cw.WriteUInt32FixNumber(0);//reference DefaultRouteLengthFieldSize
            Empty = bw.GetBufferedArray();
        }
Ejemplo n.º 7
0
 public void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, Int32 value)
 {
     if (offsetInfo.Array1ElementTypeIsNativeType == false && offsetInfo.Array1ElementType == BssomType.Int32Code)
     {
         writer.WriteWithOutTypeHead(value);
     }
     else
     {
         BssomSerializationArgumentException.InvalidOffsetInfoFormat <Int32>();
     }
 }
Ejemplo n.º 8
0
 public void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, Decimal value)
 {
     if (offsetInfo.Array1ElementTypeIsNativeType == true && offsetInfo.Array1ElementType == NativeBssomType.DecimalCode)
     {
         writer.WriteWithOutTypeHead(value);
     }
     else
     {
         BssomSerializationArgumentException.InvalidOffsetInfoFormat <Decimal>();
     }
 }
Ejemplo n.º 9
0
        public void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, Object value)
        {
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            IArray1ElementWriter array1ElementWriter = Array1ElementWriterContainers.GetArray1ElementWriter(offsetInfo.Array1ElementTypeIsNativeType, offsetInfo.Array1ElementType);

            array1ElementWriter.WriteObjectElement(ref writer, option, offsetInfo, value);
        }
Ejemplo n.º 10
0
        public static long WriteMapHead(ref BssomWriter writer, int valueCount, int maxDepth)
        {
            DEBUG.Assert(valueCount != 0 && maxDepth != 0);
            writer.FillUInt32FixNumber();           //len
            writer.WriteVariableNumber(valueCount); //count
            writer.WriteVariableNumber(maxDepth);   //depth
            long routeLenPos = writer.Position;

            writer.FillUInt32FixNumber();//routelen
            return(routeLenPos);
        }
Ejemplo n.º 11
0
 public void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, DateTime value)
 {
     if (offsetInfo.Array1ElementTypeIsNativeType == false && offsetInfo.Array1ElementType == BssomType.TimestampCode)
     {
         writer.Write(value, true, false);
     }
     else if (offsetInfo.Array1ElementTypeIsNativeType == true && offsetInfo.Array1ElementType == NativeBssomType.DateTimeCode)
     {
         writer.Write(value, false, false);
     }
     else
     {
         BssomSerializationArgumentException.InvalidOffsetInfoFormat <DateTime>();
     }
 }
Ejemplo n.º 12
0
        public static void Serialize <TKey, TValue>(ref BssomWriter writer, ref BssomSerializeContext context, IEnumerable <KeyValuePair <TKey, TValue> > value, int count)
        {
            if (typeof(TKey) == typeof(DateTime))
            {
                context.Option = context.Option.WithIsUseStandardDateTime(false);
            }

            if (context.Option.IDictionaryIsSerializeMap1Type)
            {
                MapFormatterHelper_Map1.Serialize(ref writer, value, ref context, count);
            }
            else
            {
                MapFormatterHelper_Map2.Serialize(ref writer, value, ref context, count);
            }
        }
Ejemplo n.º 13
0
        public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, BssomValue value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            switch (value.ValueType)
            {
            case BssomValueType.Array:
                BssomArrayFormatter.Instance.Serialize(ref writer, ref context, (BssomArray)value);
                break;

            case BssomValueType.Map:
                BssomMapFormatter.Instance.Serialize(ref writer, ref context, (BssomMap)value);
                break;

            case BssomValueType.Null:
                BssomNullFormatter.Instance.Serialize(ref writer, ref context, (BssomNull)(value));
                break;

            case BssomValueType.Number:
                BssomNumberFormatter.Instance.Serialize(ref writer, ref context, (BssomNumber)value);
                break;

            case BssomValueType.Float:
                BssomFloatFormatter.Instance.Serialize(ref writer, ref context, (BssomFloat)(value));
                break;

            case BssomValueType.String:
                BssomStringFormatter.Instance.Serialize(ref writer, ref context, (BssomString)(value));
                break;

            case BssomValueType.DateTime:
                BssomDateTimeFormatter.Instance.Serialize(ref writer, ref context, (BssomDateTime)(value));
                break;

            case BssomValueType.Char:
                BssomCharFormatter.Instance.Serialize(ref writer, ref context, (BssomChar)value);
                break;

            default:    //case BssomValueType.Boolean:
                BssomBooleanFormatter.Instance.Serialize(ref writer, ref context, (BssomBoolean)(value));
                break;
            }
        }
Ejemplo n.º 14
0
        public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, BssomFloat value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            switch (value.FloatType)
            {
            case BssomFloat.BssomFloatType.Single:
                writer.Write(value.GetFloat32());
                break;

            default:    //case BssomFloatType.Double:
                writer.Write(value.GetFloat64());
                break;
            }
        }
Ejemplo n.º 15
0
        public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, object value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Type realType = value.GetType();

            if (realType == typeof(object))
            {
                writer.WriteArray1BuildInType(BssomType.Map2);
                BssMapObjMarshal.WriteEmptyMapObject(ref writer);
                return;
            }

            object formatter = context.Option.FormatterResolver.GetFormatterWithVerify(realType);

            if (!SerializerDelegates.TryGetValue(realType, out SerializeMethod serializerDelegate))
            {
                Type formatterType         = typeof(IBssomFormatter <>).MakeGenericType(realType);
                ParameterExpression param0 = Expression.Parameter(typeof(object), "formatter");
                ParameterExpression param1 = Expression.Parameter(typeof(BssomWriter).MakeByRefType(), "writer");
                ParameterExpression param2 = Expression.Parameter(typeof(BssomSerializeContext).MakeByRefType(), "context");
                ParameterExpression param3 = Expression.Parameter(typeof(object), "value");

                MethodInfo serializeMethod = formatterType.GetRuntimeMethod(nameof(Serialize), new[] { typeof(BssomWriter).MakeByRefType(), typeof(BssomSerializeContext).MakeByRefType(), realType });

                MethodCallExpression body = Expression.Call(
                    Expression.Convert(param0, formatterType),
                    serializeMethod,
                    param1, param2,
                    realType.IsValueType ? Expression.Unbox(param3, realType) : Expression.Convert(param3, realType)
                    );

                serializerDelegate = Expression.Lambda <SerializeMethod>(body, param0, param1, param2, param3).Compile();
                SerializerDelegates.TryAdd(realType, serializerDelegate);
            }

            serializerDelegate(formatter, ref writer, ref context, value);
        }
Ejemplo n.º 16
0
        public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, BssomNumber value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            switch (value.NumberType)
            {
            case BssomNumber.BssomNumberType.SByte:
                writer.Write(value.GetSByte());
                break;

            case BssomNumber.BssomNumberType.Byte:
                writer.Write(value.GetByte());
                break;

            case BssomNumber.BssomNumberType.Short:
                writer.Write(value.GetShort());
                break;

            case BssomNumber.BssomNumberType.Int:
                writer.Write(value.GetInt());
                break;

            case BssomNumber.BssomNumberType.Long:
                writer.Write(value.GetLong());
                break;

            case BssomNumber.BssomNumberType.UShort:
                writer.Write(value.GetUShort());
                break;

            case BssomNumber.BssomNumberType.UInt:
                writer.Write(value.GetUInt());
                break;

            default:    //case BssomNumberType.ULong:
                writer.Write(value.GetULong());
                break;
            }
        }
Ejemplo n.º 17
0
        //Serialize IEnumerable<>
        public static void SerializeGenericIEnumerable <TElement>(ref BssomWriter writer,
                                                                  ref BssomSerializeContext context, IEnumerable <TElement> value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            IBssomFormatter <TElement> formatter = context.Option.FormatterResolver.GetFormatterWithVerify <TElement>();

            writer.WriteArray2Type();
            long pos = writer.FillUInt32FixNumber();

            if (value.TryGetICollectionCount(out int count))
            {
                writer.WriteVariableNumber(count);
                foreach (TElement item in value)
                {
                    context.CancellationToken.ThrowIfCancellationRequested();
                    formatter.Serialize(ref writer, ref context, item);
                }
                writer.WriteBackFixNumber(pos, checked ((int)(writer.Position - pos - BssomBinaryPrimitives.FixUInt32NumberSize)));
            }
            else
            {
                count = 0;
                long posCount = writer.FillUInt32FixNumber();
                foreach (TElement item in value)
                {
                    context.CancellationToken.ThrowIfCancellationRequested();
                    count++;
                    formatter.Serialize(ref writer, ref context, item);
                }
                long cPos = writer.Position;
                writer.BufferWriter.Seek(pos);
                writer.WriteBackFixNumber(checked ((int)(writer.Position - posCount)));
                writer.WriteBackFixNumber(count);
                writer.BufferWriter.Seek(cPos);
            }
        }
Ejemplo n.º 18
0
        //Serialize IList
        public static void SerializeIList(ref BssomWriter writer, ref BssomSerializeContext context, IList value)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            IBssomFormatter <object> formatter = context.Option.FormatterResolver.GetFormatterWithVerify <object>();

            writer.WriteArray2Type();
            long pos = writer.FillUInt32FixNumber();

            writer.WriteVariableNumber(value.Count);
            for (int i = 0; i < value.Count; i++)
            {
                context.CancellationToken.ThrowIfCancellationRequested();
                formatter.Serialize(ref writer, ref context, value[i]);
            }
            writer.WriteBackFixNumber(pos, checked ((int)(writer.Position - pos - BssomBinaryPrimitives.FixUInt32NumberSize)));
        }
Ejemplo n.º 19
0
        //Serialize IList<> / IReadOnlyList<>
        public static void SerializeGenerIList <TElement>(ref BssomWriter writer, ref BssomSerializeContext context,
                                                          IEnumerable <TElement> value)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                DEBUG.Assert(value is IList <TElement> || value is IReadOnlyList <TElement>);
                IBssomFormatter <TElement> formatter = context.Option.FormatterResolver.GetFormatterWithVerify <TElement>();

                writer.WriteArray2Type();
                long pos = writer.FillUInt32FixNumber();
                if (value is IList <TElement> list)
                {
                    writer.WriteVariableNumber(list.Count);
                    for (int i = 0; i < list.Count; i++)
                    {
                        context.CancellationToken.ThrowIfCancellationRequested();
                        formatter.Serialize(ref writer, ref context, list[i]);
                    }
                }
                else
                {
                    IReadOnlyList <TElement> rels = Unsafe.As <IEnumerable <TElement>, IReadOnlyList <TElement> >(ref value);
                    writer.WriteVariableNumber(rels.Count);
                    for (int i = 0; i < rels.Count; i++)
                    {
                        context.CancellationToken.ThrowIfCancellationRequested();
                        formatter.Serialize(ref writer, ref context, rels[i]);
                    }
                }
                writer.WriteBackFixNumber(pos, checked ((int)(writer.Position - pos - BssomBinaryPrimitives.FixUInt32NumberSize)));
            }
        }
Ejemplo n.º 20
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, int value)
 {
     value -= 5;
     PrimitiveResolver.Instance.GetFormatter <int>().Serialize(ref writer, ref context, value);
 }
Ejemplo n.º 21
0
            public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, _Attribute_Class_3 value)
            {
                SecurityVerification(value, context.Option);

                MapCodeGenResolver.Instance.GetFormatter <_Attribute_Class_3>().Serialize(ref writer, ref context, value);
            }
Ejemplo n.º 22
0
 public void WriteObjectElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, object value)
 {
     WriteElement(ref writer, option, offsetInfo, (Int16)value);
 }
Ejemplo n.º 23
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, IDictionary value)
 {
     MapFormatterHelper.SerializeIDictionary(ref writer, ref context, value);
 }
Ejemplo n.º 24
0
 public MapRouteSegmentWriter(BssomWriter writer, long basePosition)
 {
     this.writer   = writer;
     _basePosition = basePosition;
 }
Ejemplo n.º 25
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, Int32 value)
 {
     writer.Write(value);
 }
Ejemplo n.º 26
0
 public void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, BssomDecimal value)
 {
     WriteElement(ref writer, option, offsetInfo, value.RawValue);
 }
Ejemplo n.º 27
0
 public void WriteObjectElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, object value)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 28
0
 public void Serialize(ref BssomWriter writer, ref BssomSerializeContext context, T value)
 {
     serializer(ref writer, ref context, value);
 }
Ejemplo n.º 29
0
 public static void WriteElement(ref BssomWriter writer, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo, T value)
 {
     _controller.WriteElement(ref writer, option, offsetInfo, value);
 }
Ejemplo n.º 30
0
 public static void WriteEmptyMapObject(ref BssomWriter writer)
 {
     writer.WriteRaw(Empty, 0, Empty.Length);
 }