Esempio n. 1
0
 public override object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(fieldNumber == source.FieldNumber);
     if (strict) { source.Assert(wireType); }
     else if (NeedsHint) { source.Hint(wireType); }
     return Tail.Read(value, source);
 }
Esempio n. 2
0
 // Token: 0x0600027E RID: 638 RVA: 0x000038AE File Offset: 0x00001AAE
 public override object Read(object value, ProtoReader source)
 {
     if (this.strict)
     {
         source.Assert(this.wireType);
     }
     else if (this.NeedsHint)
     {
         source.Hint(this.wireType);
     }
     return(this.Tail.Read(value, source));
 }
Esempio n. 3
0
 public override object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(fieldNumber == source.FieldNumber);
     if (strict)
     {
         source.Assert(wireType);
     }
     else if (NeedsHint)
     {
         source.Hint(wireType);
     }
     return(Tail.Read(value, source));
 }
Esempio n. 4
0
 public override object Read(ProtoReader source, ref ProtoReader.State state, object value)
 {
     Helpers.DebugAssert(fieldNumber == source.FieldNumber);
     if (strict)
     {
         source.Assert(ref state, wireType);
     }
     else if (NeedsHint)
     {
         source.Hint(wireType);
     }
     return(Tail.Read(source, ref state, value));
 }
Esempio n. 5
0
        public override object Read(object value, ProtoReader source)
        {
            // ReadFieldHeader called outside
            // so wireType is read already too!

            if (_strict)
            {
                source.Assert(_wireType);
            }
            else if (NeedsHint)
            {
                source.Hint(_wireType);
            }
            return(Tail.Read(value, source));
        }
        private static void Merge(ProtoReader reader, ref ProtoReader.State state, ref protogen.OrderLine obj)
        {
            int field;

            if (obj == null)
            {
                obj = new protogen.OrderLine();
            }
            while ((field = reader.ReadFieldHeader(ref state)) != 0)
            {
                switch (field)
                {
                case 1:
                    obj.OrderID = reader.ReadInt32(ref state);
                    break;

                case 2:
                    obj.ProductID = reader.ReadInt32(ref state);
                    break;

                case 3:
                    obj.UnitPrice = reader.ReadDouble(ref state);
                    break;

                case 4:
                    reader.Hint(WireType.SignedVariant);
                    obj.Quantity = reader.ReadInt32(ref state);
                    break;

                case 5:
                    obj.Discount = reader.ReadSingle(ref state);
                    break;

                default:
                    reader.AppendExtensionData(ref state, obj);
                    break;
                }
            }
        }
Esempio n. 7
0
 public override object Read(object value, ProtoReader source)
 {
     if (this.strict)
     {
         source.Assert(this.wireType);
     }
     else if (this.NeedsHint)
     {
         source.Hint(this.wireType);
     }
     return this.Tail.Read(value, source);
 }
        /// <summary>
        /// This is the more "complete" version of Deserialize, which handles single instances of mapped types.
        /// The value is read as a complete field, including field-header and (for sub-objects) a
        /// length-prefix..kmc  
        /// 
        /// In addition to that, this provides support for:
        ///  - basic values; individual int / string / Guid / etc
        ///  - IList sets of any type handled by TryDeserializeAuxiliaryType
        /// </summary>
        private bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem)
        {
            if (type == null) throw new ArgumentNullException("type");
            Type itemType = null;
            TypeCode typecode = Type.GetTypeCode(type);
            int modelKey;
            WireType wiretype = GetWireType(typecode, format, ref type, out modelKey);

            bool found = false;
            if (wiretype == WireType.None)
            {
                itemType = GetListItemType(type);

                if (itemType != null)
                {
                    return TryDeserializeList(reader, format, tag, type, itemType, ref value);                    
                }
                // otherwise, not a happy bunny...
                ThrowUnexpectedType(type);
            }
            
            // to treat correctly, should read all values

            while (true)
            {
                // for convenience (re complex exit conditions), additional exit test here:
                // if we've got the value, are only looking for one, and we aren't a list - then exit
                if (found && asListItem) break;

                // read the next item
                int fieldNumber = reader.ReadFieldHeader();
                if (fieldNumber <= 0) break;
                if (fieldNumber != tag)
                {
                    if (skipOtherFields)
                    {
                        reader.SkipField();
                        continue;
                    }
                    throw ProtoReader.AddErrorData(new InvalidOperationException(
                        "Expected field " + tag + ", but found " + fieldNumber), reader);
                }
                found = true;
                reader.Hint(wiretype); // handle signed data etc

                if (modelKey >= 0)
                {
                    switch (wiretype)
                    {
                        case WireType.String:
                        case WireType.StartGroup:
                            SubItemToken token = ProtoReader.StartSubItem(reader);
                            value = Deserialize(modelKey, value, reader);
                            ProtoReader.EndSubItem(token, reader);
                            continue;
                        default:
                            value = Deserialize(modelKey, value, reader);
                            continue;
                    }
                }
                switch (typecode)
                {
                    case TypeCode.Int16: value = reader.ReadInt16(); continue;
                    case TypeCode.Int32: value = reader.ReadInt32(); continue;
                    case TypeCode.Int64: value = reader.ReadInt64(); continue;
                    case TypeCode.UInt16: value = reader.ReadUInt16(); continue;
                    case TypeCode.UInt32: value = reader.ReadUInt32(); continue;
                    case TypeCode.UInt64: value = reader.ReadUInt64(); continue;
                    case TypeCode.Boolean: value = reader.ReadBoolean(); continue;
                    case TypeCode.SByte: value = reader.ReadSByte(); continue;
                    case TypeCode.Byte: value = reader.ReadByte(); continue;
                    case TypeCode.Char: value = (char)reader.ReadUInt16(); continue;
                    case TypeCode.Double: value = reader.ReadDouble(); continue;
                    case TypeCode.Single: value = reader.ReadSingle(); continue;
                    case TypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); continue;
                    case TypeCode.Decimal: BclHelpers.ReadDecimal(reader); continue;
                    case TypeCode.String: value = reader.ReadString(); continue;
                }
                if (type == typeof(byte[])) { value = ProtoReader.AppendBytes((byte[])value, reader); continue; }
                if (type == typeof(TimeSpan)) { value = BclHelpers.ReadTimeSpan(reader); continue; }
                if (type == typeof(Guid)) { value = BclHelpers.ReadGuid(reader); continue; }
                if (type == typeof(Uri)) { value = new Uri(reader.ReadString()); continue; }

            }
            if (!found && !asListItem) { value = Activator.CreateInstance(type); }
            return found;
        }
