/// <summary>
        /// Parses a decimal from a protobuf stream
        /// </summary>
        public static decimal ReadDecimal(ProtoReader reader)
        {
            ulong low       = 0;
            uint  high      = 0;
            uint  signScale = 0;

            int          fieldNumber;
            SubItemToken token = ProtoReader.StartSubItem(reader);

            while ((fieldNumber = reader.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldDecimalLow: low = reader.ReadUInt64(); break;

                case FieldDecimalHigh: high = reader.ReadUInt32(); break;

                case FieldDecimalSignScale: signScale = reader.ReadUInt32(); break;

                default: reader.SkipField(); break;
                }
            }
            ProtoReader.EndSubItem(token, reader);

            int lo     = (int)(low & 0xFFFFFFFFL),
                mid    = (int)((low >> 32) & 0xFFFFFFFFL),
                hi     = (int)high;
            bool isNeg = (signScale & 0x0001) == 0x0001;
            byte scale = (byte)((signScale & 0x01FE) >> 1);

            return(new decimal(lo, mid, hi, isNeg, scale));
        }
Example #2
0
        public object Read(object value, ProtoReader source)

        {
            Helpers.DebugAssert(value == null); // since replaces

            return(source.ReadUInt32());
        }
 // Token: 0x060002AD RID: 685 RVA: 0x000039E9 File Offset: 0x00001BE9
 public object Read(object value, ProtoReader source)
 {
     return(source.ReadUInt32());
 }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="mxMessage">
        /// The mx message.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="MxMessage"/>.
        /// </returns>
        private static MxMessage Read(MxMessage mxMessage, ProtoReader protoReader)
        {
            int num;

            while ((num = protoReader.ReadFieldHeader()) > 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (num != 3)
                        {
                            if (num != 4)
                            {
                                if (num != 6)
                                {
                                    if (mxMessage == null)
                                    {
                                        var expr_170 = new MxMessage();
                                        ProtoReader.NoteObject(expr_170, protoReader);
                                        mxMessage = expr_170;
                                    }

                                    protoReader.SkipField();
                                }
                                else
                                {
                                    if (mxMessage == null)
                                    {
                                        var expr_D9 = new MxMessage();
                                        ProtoReader.NoteObject(expr_D9, protoReader);
                                        mxMessage = expr_D9;
                                    }

                                    MxPayload[] payloads = mxMessage.Payloads;
                                    var         list     = new List <MxPayload>();
                                    int         num2     = protoReader.FieldNumber;
                                    do
                                    {
                                        List <MxPayload> arg_111_0 = list;
                                        MxPayload        arg_104_0 = null;
                                        SubItemToken     token     = ProtoReader.StartSubItem(protoReader);
                                        MxPayload        arg_111_1 = Read(arg_104_0, protoReader);
                                        ProtoReader.EndSubItem(token, protoReader);
                                        arg_111_0.Add(arg_111_1);
                                    }while (protoReader.TryReadFieldHeader(num2));
                                    MxPayload[] expr_124 = payloads;
                                    var         array    =
                                        new MxPayload[(num2 = (expr_124 != null) ? expr_124.Length : 0) + list.Count];
                                    if (num2 != 0)
                                    {
                                        payloads.CopyTo(array, 0);
                                    }

                                    list.CopyTo(array, num2);
                                    array = array;
                                    if (array != null)
                                    {
                                        mxMessage.Payloads = array;
                                    }
                                }
                            }
                            else
                            {
                                if (mxMessage == null)
                                {
                                    var expr_A9 = new MxMessage();
                                    ProtoReader.NoteObject(expr_A9, protoReader);
                                    mxMessage = expr_A9;
                                }

                                uint num3 = protoReader.ReadUInt32();
                                mxMessage.AckBitfield = num3;
                            }
                        }
                        else
                        {
                            if (mxMessage == null)
                            {
                                var expr_79 = new MxMessage();
                                ProtoReader.NoteObject(expr_79, protoReader);
                                mxMessage = expr_79;
                            }

                            uint num3 = protoReader.ReadUInt32();
                            mxMessage.Ack = num3;
                        }
                    }
                    else
                    {
                        if (mxMessage == null)
                        {
                            var expr_49 = new MxMessage();
                            ProtoReader.NoteObject(expr_49, protoReader);
                            mxMessage = expr_49;
                        }

                        uint num3 = protoReader.ReadUInt32();
                        mxMessage.Sequence = num3;
                    }
                }
                else
                {
                    if (mxMessage == null)
                    {
                        var expr_19 = new MxMessage();
                        ProtoReader.NoteObject(expr_19, protoReader);
                        mxMessage = expr_19;
                    }

                    uint num3 = protoReader.ReadUInt32();
                    mxMessage.ProtocolID = num3;
                }
            }

            if (mxMessage == null)
            {
                var expr_198 = new MxMessage();
                ProtoReader.NoteObject(expr_198, protoReader);
                mxMessage = expr_198;
            }

            return(mxMessage);
        }
        /// <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;
        }
Example #6
0
        /// <summary>
        /// 解析protobuf数据
        /// </summary>
        /// <param name="reader"></param>
        /// <see cref="https://developers.google.com/protocol-buffers/docs/encoding"/>
        /// <returns>全部成功返回true,部分失败或全失败返回false,这时候可以通过LastError获取失败信息</returns>
        public bool Parse(ProtoReader reader)
        {
            buildIndex();
            lastError.Clear();

            try {
                int          field_id;
                SubItemToken token;
                while ((field_id = reader.ReadFieldHeader()) != 0)
                {
                    WireType pb_type = reader.WireType;

                    FieldDescriptorProto desc;
                    if (false == msgDescriptor.FieldIdIndex.TryGetValue(field_id, out desc))
                    {
                        // unknown field skipped
                        reader.SkipField();
                        continue;
                    }

                    // 类型校验
                    try {
                        switch (desc.type)
                        {
                        case FieldDescriptorProto.Type.TYPE_DOUBLE:
                            insertField(desc, reader.ReadDouble());
                            break;

                        case FieldDescriptorProto.Type.TYPE_FLOAT:
                            insertField(desc, reader.ReadSingle());
                            break;

                        case FieldDescriptorProto.Type.TYPE_INT64:
                        case FieldDescriptorProto.Type.TYPE_SINT64:
                        case FieldDescriptorProto.Type.TYPE_SFIXED64:
                            insertField(desc, reader.ReadInt64());
                            break;

                        case FieldDescriptorProto.Type.TYPE_UINT64:
                        case FieldDescriptorProto.Type.TYPE_FIXED64:
                            insertField(desc, reader.ReadUInt64());
                            break;

                        case FieldDescriptorProto.Type.TYPE_INT32:
                        case FieldDescriptorProto.Type.TYPE_SINT32:
                        case FieldDescriptorProto.Type.TYPE_SFIXED32:
                            insertField(desc, reader.ReadInt32());
                            break;

                        case FieldDescriptorProto.Type.TYPE_BOOL:
                            insertField(desc, reader.ReadBoolean());
                            break;

                        case FieldDescriptorProto.Type.TYPE_STRING:
                            insertField(desc, reader.ReadString());
                            break;

                        //case FieldDescriptorProto.Type.TYPE_GROUP: // deprecated
                        //    break;
                        case FieldDescriptorProto.Type.TYPE_MESSAGE:
                            token = ProtoReader.StartSubItem(reader);
                            try {
                                DynamicMessage sub_msg = CreateMessage(desc);
                                if (null == sub_msg)
                                {
                                    lastError.AddLast(string.Format("{0}.{1}.{2} => invalid message path {3}", msgDescriptor.Package, msgDescriptor.Protocol.name, desc.name, pickMsgName(desc)));
                                    break;
                                }
                                if (false == sub_msg.Parse(reader))
                                {
                                    lastError.AddLast(sub_msg.LastError);
                                }
                                else
                                {
                                    insertField(desc, sub_msg);
                                }
                            } catch (Exception e) {
                                lastError.AddLast(string.Format("{0}.{1}.{2} => {3}", msgDescriptor.Package, msgDescriptor.Protocol.name, desc.name, e.Message));
                            }
                            ProtoReader.EndSubItem(token, reader);
                            break;

                        case FieldDescriptorProto.Type.TYPE_BYTES:
                            insertField(desc, ProtoReader.AppendBytes(null, reader));
                            break;

                        case FieldDescriptorProto.Type.TYPE_FIXED32:
                        case FieldDescriptorProto.Type.TYPE_UINT32:
                            insertField(desc, reader.ReadUInt32());
                            break;

                        case FieldDescriptorProto.Type.TYPE_ENUM:
                            insertField(desc, reader.ReadInt32());
                            break;

                        default:
                            // unsupported field
                            lastError.AddLast(string.Format("field type {0} in {1}.{2}.{3} unsupported", desc.type.ToString(), msgDescriptor.Package, msgDescriptor.Protocol.name, desc.name));
                            reader.SkipField();
                            break;
                        }
                    } catch (Exception e) {
                        lastError.AddLast(string.Format("{0}.{1}.{2} {3}", msgDescriptor.Package, msgDescriptor.Protocol.name, desc.name, e.ToString()));
                        reader.SkipField();
                    }
                }
            } catch (Exception e) {
                lastError.AddLast(e.Message);
            }

            return(0 == lastError.Count);
        }
