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


C# KeyValue.ReadAsBinary方法代码示例

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


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

示例1: Package

                internal Package( CMsgClientPackageInfoResponse.Package pack, Package.PackageStatus status )
                {
                    Status = status;

                    PackageID = pack.package_id;
                    ChangeNumber = pack.change_number;
                    Hash = pack.sha;

                    Data = new KeyValue();

                    using ( var ms = new MemoryStream( pack.buffer ) )
                    using ( var br = new BinaryReader( ms ) )
                    {
                        br.ReadUInt32(); // unknown uint at the beginning of the buffer
                        Data.ReadAsBinary( ms );
                    }

                    if ( Data.Children != null )
                    {
                        Data = Data.Children.FirstOrDefault() ?? KeyValue.Invalid;
                    }
                }
开发者ID:Nightgunner5,项目名称:steamkit-go,代码行数:22,代码来源:Callbacks.cs

示例2: GuestPassListCallback

            internal GuestPassListCallback( MsgClientUpdateGuestPassesList msg, Stream payload )
#endif
            {
                Result = msg.Result;
                CountGuestPassesToGive = msg.CountGuestPassesToGive;
                CountGuestPassesToRedeem = msg.CountGuestPassesToRedeem;

                GuestPasses = new List<KeyValue>();
                for ( int i = 0; i < CountGuestPassesToGive + CountGuestPassesToRedeem; i++ )
                {
                    var kv = new KeyValue();
                    kv.ReadAsBinary( payload );
                    GuestPasses.Add( kv.Children[0] );
                }
            }
开发者ID:Nightgunner5,项目名称:steamkit-go,代码行数:15,代码来源:Callbacks.cs

示例3: App

                internal App( CMsgClientAppInfoResponse.App app, AppInfoStatus status )
                {
                    Status = status;
                    AppID = app.app_id;
                    ChangeNumber = app.change_number;
                    Sections = new Dictionary<EAppInfoSection, KeyValue>();

                    foreach ( var section in app.sections )
                    {
                        KeyValue kv = new KeyValue();

                        using ( MemoryStream ms = new MemoryStream( section.section_kv ) )
                            kv.ReadAsBinary( ms );

                        if ( kv.Children != null )
                        {
                            Sections.Add( ( EAppInfoSection )section.section_id, kv.Children.FirstOrDefault() ?? KeyValue.Invalid );
                        }
                    }
                }
开发者ID:Nightgunner5,项目名称:steamkit-go,代码行数:20,代码来源:Callbacks.cs

示例4: KeyValuesReadsBinary_ReadAsBinary_PreservesBuggyBehavior

        public void KeyValuesReadsBinary_ReadAsBinary_PreservesBuggyBehavior()
        {
            var binary = Utils.DecodeHexString( TestObjectHex );
            var kv = new KeyValue();
            bool success;
            using ( var ms = new MemoryStream( binary ) )
            {
                success = kv.ReadAsBinary( ms );
                Assert.Equal( ms.Length, ms.Position );
            }

            Assert.True( success, "Should have read test object." );
            Assert.Null( kv.Name );
            Assert.Equal( 1, kv.Children.Count );

            var actualKv = kv.Children[ 0 ];
            Assert.Equal( "TestObject", actualKv.Name );
            Assert.Equal( 1, actualKv.Children.Count );
            Assert.Equal( "key", actualKv.Children[0].Name );
            Assert.Equal( "value", actualKv.Children[0].Value );
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:21,代码来源:KeyValueFacts.cs

示例5: ReadAsBinary

        /// <summary>
        /// Populate this instance from the given <see cref="Stream"/> as a binary <see cref="KeyValue"/>.
        /// </summary>
        /// <param name="input">The input <see cref="Stream"/> to read from.</param>
        /// <returns><c>true</c> if the read was successful; otherwise, <c>false</c>.</returns>
        public bool ReadAsBinary( Stream input )
        {
            this.Children = new List<KeyValue>();

            while ( true )
            {

                var type = ( Type )input.ReadByte();

                if ( type == Type.End )
                {
                    break;
                }

                var current = new KeyValue();
                current.Name = input.ReadNullTermString( Encoding.UTF8 );

                try
                {
                    switch ( type )
                    {
                        case Type.None:
                            {
                                current.ReadAsBinary( input );
                                break;
                            }

                        case Type.String:
                            {
                                current.Value = input.ReadNullTermString( Encoding.UTF8 );
                                break;
                            }

                        case Type.WideString:
                            {
                                throw new InvalidDataException( "wstring is unsupported" );
                            }

                        case Type.Int32:
                        case Type.Color:
                        case Type.Pointer:
                            {
                                current.Value = Convert.ToString( input.ReadInt32() );
                                break;
                            }

                        case Type.UInt64:
                            {
                                current.Value = Convert.ToString( input.ReadUInt64() );
                                break;
                            }

                        case Type.Float32:
                            {
                                current.Value = Convert.ToString( input.ReadFloat() );
                                break;
                            }

                        default:
                            {
                                throw new InvalidDataException( "Unknown KV type encountered." );
                            }
                    }
                }
                catch ( InvalidDataException ex )
                {
                    throw new InvalidDataException( string.Format( "An exception ocurred while reading KV '{0}'", current.Name ), ex );
                }

                this.Children.Add( current );
            }

            return input.Position == input.Length;
        }
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:79,代码来源:KeyValue.cs

示例6: LoadFromFile

        static KeyValue LoadFromFile( string path, bool asBinary )
        {
            if ( File.Exists( path ) == false )
            {
                return null;
            }

            try
            {
                using ( var input = File.Open( path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ) )
                {
                    var kv = new KeyValue();

                    if ( asBinary )
                    {
                        if ( kv.ReadAsBinary( input ) == false )
                        {
                            return null;
                        }
                    }
                    else
                    {
                        if ( kv.ReadAsText( input ) == false )
                        {
                            return null;
                        }
                    }

                    return kv;
                }
            }
            catch ( Exception )
            {
                return null;
            }
        }
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:36,代码来源:KeyValue.cs

示例7: DisplayDataAsBinaryKeyValues

		void DisplayDataAsBinaryKeyValues(object sender, EventArgs e)
		{
			SetAsRadioSelected(sender);

			var data = (byte[])value;
			var kv = new KeyValue();
			bool didRead;
			using (var ms = new MemoryStream(data))
			{
				try
				{
					didRead = kv.ReadAsBinary(ms);
				}
				catch (InvalidDataException)
				{
					didRead = false;
				}
			}

			if (!didRead)
			{
				SetValueForDisplay("Not a valid KeyValues object!");
			}
			else
			{
				var firstChild = kv.Children[0]; // Due to bug in KeyValues parser.
				SetValueForDisplay(null, childNodes: new[] { new TreeNodeObjectExplorer(firstChild.Name, firstChild).TreeNode });
			}

			TreeNode.ExpandAll();
		}
开发者ID:ChronosWS,项目名称:SteamKit,代码行数:31,代码来源:TreeNodeObjectExplorer.cs


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