Esempio n. 9
0
        /// <summary>
        /// This is the more "complete" version of Deserialize, which handles single instances of mapped types.
        /// The value is read as a complete field, including field-header and (for sub-objects) a
        /// length-prefix..kmc
        ///
        /// In addition to that, this provides support for:
        ///  - basic values; individual int / string / Guid / etc
        ///  - IList sets of any type handled by TryDeserializeAuxiliaryType
        /// </summary>
        private bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Type     itemType = null;
            TypeCode typecode = Type.GetTypeCode(type);
            int      modelKey;
            WireType wiretype = GetWireType(typecode, format, ref type, out modelKey);

            bool found = false;

            if (wiretype == WireType.None)
            {
                itemType = GetListItemType(type);

                if (itemType != null)
                {
                    return(TryDeserializeList(reader, format, tag, type, itemType, ref value));
                }
                // otherwise, not a happy bunny...
                ThrowUnexpectedType(type);
            }

            // to treat correctly, should read all values

            while (true)
            {
                // for convenience (re complex exit conditions), additional exit test here:
                // if we've got the value, are only looking for one, and we aren't a list - then exit
                if (found && asListItem)
                {
                    break;
                }

                // read the next item
                int fieldNumber = reader.ReadFieldHeader();
                if (fieldNumber <= 0)
                {
                    break;
                }
                if (fieldNumber != tag)
                {
                    if (skipOtherFields)
                    {
                        reader.SkipField();
                        continue;
                    }
                    throw ProtoReader.AddErrorData(new InvalidOperationException(
                                                       "Expected field " + tag + ", but found " + fieldNumber), reader);
                }
                found = true;
                reader.Hint(wiretype); // handle signed data etc

                if (modelKey >= 0)
                {
                    switch (wiretype)
                    {
                    case WireType.String:
                    case WireType.StartGroup:
                        SubItemToken token = ProtoReader.StartSubItem(reader);
                        value = Deserialize(modelKey, value, reader);
                        ProtoReader.EndSubItem(token, reader);
                        continue;

                    default:
                        value = Deserialize(modelKey, value, reader);
                        continue;
                    }
                }
                switch (typecode)
                {
                case TypeCode.Int16: value = reader.ReadInt16(); continue;

                case TypeCode.Int32: value = reader.ReadInt32(); continue;

                case TypeCode.Int64: value = reader.ReadInt64(); continue;

                case TypeCode.UInt16: value = reader.ReadUInt16(); continue;

                case TypeCode.UInt32: value = reader.ReadUInt32(); continue;

                case TypeCode.UInt64: value = reader.ReadUInt64(); continue;

                case TypeCode.Boolean: value = reader.ReadBoolean(); continue;

                case TypeCode.SByte: value = reader.ReadSByte(); continue;

                case TypeCode.Byte: value = reader.ReadByte(); continue;

                case TypeCode.Char: value = (char)reader.ReadUInt16(); continue;

                case TypeCode.Double: value = reader.ReadDouble(); continue;

                case TypeCode.Single: value = reader.ReadSingle(); continue;

                case TypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); continue;

                case TypeCode.Decimal: BclHelpers.ReadDecimal(reader); continue;

                case TypeCode.String: value = reader.ReadString(); continue;
                }
                if (type == typeof(byte[]))
                {
                    value = ProtoReader.AppendBytes((byte[])value, reader); continue;
                }
                if (type == typeof(TimeSpan))
                {
                    value = BclHelpers.ReadTimeSpan(reader); continue;
                }
                if (type == typeof(Guid))
                {
                    value = BclHelpers.ReadGuid(reader); continue;
                }
                if (type == typeof(Uri))
                {
                    value = new Uri(reader.ReadString()); continue;
                }
            }
            if (!found && !asListItem)
            {
                value = Activator.CreateInstance(type);
            }
            return(found);
        }
