项目作者: shravan2x

项目描述 :
A fast, easy-to-use Valve Data Format parser for .NET
高级语言: C#
项目地址: git://github.com/shravan2x/Gameloop.Vdf.git
创建时间: 2016-02-11T04:48:02Z
项目社区:https://github.com/shravan2x/Gameloop.Vdf

开源协议:MIT License

下载


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.

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

Documentation

To deserialize a file importantInfo.vdf,

  1. "Steam"
  2. {
  3. "SSAVersion" "3"
  4. "PrivacyPolicyVersion" "2"
  5. "SteamDefaultDialog" "#app_store"
  6. "DesktopShortcutCheck" "0"
  7. "StartMenuShortcutCheck" "0"
  8. }

do

  1. dynamic volvo = VdfConvert.Deserialize(File.ReadAllText("importantInfo.vdf"));
  2. // 'volvo' is a VProperty, analogous to Json.NET's JProperty
  3. // Now do whatever with this
  4. 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:

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

where SteamModel is something like

  1. class SteamModel
  2. {
  3. public int SSAVersion { get; set; } // Json.NET automatically converts strings to target types
  4. public int PrivacyPolicyVersion { get; set; }
  5. public string SteamDefaultDialog { get; set; }
  6. ...
  7. }

Extensions

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

License

Vdf.NET is released under the MIT license.