Skip to content

shravan2x/Gameloop.Vdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vdf.NET

NuGet AppVeyor

A fast, easy-to-use Valve Data Format parser for .NET

Getting Binaries

Vdf.NET is available as a NuGet package. Binaries can also be found on the releases page.

Performance

Vdf.NET was originally written as an experiment in deserialization performance. It is significantly faster than alternatives like SteamKit's KeyValue and even Json.NET (though I admit Json.NET is far more feature rich).

The test source file is VdfNetBenchmark.cs. I used version Vdf.NET 0.4.1 and the TF2 schema, which is available both in JSON and VDF formats (you'll need an API key to obtain them).

The following are the times taken for 10 iterations of deserializing the schema on an Intel i7-4790k processor.

Vdf.NET (VDF)	    : 129ms, 501871ticks average
Json.NET (JSON)	    : 270ms, 1022480ticks average
SK2 KeyValue (VDF)  : 340ms, 1255055ticks average

Documentation

To deserialize a file importantInfo.vdf,

"Steam"
{
	"SSAVersion"		"3"
	"PrivacyPolicyVersion"		"2"
	"SteamDefaultDialog"		"#app_store"
	"DesktopShortcutCheck"		"0"
	"StartMenuShortcutCheck"		"0"
}

do

dynamic volvo = VdfConvert.Deserialize(File.ReadAllText("importantInfo.vdf"));
// 'volvo' is a VProperty, analogous to Json.NET's JProperty

// Now do whatever with this
Console.WriteLine(volvo.Value.SSAVersion); // Prints 3

Note the need to use .Value and skip the enclosing property name Steam. This is because root types in VDF are properties, as opposed to objects in traditional JSON.

Deserialization using models

Vdf.NET does not natively support deserializing to models, but this can be achieved indirectly using the Gameloop.Vdf.JsonConverter extension such as:

VProperty volvo = VdfConvert.Deserialize(File.ReadAllText("importantInfo.vdf"));
SteamModel sm = volvo.ToJson().ToObject<SteamModel>();

where SteamModel is something like

class SteamModel
{
	public int SSAVersion { get; set; } // Json.NET automatically converts strings to target types
	public int PrivacyPolicyVersion { get; set; }
	public string SteamDefaultDialog { get; set; }
	...
}

Extensions

Gameloop.Vdf.JsonConverter: VDF-JSON converters for Vdf.NET.

License

Vdf.NET is released under the MIT license.

About

A fast, easy-to-use Valve Data Format parser for .NET

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages