Skip to content

Commit e0f9916

Browse files
committed
EBML: Try to document the ebml_master_elements macro
1 parent 60b1fb7 commit e0f9916

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lofty/src/ebml/element_reader.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ pub(crate) struct ChildElementDescriptor {
5050
pub(crate) data_type: ElementDataType,
5151
}
5252

53+
// This macro helps us define the EBML master elements and their children.
54+
//
55+
// It will generate the `ElementIdent` enum, and the `master_elements` function.
56+
//
57+
// The `ElementIdent` enum is used to represent **ONLY** the elements that we care about.
58+
// When one of these elements is encountered, `ElementReader::next()` will return an
59+
// `ElementReaderYield::Master` or `ElementReaderYield::Child`. Otherwise, it will return
60+
// `ElementReaderYield::Unknown`.
61+
//
62+
// The `master_elements` function is used to map the element IDs to their respective
63+
// `MasterElement` struct, which contains the element's identifier and its children.
64+
// This is used to determine the children of a master element when it is encountered.
65+
//
66+
// If a master element is a child to another master element, it will be defined BOTH as a
67+
// child element in the parent master element, and as a top level master element.
68+
//
69+
// To define a master element, use the following syntax:
70+
//
71+
// ELEMENT_IDENT_VARIANT: {
72+
// id: 0x1234_5678,
73+
// children: [
74+
// CHILD_ELEMENT_VARIANT: { 0x1234_5679, DataType },
75+
// CHILD_ELEMENT_VARIANT2: { 0x1234_567A, DataType },
76+
// ],
77+
// },
78+
//
79+
// If `CHILD_ELEMENT_VARIANT2` is a master element, it should ALSO be defined at the top level with
80+
// its own children.
81+
//
82+
// Then when parsing, `ELEMENT_IDENT_VARIANT`, `CHILD_ELEMENT_VARIANT`, and `CHILD_ELEMENT_VARIANT2`
83+
// will be available as `ElementIdent` variants.
5384
ebml_master_elements! {
5485
EBML: {
5586
id: 0x1A45_DFA3,

0 commit comments

Comments
 (0)