WebAPI/VDF

From Team Fortress Wiki
< WebAPI
Revision as of 21:39, 12 December 2011 by Lagg (talk | contribs) (Probably needed)
Jump to: navigation, search


VDF is an ad-hoc file format designed by Valve to support storage of hierarchical data.

Basic layout

A basic VDF file will usually consist of a single root node containing the rest of the nodes within.

"someresource"
{
"foo" "bar" // Some comment
"odd" "record" [$ODD]
"someotherresource"
{
"baz" "tar"
}
}

In this example someresource will be the root node. Most of the time a given record will and can be indented by any whitespace including ' ' and '\t'. Most key names in a VDF file will be double quoted. However this is not always the case as seen in TF2's own files such as hudlayout.res.

C++-style commenting is supported as seen in the above example.

Notes

Valve's own documentation

It has 3 control characters '{', '}' and '"'. Names and values may be quoted or
not. The quote '"' charater must not be used within name or values, only for
quoting whole tokens. You may use escape sequences wile parsing and add within a
quoted token a \" to add quotes within your name or token. When using Escape
Sequence the parser must now that by setting KeyValues::UsesEscapeSequences( true ),
which it's off by default. Non-quoted tokens ends with a whitespace, '{', '}' and '"'.
So you may use '{' and '}' within quoted tokens, but not for non-quoted tokens.
An open bracket '{' after a key name indicates a list of subkeys which is finished
with a closing bracket '}'. Subkeys use the same definitions recursively.
Whitespaces are space, return, newline and tabulator. Allowed Escape sequences
are \n, \t, \\, \n and \". The number character '#' is used for macro purposes 
(eg #include), don't use it as first charater in key names.