当前位置: 首页>>代码示例>>C#>>正文


C# Local.AfterDeserialize方法代码示例

本文整理汇总了C#中Local.AfterDeserialize方法的典型用法代码示例。如果您正苦于以下问题:C# Local.AfterDeserialize方法的具体用法?C# Local.AfterDeserialize怎么用?C# Local.AfterDeserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Local的用法示例。


在下文中一共展示了Local.AfterDeserialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeserializeLengthDelimited

        /// <summary>Read the VarInt length prefix and the given number of bytes from the stream and deserialze it into the instance.</summary>
        internal static Local.LocalFeatures DeserializeLengthDelimited(Stream stream, Local.LocalFeatures instance)
        {
            BinaryReader br = new BinaryReader(stream);
            instance.MyEnum = LocalFeatureTest.TopEnum.First;
            long limit = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt32(stream);
            limit += stream.Position;
            while (true)
            {
                if (stream.Position >= limit)
                {
                    if (stream.Position == limit)
                        break;
                    else
                        throw new InvalidOperationException("Read past max limit");
                }
                int keyByte = stream.ReadByte();
                if (keyByte == -1)
                    throw new System.IO.EndOfStreamException();
                // Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                    // Field 1 Varint
                    case 8:
                        instance.Uptime = new TimeSpan((long)(long)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream));
                        continue;
                    // Field 2 Varint
                    case 16:
                        instance.DueDate = new DateTime((long)(long)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream));
                        continue;
                    // Field 3 Fixed64
                    case 25:
                        instance.Amount = br.ReadDouble();
                        continue;
                    // Field 4 LengthDelimited
                    case 34:
                        instance.Denial = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 5 LengthDelimited
                    case 42:
                        instance.Secret = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 6 LengthDelimited
                    case 50:
                        instance.Internal = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 7 LengthDelimited
                    case 58:
                        instance.PR = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 8 LengthDelimited
                    case 66:
                        Mine.MyMessageV1.DeserializeLengthDelimited(stream, instance.TestingReadOnly);
                        continue;
                    // Field 9 LengthDelimited
                    case 74:
                        if (instance.MyInterface == null)
                            throw new InvalidOperationException("Can't deserialize into a interfaces null pointer");
                        else
                            LocalFeatureTest.InterfaceTestSerializer.DeserializeLengthDelimited(stream, instance.MyInterface);
                        continue;
                    // Field 10 LengthDelimited
                    case 82:
                        LocalFeatureTest.StructTest.DeserializeLengthDelimited(stream, ref instance.MyStruct);
                        continue;
                    // Field 11 LengthDelimited
                    case 90:
                        TestB.ExternalStructSerializer.DeserializeLengthDelimited(stream, ref instance.MyExtStruct);
                        continue;
                    // Field 12 LengthDelimited
                    case 98:
                        if (instance.MyExtClass == null)
                            instance.MyExtClass = TestB.ExternalClassSerializer.DeserializeLengthDelimited(stream);
                        else
                            TestB.ExternalClassSerializer.DeserializeLengthDelimited(stream, instance.MyExtClass);
                        continue;
                    // Field 13 Varint
                    case 104:
                        instance.MyEnum = (LocalFeatureTest.TopEnum)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream);
                        continue;
                }

                var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream);

                // Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                    case 0:
                        throw new InvalidDataException("Invalid field id: 0, something went wrong in the stream");
                    default:
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.SkipKey(stream, key);
                        break;
                }
            }

            instance.AfterDeserialize();
            return instance;
        }
开发者ID:4eJI0Be4ur,项目名称:ProtoBuf,代码行数:98,代码来源:Generated.Serializer.cs


注:本文中的Local.AfterDeserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。