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


C# KeyValue.TryReadAsBinary方法代码示例

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


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

示例1: GuestPassListCallback

            internal GuestPassListCallback( MsgClientUpdateGuestPassesList msg, Stream payload )
            {
                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.TryReadAsBinary( payload );
                    GuestPasses.Add( kv );
                }
            }
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:14,代码来源:Callbacks.cs

示例2: 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 ) )
                        {
                            if ( kv.TryReadAsBinary( ms ) )
                            {
                                Sections.Add( ( EAppInfoSection )section.section_id, kv );
                            }
                        }
                    }
                }
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:20,代码来源:Callbacks.cs

示例3: 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 ) )
                    {
                        // steamclient checks this value == 1 before it attempts to read the KV from the buffer
                        // see: CPackageInfo::UpdateFromBuffer(CSHA const&,uint,CUtlBuffer &)
                        // todo: we've apparently ignored this with zero ill effects, but perhaps we want to respect it?
                        br.ReadUInt32();
                        
                        Data.TryReadAsBinary( ms );
                    }
                }
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:21,代码来源:Callbacks.cs

示例4: KeyValuesReadsBinaryWithMultipleChildren

        public void KeyValuesReadsBinaryWithMultipleChildren()
        {
            var hex = "00546573744f626a65637400016b6579310076616c75653100016b6579320076616c756532000808";
            var binary = Utils.DecodeHexString( hex );
            var kv = new KeyValue();
            bool success;
            using ( var ms = new MemoryStream( binary ) )
            {
                success = kv.TryReadAsBinary( ms );
            }

            Assert.True( success );
            
            Assert.Equal( "TestObject", kv.Name );
            Assert.Equal( 2, kv.Children.Count );
            Assert.Equal( "key1", kv.Children[ 0 ].Name );
            Assert.Equal( "value1", kv.Children[ 0 ].Value );
            Assert.Equal( "key2", kv.Children[ 1 ].Name );
            Assert.Equal( "value2", kv.Children[ 1 ].Value );
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:20,代码来源:KeyValueFacts.cs

示例5: PurchaseResponseCallback

			internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
				if ((jobID == null) || (msg == null)) {
					throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
				}

				JobID = jobID;
				PurchaseResult = (EPurchaseResult) msg.purchase_result_details;

				if (msg.purchase_receipt_info == null) {
					return;
				}

				KeyValue receiptInfo = new KeyValue();
				using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
					if (!receiptInfo.TryReadAsBinary(ms)) {
						Logging.LogNullError(nameof(ms));
						return;
					}
				}

				List<KeyValue> lineItems = receiptInfo["lineitems"].Children;
				if (lineItems.Count == 0) {
					return;
				}

				Items = new Dictionary<uint, string>(lineItems.Count);
				foreach (KeyValue lineItem in lineItems) {
					uint packageID = lineItem["PackageID"].AsUnsignedInteger();
					if (packageID == 0) {
						// Valid, coupons have PackageID of -1 (don't ask me why)
						packageID = lineItem["ItemAppID"].AsUnsignedInteger();
						if (packageID == 0) {
							Logging.LogNullError(nameof(packageID));
							return;
						}
					}

					string gameName = lineItem["ItemDescription"].Value;
					if (string.IsNullOrEmpty(gameName)) {
						Logging.LogNullError(nameof(gameName));
						return;
					}

					gameName = WebUtility.HtmlDecode(gameName); // Apparently steam expects client to decode sent HTML
					Items[packageID] = WebUtility.HtmlDecode(gameName);
				}
			}
开发者ID:Kasp42,项目名称:ArchiSteamFarm,代码行数:47,代码来源:ArchiHandler.cs

