示例#1
0
        public unsafe bool ReadFrom(WireType.WireTypeReader reader)
        {
            if (reader is null)
            {
                throw new System.ArgumentNullException(nameof(reader));
            }

            long size        = reader.Current.Size;
            long alreadyRead = reader.TotalRead;

            while (reader.TotalRead - alreadyRead < size)
            {
                if (!reader.Read(out WireType.TypeHeader header))
                {
                    return(false);
                }

                switch (header.Ordinal)
                {
                case 1:     // Leaves
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out Sample.Basic[] values))
                    {
                        _Leaves.Value = values;
                    }
                }
                break;

                case 4:     // Branches
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out Sample.Complex[] values))
                    {
                        _Branches.Value = values;
                    }
                }
                break;
                }
            }

            return(true);
        }
示例#2
0
文件: Person.cs 项目: whoisj/wiretype
        public unsafe bool ReadFrom(WireType.WireTypeReader reader)
        {
            if (reader is null)
            {
                throw new System.ArgumentNullException(nameof(reader));
            }

            long size        = reader.Current.Size;
            long alreadyRead = reader.TotalRead;

            while (reader.TotalRead - alreadyRead < size)
            {
                if (!reader.Read(out WireType.TypeHeader header))
                {
                    return(false);
                }

                switch (header.Ordinal)
                {
                case 1:     // Name
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out byte[] value))
                    {
                        _Name.Value = value;
                    }
                }
                break;

                case 2:     // DoB
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out long value))
                    {
                        _DoB.Value = value;
                    }
                }
                break;

                case 3:     // Len
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out long value))
                    {
                        _Len.Value = value;
                    }
                }
                break;

                case 4:     // Mother
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out Sample.More.Person[] values))
                    {
                        _Mother.Value = values;
                    }
                }
                break;

                case 7:     // Friends
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out byte[][] values))
                    {
                        _Friends.Value = values;
                    }
                }
                break;

                case 8:     // Raw
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out byte[] value))
                    {
                        _Raw.Value = value;
                    }
                }
                break;

                case 567:     // Images
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out byte[][] values))
                    {
                        _Images.Value = values;
                    }
                }
                break;
                }
            }

            return(true);
        }
示例#3
0
文件: Basic.cs 项目: whoisj/wiretype
        public unsafe bool ReadFrom(WireType.WireTypeReader reader)
        {
            if (reader is null)
            {
                throw new System.ArgumentNullException(nameof(reader));
            }

            long size        = reader.Current.Size;
            long alreadyRead = reader.TotalRead;

            while (reader.TotalRead - alreadyRead < size)
            {
                if (!reader.Read(out WireType.TypeHeader header))
                {
                    return(false);
                }

                switch (header.Ordinal)
                {
                case 1:     // Text
                {
                    if (header.Kind != WireType.TypeKind.ExplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out byte[] value))
                    {
                        _Text.Value = value;
                    }
                }
                break;

                case 2:     // Value
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out int value))
                    {
                        _Value.Value = value;
                    }
                }
                break;

                case 3:     // Enum
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSize)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out int value))
                    {
                        _Enum.Value = (Sample.Values)value;
                    }
                }
                break;

                case 4:     // Values
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out float[] values))
                    {
                        _Values.Value = values;
                    }
                }
                break;

                case 5:     // List
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out ulong[] values))
                    {
                        _List.Value = values;
                    }
                }
                break;

                case 6:     // Enums
                {
                    if (header.Kind != WireType.TypeKind.ImplicitSizeList)
                    {
                        reader.Skip();
                    }

                    if (reader.Read(out int[] temp))
                    {
                        var values = new Sample.Values[temp.Length];

                        System.Buffer.BlockCopy(temp, 0, values, 0, temp.Length * sizeof(int));

                        _Enums.Value = values;
                    }
                }
                break;
                }
            }

            return(true);
        }