Пример #1
0
        /// <summary>
        /// <para>根据<paramref name="isNativeType"/>和<paramref name="typeCode"/>来获得BssomValueType</para>
        /// <para>Obtain the BssomValueType name according to <paramref name="isNativeType"/> and <paramref name="typeCode"/></para>
        /// </summary>
        /// <returns>BssomValueType</returns>
        public static BssomValueType GetBssomValueType(bool isNativeType, byte typeCode)
        {
            if (isNativeType)
            {
                switch (typeCode)
                {
                case NativeBssomType.CharCode:
                    return(BssomValueType.Char);

                case NativeBssomType.DateTimeCode:
                    return(BssomValueType.DateTime);

                case NativeBssomType.DecimalCode:
                    return(BssomValueType.Decimal);

                case NativeBssomType.GuidCode:
                    return(BssomValueType.Guid);
                }
            }
            else
            {
                switch (typeCode)
                {
                case BssomType.NullCode:
                    return(BssomValueType.Null);

                case BssomType.Int8Code:
                case BssomType.Int16Code:
                case BssomType.Int32Code:
                case BssomType.Int64Code:
                case BssomType.UInt8Code:
                case BssomType.UInt16Code:
                case BssomType.UInt32Code:
                case BssomType.UInt64Code:
                    return(BssomValueType.Number);

                case BssomType.Float32Code:
                case BssomType.Float64Code:
                    return(BssomValueType.Float);

                case BssomType.BooleanCode:
                    return(BssomValueType.Boolean);

                case BssomType.TimestampCode:
                    return(BssomValueType.DateTime);

                case BssomType.StringCode:
                    return(BssomValueType.String);

                case BssomType.Map1:
                case BssomType.Map2:
                    return(BssomValueType.Map);

                case BssomType.Array1:
                case BssomType.Array2:
                    return(BssomValueType.Array);
                }
            }
            throw BssomSerializationArgumentException.InvalidTypeCode();
        }
Пример #2
0
        public Int32 ReadElement(ref BssomReader reader, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo)
        {
            if (offsetInfo.Array1ElementTypeIsNativeType == false && offsetInfo.Array1ElementType == BssomType.Int32Code)
            {
                return(reader.ReadInt32WithOutTypeHead());
            }

            return(BssomSerializationArgumentException.InvalidOffsetInfoFormat <Int32>());
        }
Пример #3
0
        public Guid ReadElement(ref BssomReader reader, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo)
        {
            if (offsetInfo.Array1ElementTypeIsNativeType == true && offsetInfo.Array1ElementType == NativeBssomType.GuidCode)
            {
                return(reader.ReadGuidWithOutTypeHead());
            }

            return(BssomSerializationArgumentException.InvalidOffsetInfoFormat <Guid>());
        }
Пример #4
0
        public static IArray1ElementWriter GetArray1ElementWriter(Type type)
        {
            if (containers.TryGetValue(type, out IArray1ElementWriter array1ElementWriter))
            {
                return(array1ElementWriter);
            }

            return(BssomSerializationArgumentException.InvalidOffsetInfoFormat <IArray1ElementWriter>());
        }
Пример #5
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>();
     }
 }
Пример #6
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>();
     }
 }
        public static void VertyBssMapStringKey(object key)
        {
            if (key == null)
            {
                ThrowArgumentNullException(key);
            }

            if (((string)key) == string.Empty)
            {
                BssomSerializationArgumentException.BssomMapStringKeyIsEmpty();
            }
        }
Пример #8
0
 public DateTime ReadElement(ref BssomReader reader, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo)
 {
     if (offsetInfo.Array1ElementTypeIsNativeType == false && offsetInfo.Array1ElementType == BssomType.TimestampCode)
     {
         return(reader.ReadStandDateTimeWithOutTypeHead());
     }
     else if (offsetInfo.Array1ElementTypeIsNativeType == true && offsetInfo.Array1ElementType == NativeBssomType.DateTimeCode)
     {
         return(reader.ReadNativeDateTimeWithOutTypeHead());
     }
     else
     {
         return(BssomSerializationArgumentException.InvalidOffsetInfoFormat <DateTime>());
     }
 }
Пример #9
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>();
     }
 }
Пример #10
0
 public static IArray1ElementWriter GetArray1ElementWriter(bool isNativeType, byte type)
 {
     if (!isNativeType)
     {
         if (type > BssomType.MinFixLenTypeCode && type <= BssomType.TimestampCode)
         {
             return(buildInTypeContainers[type - BssomType.MinFixLenTypeCode - 1]);
         }
     }
     else
     {
         if (type <= NativeBssomType.MaxCode)
         {
             IArray1ElementWriter writer = nativeTypeContainers[type];
             if (writer != null)
             {
                 return(writer);
             }
         }
     }
     return(BssomSerializationArgumentException.InvalidOffsetInfoFormat <IArray1ElementWriter>());
 }
Пример #11
0
        /// <summary>
        /// <para>根据<paramref name="isNativeType"/>和<paramref name="typeCode"/>来获得Bssom类型名称</para>
        /// <para>Obtain the Bssom type name according to <paramref name="isNativeType"/> and <paramref name="typeCode"/></para>
        /// </summary>
        /// <returns>Bssom type name</returns>
        public static string GetTypeName(bool isNativeType, byte typeCode)
        {
            if (isNativeType)
            {
                switch (typeCode)
                {
                case NativeBssomType.CharCode:
                    return(nameof(NativeBssomType.CharCode));

                case NativeBssomType.DateTimeCode:
                    return(nameof(NativeBssomType.DateTimeCode));

                case NativeBssomType.DecimalCode:
                    return(nameof(NativeBssomType.DecimalCode));

                case NativeBssomType.GuidCode:
                    return(nameof(NativeBssomType.GuidCode));
                }
            }
            else
            {
                switch (typeCode)
                {
                case BssomType.NullCode: return(nameof(BssomType.NullCode));

                case BssomType.Int8Code: return(nameof(BssomType.Int8Code));

                case BssomType.Int16Code: return(nameof(BssomType.Int16Code));

                case BssomType.Int32Code: return(nameof(BssomType.Int32Code));

                case BssomType.Int64Code: return(nameof(BssomType.Int64Code));

                case BssomType.UInt8Code: return(nameof(BssomType.UInt8Code));

                case BssomType.UInt16Code: return(nameof(BssomType.UInt16Code));

                case BssomType.UInt32Code: return(nameof(BssomType.UInt32Code));

                case BssomType.UInt64Code: return(nameof(BssomType.UInt64Code));

                case BssomType.Float32Code: return(nameof(BssomType.Float32Code));

                case BssomType.Float64Code: return(nameof(BssomType.Float64Code));

                case BssomType.BooleanCode: return(nameof(BssomType.BooleanCode));

                case BssomType.TimestampCode: return(nameof(BssomType.TimestampCode));

                case BssomType.StringCode: return(nameof(BssomType.StringCode));

                case BssomType.Map1: return(nameof(BssomType.Map1));

                case BssomType.Map2: return(nameof(BssomType.Map2));

                case BssomType.Array1: return(nameof(BssomType.Array1));

                case BssomType.Array2: return(nameof(BssomType.Array2));
                }
            }
            throw BssomSerializationArgumentException.InvalidTypeCode();
        }