Esempio n. 10
0
        internal bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem, bool autoCreate, bool insideList)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Type          type2    = null;
            ProtoTypeCode typeCode = Helpers.GetTypeCode(type);
            int           modelKey;
            WireType      wireType = GetWireType(typeCode, format, ref type, out modelKey);
            bool          flag     = false;

            if (wireType == WireType.None)
            {
                type2 = GetListItemType(this, type);
                if (type2 == null && type.IsArray && type.GetArrayRank() == 1 && type != typeof(byte[]))
                {
                    type2 = type.GetElementType();
                }
                if (type2 != null)
                {
                    if (insideList)
                    {
                        throw CreateNestedListsNotSupported();
                    }
                    flag = TryDeserializeList(this, reader, format, tag, type, type2, ref value);
                    if (!flag && autoCreate)
                    {
                        value = CreateListInstance(type, type2);
                    }
                    return(flag);
                }
                ThrowUnexpectedType(type);
            }
            while (!flag || !asListItem)
            {
                int num = reader.ReadFieldHeader();
                if (num <= 0)
                {
                    break;
                }
                if (num != tag)
                {
                    if (skipOtherFields)
                    {
                        reader.SkipField();
                        continue;
                    }
                    throw ProtoReader.AddErrorData(new InvalidOperationException("Expected field " + tag.ToString() + ", but found " + num.ToString()), reader);
                }
                flag = true;
                reader.Hint(wireType);
                if (modelKey >= 0)
                {
                    if ((uint)(wireType - 2) <= 1u)
                    {
                        SubItemToken token = ProtoReader.StartSubItem(reader);
                        value = Deserialize(modelKey, value, reader);
                        ProtoReader.EndSubItem(token, reader);
                    }
                    else
                    {
                        value = Deserialize(modelKey, value, reader);
                    }
                    continue;
                }
                switch (typeCode)
                {
                case ProtoTypeCode.Int16:
                    value = reader.ReadInt16();
                    break;

                case ProtoTypeCode.Int32:
                    value = reader.ReadInt32();
                    break;

                case ProtoTypeCode.Int64:
                    value = reader.ReadInt64();
                    break;

                case ProtoTypeCode.UInt16:
                    value = reader.ReadUInt16();
                    break;

                case ProtoTypeCode.UInt32:
                    value = reader.ReadUInt32();
                    break;

                case ProtoTypeCode.UInt64:
                    value = reader.ReadUInt64();
                    break;

                case ProtoTypeCode.Boolean:
                    value = reader.ReadBoolean();
                    break;

                case ProtoTypeCode.SByte:
                    value = reader.ReadSByte();
                    break;

                case ProtoTypeCode.Byte:
                    value = reader.ReadByte();
                    break;

                case ProtoTypeCode.Char:
                    value = (char)reader.ReadUInt16();
                    break;

                case ProtoTypeCode.Double:
                    value = reader.ReadDouble();
                    break;

                case ProtoTypeCode.Single:
                    value = reader.ReadSingle();
                    break;

                case ProtoTypeCode.DateTime:
                    value = BclHelpers.ReadDateTime(reader);
                    break;

                case ProtoTypeCode.Decimal:
                    value = BclHelpers.ReadDecimal(reader);
                    break;

                case ProtoTypeCode.String:
                    value = reader.ReadString();
                    break;

                case ProtoTypeCode.ByteArray:
                    value = ProtoReader.AppendBytes((byte[])value, reader);
                    break;

                case ProtoTypeCode.TimeSpan:
                    value = BclHelpers.ReadTimeSpan(reader);
                    break;

                case ProtoTypeCode.Guid:
                    value = BclHelpers.ReadGuid(reader);
                    break;

                case ProtoTypeCode.Uri:
                    value = new Uri(reader.ReadString());
                    break;
                }
            }
            if (((!flag && !asListItem) & autoCreate) && type != typeof(string))
            {
                value = Activator.CreateInstance(type);
            }
            return(flag);
        }
