Esempio n. 1
0
        public static BssomFieldOffsetInfo IndexOf(IBssomBuffer buffer, IIndexOfInputSource indexOfInputSource)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (indexOfInputSource is null)
            {
                throw new ArgumentNullException(nameof(indexOfInputSource));
            }

            BssomReader          reader = new BssomReader(buffer);
            BssomFieldOffsetInfo info   = new BssomFieldOffsetInfo();

            indexOfInputSource.Reset();
            if (!indexOfInputSource.MoveNext())
            {
                throw BssomSerializationOperationException.InputDataSouceIsEmpty();
            }

Next:
            byte bssOjectType = reader.SkipBlankCharacterAndReadBssomType();

            switch (bssOjectType)
            {
            case BssomType.Map1:
            {
                object key = indexOfInputSource.CurrentMapKey();
                if (!BssMapKeyResolverProvider.TryGetBssMapKeyResolver(key.GetType(), out IBssMapKeyResolver resolver))
                {
                    throw BssomSerializationTypeFormatterException.BssomMapKeyUnsupportedType(key.GetType());
                }

                reader.SkipVariableNumber();        //Skip Length
                int count = reader.ReadVariableNumber();
                Raw64BytesISegment keyISegment = resolver.GetMap1KeySegment(key);
                for (int i = 0; i < count; i++)
                {
                    int keyLength = reader.GetMap1KeyLength();
                    if (keyISegment.DataLen != keyLength)
                    {
                        reader.BssomBuffer.Seek(keyLength, BssomSeekOrgin.Current); //Advance Key
                        reader.SkipObject();                                        //Skip Value
                        continue;
                    }

                    //determine if the key is equal
                    bool keyIsEqual = true;
                    for (int z = 0; z < keyISegment.Length; z++)
                    {
                        if (keyISegment[z] != reader.ReadRaw64(ref keyLength))
                        {
                            reader.BssomBuffer.Seek(keyLength, BssomSeekOrgin.Current); //Advance remaining keyLength
                            reader.SkipObject();                                        //Skip Value
                            keyIsEqual = false;
                            break;
                        }
                    }

                    if (keyIsEqual)
                    {
                        if (!indexOfInputSource.MoveNext())
                        {
                            info.Offset       = reader.Position;
                            info.IsArray1Type = false;
                            return(info);
                        }
                        else
                        {
                            goto Next;
                        }
                    }
                }
                if (indexOfInputSource.MoveNext())
                {
                    throw BssomSerializationOperationException.BssomMapIsNull(key);
                }

                info.Offset = -1;
                return(info);
            }

            case BssomType.Map2:
            {
                object key = indexOfInputSource.CurrentMapKey();
                if (!BssMapKeyResolverProvider.TryGetBssMapKeyResolver(key.GetType(), out IBssMapKeyResolver resolver))
                {
                    throw BssomSerializationTypeFormatterException.BssomMapKeyUnsupportedType(key.GetType());
                }

                UInt64BytesISegment keyISegment = resolver.GetMap2KeySegment(key);
                BssMapHeadPackInfo  aprp        = BssMapHeadPackInfo.Create(ref reader);
                if (aprp.MapHead.ElementCount > 0)
                {
                    ref byte refb = ref reader.BssomBuffer.TryReadFixedRef(aprp.MapHead.RouteLength, out bool haveEnoughSizeAndCanBeFixed);
                    if (haveEnoughSizeAndCanBeFixed)
                    {
                        if (BssMapObjMarshalReader.TrySeek(keyISegment, resolver.KeyType, resolver.KeyIsNativeType, ref aprp, ref reader, ref refb))
                        {
                            if (!indexOfInputSource.MoveNext())
                            {
                                info.Offset       = reader.Position;
                                info.IsArray1Type = false;
                                return(info);
                            }
                            else
                            {
                                goto Next;
                            }
                        }
                    }
                    else
                    {
                        if (BssMapObjMarshalReader.TrySeekSlow(keyISegment, resolver.KeyType, resolver.KeyIsNativeType, ref aprp, ref reader))
                        {
                            if (!indexOfInputSource.MoveNext())
                            {
                                info.Offset       = reader.Position;
                                info.IsArray1Type = false;
                                return(info);
                            }
                            else
                            {
                                goto Next;
                            }
                        }
                    }
                }
                if (indexOfInputSource.MoveNext())
                {
                    throw BssomSerializationOperationException.BssomMapIsNull(key);
                }

                info.Offset = -1;
                return(info);
            }
Esempio n. 2
0
 public static IEnumerable <KeyValuePair <TKey, BssomFieldOffsetInfo> > ReadAllKeysByMapType <TKey>(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo, BssomSerializerOptions option = null)
 {
     return(ReadAllKeysByMapType <TKey>(new SimpleBufferWriter(buffer, start, end), offsetInfo, option));
 }
Esempio n. 3
0
 public static bool TryWrite <T>(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo, T value, BssomSerializerOptions option = null)
 {
     return(TryWrite(new SimpleBufferWriter(buffer, start, end), offsetInfo, value, option));
 }
Esempio n. 4
0
 public static byte ReadValueTypeCode(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo, out bool isNativeType)
 {
     return(ReadValueTypeCode(new SimpleBufferWriter(buffer, start, end), offsetInfo, out isNativeType));
 }
Esempio n. 5
0
 public static int ReadArrayCount(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo)
 {
     return(ReadArrayCountByMapType(new SimpleBufferWriter(buffer, start, end), offsetInfo));
 }
Esempio n. 6
0
 public static T ReadValue <T>(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo, BssomSerializerOptions option = null)
 {
     return(ReadValue <T>(new SimpleBufferWriter(buffer, start, end), offsetInfo, option));
 }
Esempio n. 7
0
 public static BssomValueType ReadValueType(byte[] buffer, int start, int end, BssomFieldOffsetInfo offsetInfo)
 {
     return(ReadValueType(new SimpleBufferWriter(buffer, start, end), offsetInfo));
 }
Esempio n. 8
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取Map对象的字段位置信息. Read the field location information of the Map object by specifying the location information of the buffer
 /// </summary>
 /// <typeparam name="TKey">Map对象的Key类型,如不确认可以为<see cref="object"/>. The Key type of the Map object, if not confirmed, it can be <seealso cref="object"/></typeparam>
 /// <param name="offsetInfo">用于读取的位置信息. Location information for reading</param>
 /// <param name="option">过程中所使用的配置. Configuration used in the process</param>
 /// <returns>Map对象的字段位置信息. Field location information of the Map object</returns>
 /// <exception cref="BssomSerializationOperationException">缓冲区<paramref name="offsetInfo"/>位置处的对象并不是Map类型,类型读取错误. The object at the position of the buffer <paramref name="offsetInfo"/> is not a Map type, and the type is read incorrectly</exception>
 public IEnumerable <KeyValuePair <TKey, BssomFieldOffsetInfo> > ReadAllKeysByMapType <TKey>(BssomFieldOffsetInfo offsetInfo, BssomSerializerOptions option = null)
 {
     return(ReadAllKeysByMapType <TKey>(bufferWriter.GetBssomBuffer(), offsetInfo, option));
 }
Esempio n. 9
0
 /// <summary>
 /// <para>尝试在指定的位置对缓冲区进行对象写入</para>
 /// <para>Attempt to write an object to the buffer at the specified location</para>
 /// </summary>
 /// <typeparam name="T">被写入元素的类型. The type of element being written</typeparam>
 /// <param name="offsetInfo">用于写入元素的位置信息. Used to write the position information of the element</param>
 /// <param name="value">被写入的对象. Value being written</param>
 /// <param name="option">过程中所使用的配置. Configuration used in the process</param>
 /// <returns>
 /// <para>如果对象的二进制大小小于对象在缓冲区中的大小,则成功写入,返回true</para>
 /// <para>If the binary size of the value is smaller than the size of the member in the buffer, it is successfully written and true is returned</para>
 /// </returns>
 public bool TryWrite <T>(BssomFieldOffsetInfo offsetInfo, T value, BssomSerializerOptions option = null)
 {
     return(TryWrite <T>(bufferWriter, offsetInfo, value, option));
 }
Esempio n. 10
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取Array对象的元素数量. Read the number of elements of the Array object by specifying the location information of the buffer
 /// </summary>
 /// <param name="offsetInfo">用于读取元素的位置信息. Location information for reading</param>
 /// <returns>Array对象的元素数量. The number of elements of the Array object</returns>
 /// <exception cref="BssomSerializationOperationException">缓冲区<paramref name="offsetInfo"/>位置处的对象并不是Array类型,类型读取错误. The object at the position of the buffer <paramref name="offsetInfo"/> is not a Array type, and the type is read incorrectly</exception>
 public int ReadArrayCountByMapType(BssomFieldOffsetInfo offsetInfo)
 {
     return(ReadArrayCountByMapType(bufferWriter.GetBssomBuffer(), offsetInfo));
 }
Esempio n. 11
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取元素在缓冲区存储的大小(包括从此位置开始的空白符). Read the size of the element stored in the buffer by specifying the location information of the buffer(includes white space from this position)
 /// </summary>
 /// <param name="offsetInfo">用于读取元素的位置信息. Location information for reading</param>
 /// <returns>被读取的元素大小,包含空白符大小. Element typecode being read size,contains the blank size</returns>
 public int ReadValueSize(BssomFieldOffsetInfo offsetInfo)
 {
     return(ReadValueSize(bufferWriter.GetBssomBuffer(), offsetInfo));
 }
Esempio n. 12
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取元素的类型码. Read the element typecode by specifying the location information of the buffer
 /// </summary>
 /// <param name="offsetInfo">用于读取元素的位置信息. Location information for reading</param>
 /// <param name="isNativeType">若对象是本地类型,则为true. True if the object is a native type</param>
 /// <returns>被读取的元素类型码. Element typecode being read</returns>
 public byte ReadValueTypeCode(BssomFieldOffsetInfo offsetInfo, out bool isNativeType)
 {
     return(ReadValueTypeCode(bufferWriter.GetBssomBuffer(), offsetInfo, out isNativeType));
 }
Esempio n. 13
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取元素的类型. Read the element type by specifying the location information of the buffer
 /// </summary>
 /// <param name="offsetInfo">用于读取的位置信息. Location information for reading</param>
 /// <returns>被读取的元素类型. Element type being read</returns>
 public BssomValueType ReadValueType(BssomFieldOffsetInfo offsetInfo)
 {
     return(ReadValueType(bufferWriter.GetBssomBuffer(), offsetInfo));
 }
Esempio n. 14
0
 /// <summary>
 /// 通过指定缓冲区的位置信息来读取元素. Read the element by specifying the location information of the buffer
 /// </summary>
 /// <typeparam name="T">被读取元素的类型,如不确认可以为<see cref="object"/>. The type of the read element, if not confirmed, it can be <seealso cref="object"/></typeparam>
 /// <param name="offsetInfo">用于读取的位置信息. Location information for reading</param>
 /// <param name="option">过程中所使用的配置. Configuration used in the process</param>
 /// <returns>被读取的元素. Element being read</returns>
 public T ReadValue <T>(BssomFieldOffsetInfo offsetInfo, BssomSerializerOptions option = null)
 {
     return(ReadValue <T>(bufferWriter.GetBssomBuffer(), offsetInfo, option));
 }