Example #7
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);
        }
Example #8
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);
        }
        public object Read(object value, ProtoReader source)
        {
			object[] values = new object[members.Length];
        	int tupleKey = 0;
        	object oldTuple = null;

        	bool issueReferenceDirectives = !baseTupleAsReference && asReference;

        	if (issueReferenceDirectives)
			{
				tupleKey = (int)source.ReadUInt32();

				if (tupleKey > 0)
				{
					return source.NetCache.GetKeyedObject(tupleKey);
				}
				else
				{
					bool dummy;
					oldTuple = new object();

					tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy);
				}
			}

			bool invokeCtor = false;
			if (value == null)
			{
				invokeCtor = true;
			}
			for (int i = 0; i < values.Length; i++)
				values[i] = GetValue(value, i);

        	int j = 0;
			
        	int field;
			while (j++ < values.Length && source.ReadNextFieldHack() > 0)
			{
				field = source.ReadFieldHeader();

				invokeCtor = true;
                if(field <= tails.Length)
                {
                    IProtoSerializer tail = tails[field - 1];
                    values[field - 1] = tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source);
                }
                else
                {
                    source.SkipField();
                }
            }

        	object result = invokeCtor ? ctor.Invoke(values) : value;

			if (issueReferenceDirectives)
			{
				source.NetCache.UpdateKeyedObject(tupleKey, oldTuple, result);
			}

			if (forceIssueFakeHeader)
			{
				source.ReadEndGroupFieldHeaderHack();
			}

        	return result;
        }
Example #10
0
 public object Read(object value, ProtoReader source)
 {
     return source.ReadUInt32();
 }
Example #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);
        }
Example #12
0
 public object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(value == null); // since replaces
     return source.ReadUInt32();
 }
 object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
 {
     if (memberT == typeof(int))
     {
         return(reader.ReadInt32());
     }
     else if (memberT == typeof(uint))
     {
         return(reader.ReadUInt32());
     }
     else if (memberT == typeof(bool))
     {
         return(reader.ReadBoolean());
     }
     else if (memberT == typeof(byte))
     {
         return(reader.ReadByte());
     }
     else if (memberT == typeof(sbyte))
     {
         return(reader.ReadSByte());
     }
     else if (memberT == typeof(float))
     {
         return(reader.ReadSingle());
     }
     else if (memberT == typeof(double))
     {
         return(reader.ReadDouble());
     }
     else if (memberT == typeof(short))
     {
         return(reader.ReadInt16());
     }
     else if (memberT == typeof(ushort))
     {
         return(reader.ReadUInt16());
     }
     else if (memberT == typeof(long))
     {
         return(reader.ReadInt64());
     }
     else if (memberT == typeof(ulong))
     {
         return(reader.ReadUInt64());
     }
     else if (memberT == typeof(string))
     {
         return(reader.ReadString());
     }
     else if (memberT == typeof(byte[]))
     {
         return(ProtoReader.AppendBytes(null, reader));
     }
     else if (memberT == typeof(SInstance))
     {
         SubItemToken   st     = ProtoReader.StartSubItem(reader);
         CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
         if (!sClass.compiled)
         {
             RuntimeCompilerClass(sClassName);
         }
         CLS_Content       content = CLS_Content.NewContent(environment);
         CLS_Content.Value retVal  = sClass.function.New(content, m_emptyParams);
         CLS_Content.PoolContent(content);
         SInstance sInstance = (SInstance)retVal.value;
         ReadSInstance(reader, sInstance, environment);
         ProtoReader.EndSubItem(st, reader);
         return(sInstance);
     }
     else
     {
         throw new NotImplementedException("未实现类型: " + memberT);
     }
 }
 public object Read(ProtoReader source, ref ProtoReader.State state, object value)
 {
     Helpers.DebugAssert(value == null); // since replaces
     return(source.ReadUInt32(ref state));
 }