Esempio n. 11
0
        internal bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem, bool autoCreate, bool insideList)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            ProtoTypeCode typecode = Helpers.GetTypeCode(type);
            int           modelKey;
            WireType      wiretype = this.GetWireType(typecode, format, ref type, out modelKey);
            bool          found    = false;

            if (wiretype == WireType.None)
            {
                Type itemType = TypeModel.GetListItemType(this, type);
                if (itemType == null && type.IsArray && type.GetArrayRank() == 1 && type != typeof(byte[]))
                {
                    itemType = type.GetElementType();
                }
                if (itemType != null)
                {
                    if (insideList)
                    {
                        throw TypeModel.CreateNestedListsNotSupported();
                    }
                    found = this.TryDeserializeList(this, reader, format, tag, type, itemType, ref value);
                    if (!found && autoCreate)
                    {
                        value = TypeModel.CreateListInstance(type, itemType);
                    }
                    return(found);
                }
                else
                {
                    TypeModel.ThrowUnexpectedType(type);
                }
            }
            while (!found || !asListItem)
            {
                int fieldNumber = reader.ReadFieldHeader();
                if (fieldNumber <= 0)
                {
                    break;
                }
                if (fieldNumber != tag)
                {
                    if (!skipOtherFields)
                    {
                        throw ProtoReader.AddErrorData(new InvalidOperationException("Expected field " + tag.ToString() + ", but found " + fieldNumber.ToString()), reader);
                    }
                    reader.SkipField();
                }
                else
                {
                    found = true;
                    reader.Hint(wiretype);
                    if (modelKey >= 0)
                    {
                        switch (wiretype)
                        {
                        case WireType.String:
                        case WireType.StartGroup:
                        {
                            SubItemToken token = ProtoReader.StartSubItem(reader);
                            value = this.Deserialize(modelKey, value, reader);
                            ProtoReader.EndSubItem(token, reader);
                            break;
                        }

                        default:
                            value = this.Deserialize(modelKey, value, reader);
                            break;
                        }
                    }
                    else
                    {
                        ProtoTypeCode protoTypeCode = typecode;
                        switch (protoTypeCode)
                        {
                        case ProtoTypeCode.Boolean:
                            value = reader.ReadBoolean();
                            break;

                        case ProtoTypeCode.Char:
                            value = (char)reader.ReadUInt16();
                            break;

                        case ProtoTypeCode.SByte:
                            value = reader.ReadSByte();
                            break;

                        case ProtoTypeCode.Byte:
                            value = reader.ReadByte();
                            break;

                        case ProtoTypeCode.Int16:
                            value = reader.ReadInt16();
                            break;

                        case ProtoTypeCode.UInt16:
                            value = reader.ReadUInt16();
                            break;

                        case ProtoTypeCode.Int32:
                            value = reader.ReadInt32();
                            break;

                        case ProtoTypeCode.UInt32:
                            value = reader.ReadUInt32();
                            break;

                        case ProtoTypeCode.Int64:
                            value = reader.ReadInt64();
                            break;

                        case ProtoTypeCode.UInt64:
                            value = reader.ReadUInt64();
                            break;

                        case ProtoTypeCode.Single:
                            value = reader.ReadSingle();
                            break;

                        case ProtoTypeCode.Double:
                            value = reader.ReadDouble();
                            break;

                        case ProtoTypeCode.Decimal:
                            value = BclHelpers.ReadDecimal(reader);
                            break;

                        case ProtoTypeCode.DateTime:
                            value = BclHelpers.ReadDateTime(reader);
                            break;

                        case (ProtoTypeCode)17:
                            break;

                        case ProtoTypeCode.String:
                            value = reader.ReadString();
                            break;

                        default:
                            switch (protoTypeCode)
                            {
                            case ProtoTypeCode.TimeSpan:
                                value = BclHelpers.ReadTimeSpan(reader);
                                break;

                            case ProtoTypeCode.ByteArray:
                                value = ProtoReader.AppendBytes((byte[])value, reader);
                                break;

                            case ProtoTypeCode.Guid:
                                value = BclHelpers.ReadGuid(reader);
                                break;

                            case ProtoTypeCode.Uri:
                                value = new Uri(reader.ReadString());
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            if (!found && !asListItem && autoCreate && type != typeof(string))
            {
                value = Activator.CreateInstance(type);
            }
            return(found);
        }