示例6: KeyValuesReadsBinaryWithLeftoverData

        public void KeyValuesReadsBinaryWithLeftoverData()
        {
            var binary = Utils.DecodeHexString( TestObjectHex + Guid.NewGuid().ToString().Replace("-", "") );
            var kv = new KeyValue();
            bool success;
            using ( var ms = new MemoryStream( binary ) )
            {
                success = kv.TryReadAsBinary( ms );
                Assert.Equal( TestObjectHex.Length / 2, ms.Position );
                Assert.Equal( 16, ms.Length - ms.Position );
            }

            Assert.True( success, "Should have read test object." );
            Assert.Equal( "TestObject", kv.Name );
            Assert.Equal( 1, kv.Children.Count );
            Assert.Equal( "key", kv.Children[0].Name );
            Assert.Equal( "value", kv.Children[0].Value );
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:18,代码来源:KeyValueFacts.cs

示例7: KeyValuesFailsToReadTruncatedBinary

        public void KeyValuesFailsToReadTruncatedBinary()
        {
            // Test every possible truncation boundary we have.
            for ( int i = 0; i < TestObjectHex.Length; i += 2 )
            {
                var binary = Utils.DecodeHexString( TestObjectHex.Substring( 0, i ) );
                var kv = new KeyValue();
                bool success;
                using ( var ms = new MemoryStream( binary ) )
                {
                    success = kv.TryReadAsBinary( ms );
                    Assert.Equal( ms.Length, ms.Position );
                }

                Assert.False( success, "Should not have read test object." );
            }
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:17,代码来源:KeyValueFacts.cs

示例8: KeyValues_TryReadAsBinary_ReadsBinary

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

            Assert.True( success, "Should have read test object." );
            Assert.Equal( "TestObject", kv.Name );
            Assert.Equal( 1, kv.Children.Count );
            Assert.Equal( "key", kv.Children[0].Name );
            Assert.Equal( "value", kv.Children[0].Value );
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:17,代码来源:KeyValueFacts.cs

示例9: PurchaseResponseCallback

			internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
				JobID = jobID;

				if (msg == null) {
					return;
				}

				Result = (EResult) msg.eresult;
				PurchaseResult = (EPurchaseResult) msg.purchase_result_details;

				if (msg.purchase_receipt_info == null) {
					return;
				}

				ReceiptInfo = new KeyValue();
				using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
					if (!ReceiptInfo.TryReadAsBinary(ms)) {
						return;
					}

					List<KeyValue> lineItems = ReceiptInfo["lineitems"].Children;
					Items = new Dictionary<uint, string>(lineItems.Count);

					foreach (KeyValue lineItem in lineItems) {
						uint appID = (uint) lineItem["PackageID"].AsUnsignedLong();
						string gameName = lineItem["ItemDescription"].AsString();
						gameName = WebUtility.UrlDecode(gameName); // Apparently steam expects client to decode sent HTML
						Items.Add(appID, gameName);
					}
				}
			}
开发者ID:Ryzhehvost,项目名称:ArchiSteamFarm,代码行数:31,代码来源:ArchiHandler.cs

示例10: 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))
			{
				didRead = kv.TryReadAsBinary(ms);
			}

			if (!didRead)
			{
				SetValueForDisplay("Not a valid KeyValues object!");
			}
			else
			{
				SetValueForDisplay(null, childNodes: new[] { new TreeNodeObjectExplorer(kv.Name, kv).TreeNode });
			}

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

示例11: KeyValueBinarySerializationIsSymmetric

        public void KeyValueBinarySerializationIsSymmetric()
        {
            var kv = new KeyValue( "MessageObject" );
            kv.Children.Add( new KeyValue( "key", "value" ) );

            var deserializedKv = new KeyValue();
            bool loaded;

            using ( var ms = new MemoryStream() )
            {
                kv.SaveToStream( ms, asBinary: true );
                ms.Seek( 0, SeekOrigin.Begin );
                loaded = deserializedKv.TryReadAsBinary( ms );
            }

            Assert.True( loaded );

            Assert.Equal( kv.Name, deserializedKv.Name );
            Assert.Equal( kv.Children.Count, deserializedKv.Children.Count );

            for ( int i = 0; i < kv.Children.Count; i++ )
            {
                var originalChild = kv.Children[ i ];
                var deserializedChild = deserializedKv.Children[ i ];
                
                Assert.Equal( originalChild.Name, deserializedChild.Name );
                Assert.Equal( originalChild.Value, deserializedChild.Value );
            }
        }
开发者ID:logtcn,项目名称:SteamKit,代码行数:29,代码来源:KeyValueFacts.cs

示例12: PurchaseResponseCallback

			internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
				JobID = jobID;

				if (msg == null) {
					return;
				}

				ReceiptInfo = new KeyValue();
				Items = new Dictionary<uint, string>();

				Result = (EResult) msg.eresult;
				PurchaseResult = (EPurchaseResult) msg.purchase_result_details;

				using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
					if (!ReceiptInfo.TryReadAsBinary(ms)) {
						return;
					}

					foreach (KeyValue lineItem in ReceiptInfo["lineitems"].Children) {
						Items.Add((uint) lineItem["PackageID"].AsUnsignedLong(), lineItem["ItemDescription"].AsString());
					}
				}
			}
开发者ID:stregkoden,项目名称:ArchiSteamFarm,代码行数:23,代码来源:ArchiHandler.cs


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