本文整理汇总了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;
}
}
示例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] );
}
}
示例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 );
}
}
}
示例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 );
}
示例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;
}
示例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;
}
}
示例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();
}