/// <summary>
        /// Gets the full payload size of the next objet.
        /// </summary>
        /// <param name="Reader">Binary deserializer.</param>
        /// <returns>Full payloa size.</returns>
        public uint GetFullPayloadSize(BinaryDeserializer Reader)
        {
            int  Pos      = Reader.Position;
            uint DataType = Reader.ReadBits(6);

            switch (DataType)
            {
            case ObjectSerializer.TYPE_OBJECT:
                string            TypeName = Reader.ReadString();
                IObjectSerializer Serializer;

                if (string.IsNullOrEmpty(TypeName))
                {
                    Serializer = this.genericSerializer;
                }
                else
                {
                    Type T = Types.GetType(TypeName);
                    if (T != null)
                    {
                        Serializer = this.provider.GetObjectSerializer(T);
                    }
                    else
                    {
                        Serializer = this.genericSerializer;
                    }
                }

                Reader.Position = Pos;

                Serializer.Deserialize(Reader, ObjectSerializer.TYPE_OBJECT, false);
                break;

            case ObjectSerializer.TYPE_BOOLEAN:
                Reader.SkipBit();
                break;

            case ObjectSerializer.TYPE_BYTE:
                Reader.SkipByte();
                break;

            case ObjectSerializer.TYPE_INT16:
                Reader.SkipInt16();
                break;

            case ObjectSerializer.TYPE_INT32:
                Reader.SkipInt32();
                break;

            case ObjectSerializer.TYPE_INT64:
                Reader.SkipInt64();
                break;

            case ObjectSerializer.TYPE_SBYTE:
                Reader.SkipSByte();
                break;

            case ObjectSerializer.TYPE_UINT16:
                Reader.SkipUInt16();
                break;

            case ObjectSerializer.TYPE_UINT32:
                Reader.SkipUInt32();
                break;

            case ObjectSerializer.TYPE_UINT64:
                Reader.SkipUInt64();
                break;

            case ObjectSerializer.TYPE_DECIMAL:
                Reader.SkipDecimal();
                break;

            case ObjectSerializer.TYPE_DOUBLE:
                Reader.SkipDouble();
                break;

            case ObjectSerializer.TYPE_SINGLE:
                Reader.SkipSingle();
                break;

            case ObjectSerializer.TYPE_DATETIME:
                Reader.SkipDateTime();
                break;

            case ObjectSerializer.TYPE_TIMESPAN:
                Reader.SkipTimeSpan();
                break;

            case ObjectSerializer.TYPE_CHAR:
                Reader.SkipChar();
                break;

            case ObjectSerializer.TYPE_STRING:
                Reader.SkipString();
                break;

            case ObjectSerializer.TYPE_ENUM:
                Reader.SkipString();
                break;

            case ObjectSerializer.TYPE_BYTEARRAY:
                Reader.SkipByteArray();
                break;

            case ObjectSerializer.TYPE_GUID:
                Reader.SkipGuid();
                break;

            case ObjectSerializer.TYPE_NULL:
                break;

            default:
                throw new Exception("Object or value expected.");
            }

            Reader.FlushBits();

            uint Len = (uint)(Reader.Position - Pos);

            Reader.Position = Pos;

            return(Len);
        }
예제 #2
0
        private async Task <KeyValuePair <uint, uint> > GetSize(BinaryDeserializer Reader)
        {
            int  Pos      = Reader.Position;
            uint DataType = Reader.ReadBits(6);

            switch (DataType)
            {
            case ObjectSerializer.TYPE_OBJECT:
                ulong  TypeCode       = Reader.ReadVariableLengthUInt64();
                ulong  CollectionCode = Reader.ReadVariableLengthUInt64();
                string CollectionName = await this.provider.GetFieldName(null, CollectionCode);

                string TypeName = await this.provider.GetFieldName(CollectionName, TypeCode);

                IObjectSerializer Serializer;

                if (string.IsNullOrEmpty(TypeName))
                {
                    Serializer = this.genericSerializer;
                }
                else
                {
                    Type T = Types.GetType(TypeName);
                    if (T is null)
                    {
                        Serializer = this.genericSerializer;
                    }
                    else
                    {
                        Serializer = await this.provider.GetObjectSerializer(T);
                    }
                }

                Reader.Position = Pos + 1;
                await Serializer.Deserialize(Reader, ObjectSerializer.TYPE_OBJECT, true);

                break;

            case ObjectSerializer.TYPE_BOOLEAN:
                Reader.SkipBit();
                break;

            case ObjectSerializer.TYPE_BYTE:
                Reader.SkipByte();
                break;

            case ObjectSerializer.TYPE_INT16:
                Reader.SkipInt16();
                break;

            case ObjectSerializer.TYPE_INT32:
                Reader.SkipInt32();
                break;

            case ObjectSerializer.TYPE_INT64:
                Reader.SkipInt64();
                break;

            case ObjectSerializer.TYPE_SBYTE:
                Reader.SkipSByte();
                break;

            case ObjectSerializer.TYPE_UINT16:
                Reader.SkipUInt16();
                break;

            case ObjectSerializer.TYPE_UINT32:
                Reader.SkipUInt32();
                break;

            case ObjectSerializer.TYPE_UINT64:
                Reader.SkipUInt64();
                break;

            case ObjectSerializer.TYPE_DECIMAL:
                Reader.SkipDecimal();
                break;

            case ObjectSerializer.TYPE_DOUBLE:
                Reader.SkipDouble();
                break;

            case ObjectSerializer.TYPE_SINGLE:
                Reader.SkipSingle();
                break;

            case ObjectSerializer.TYPE_DATETIME:
                Reader.SkipDateTime();
                break;

            case ObjectSerializer.TYPE_DATETIMEOFFSET:
                Reader.SkipDateTimeOffset();
                break;

            case ObjectSerializer.TYPE_TIMESPAN:
                Reader.SkipTimeSpan();
                break;

            case ObjectSerializer.TYPE_CHAR:
                Reader.SkipChar();
                break;

            case ObjectSerializer.TYPE_STRING:
            case ObjectSerializer.TYPE_CI_STRING:
            case ObjectSerializer.TYPE_ENUM:
                Reader.SkipString();
                break;

            case ObjectSerializer.TYPE_BYTEARRAY:
                Reader.SkipByteArray();
                break;

            case ObjectSerializer.TYPE_GUID:
                Reader.SkipGuid();
                break;

            case ObjectSerializer.TYPE_NULL:
                break;

            case ObjectSerializer.TYPE_ARRAY:
                throw new Exception("Arrays must be embedded in objects.");

            case ObjectSerializer.TYPE_MAX:                         // BLOB
                return(new KeyValuePair <uint, uint>(4, (uint)Reader.ReadVariableLengthUInt64()));

            default:
                throw new Exception("Object or value expected.");
            }

            Reader.FlushBits();

            uint Size = (uint)(Reader.Position - Pos);

            Reader.Position = Pos;

            return(new KeyValuePair <uint, uint>(Size, Size));
        }