本文整理汇总了C#中SteamKit2.KeyValue.SaveToStream方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValue.SaveToStream方法的具体用法?C# KeyValue.SaveToStream怎么用?C# KeyValue.SaveToStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SteamKit2.KeyValue
的用法示例。
在下文中一共展示了KeyValue.SaveToStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 );
}
}
示例2: KeyValuesSavesTextToStream
public void KeyValuesSavesTextToStream()
{
var expected = "\"RootNode\"\n{\n\t\"key1\"\t\t\"value1\"\n\t\"key2\"\n\t{\n\t\t\"ChildKey\"\t\t\"ChildValue\"\n\t}\n}\n";
var kv = new KeyValue( "RootNode" )
{
Children =
{
new KeyValue( "key1", "value1" ),
new KeyValue( "key2" )
{
Children =
{
new KeyValue( "ChildKey", "ChildValue" )
}
}
}
};
string text;
using ( var ms = new MemoryStream() )
{
kv.SaveToStream( ms, asBinary: false );
ms.Seek( 0, SeekOrigin.Begin );
using ( var reader = new StreamReader( ms ) )
{
text = reader.ReadToEnd();
}
}
Assert.Equal( expected, text );
}
示例3: KeyValuesWritesBinaryToStream
public void KeyValuesWritesBinaryToStream()
{
var expectedHexValue = "00525000017374617475730023444F54415F52505F424F54505241435449434500016E756D5F706172616D730030000" +
"17761746368696E675F736572766572005B413A313A323130383933353136393A353431325D00017761746368696E675F66726F6D5F73" +
"6572766572005B413A313A3836343436383939343A353431325D000808";
var kv = new KeyValue( "RP" );
kv.Children.Add( new KeyValue( "status", "#DOTA_RP_BOTPRACTICE" ) );
kv.Children.Add( new KeyValue( "num_params", "0" ) );
kv.Children.Add( new KeyValue( "watching_server", "[A:1:2108935169:5412]" ) );
kv.Children.Add( new KeyValue( "watching_from_server", "[A:1:864468994:5412]" ) );
byte[] binaryValue;
using ( var ms = new MemoryStream() )
{
kv.SaveToStream( ms, asBinary: true );
binaryValue = ms.ToArray();
}
var hexValue = BitConverter.ToString( binaryValue ).Replace( "-", "" );
Assert.Equal( expectedHexValue, hexValue );
}