Skip to content

Class XmlBinary

Namespace: Apogee.Content.Xml
Assembly: Apogee.Content.dll

A binary encoding of an XML document, for cooked packs (APXB): the tree holds, with every name and value in one string table and the nodes in document order. It is smaller than the text and read without parsing it, and it gives back exactly the tree that was written: names, attributes in their order, text, lines and children. Read a file that may be either form through .

public static class XmlBinary

Inheritance

object ← XmlBinary

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

Little-endian; a varint is an unsigned LEB128 of at most 32 bits.

header   u32 magic "APXB" (0x42585041) · u16 version · u16 flags (0) · u32 string count · u32 node count
strings  count x { varint byte length, UTF-8 bytes }    first-appearance order, string 0 is ""
nodes    pre-order, root first: varint name, varint line, varint attribute count,
         attributes x { varint name, varint value }, varint text, varint child count

The reader checks every count against the bytes that are left before it allocates for it, so a damaged or hostile file can only make it throw a , or allocate in proportion to the file's own size. is not stored; the reader sets it to the path it was given.

Fields

Version

The version of the encoding that produces and the newest accepts.

public const int Version = 1

Field Value

int

Methods

IsBinary(ReadOnlySpan<byte>)

Whether the bytes start with the magic of a cooked XML file (a text XML file cannot: it begins with <, a byte order mark or white space).

public static bool IsBinary(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

Returns

bool

Read(ReadOnlySpan<byte>, string)

The tree encoded in bytes.

public static XmlNode Read(ReadOnlySpan<byte> bytes, string origin)

Parameters

bytes ReadOnlySpan<byte>

A cooked XML file.

origin string

The path to name in errors, and what becomes on every element.

Returns

XmlNode

Exceptions

ContentException

The bytes are not a cooked XML file this engine can read: foreign, cooked by a newer engine, cut short or damaged.

Write(XmlNode)

The encoding of the tree. The same tree always gives the same bytes.

public static byte[] Write(XmlNode root)

Parameters

root XmlNode

Returns

byte[]

Exceptions

ContentException

The tree nests deeper than the text parser allows (), has an element or attribute with no name, a negative line, or text that is not valid Unicode.