entry = trunk-definition
; Portable PIL structure. Unknown text-keyed annotations are preserved.
; Name/dictionary uniqueness, STRING-only dictionaries and @fields are semantic checks.
pil-definition = { pil-layout, pil-members, * tstr => any }
pil-layout = ((pil: 0, ? adaptive_integers: "none") //
              (pil: 1, adaptive_integers: "16" / "32"))
pil-members = (
  definition: tstr .size (1..4294967295),
  version: uint,
  fields: [+ pil-field]
)
pil-field = {
  name: tstr .size (1..4294967295),
  type: pil-scalar / pil-array,
  ? values: [* tstr],
  * tstr => any
}
pil-scalar = "BOOL" / "I8" / "I16" / "I32" / "I64"
           / "U8" / "U16" / "U32" / "U64" / "F32" / "F64"
           / "UUID" / "TIMESTAMP_MS" / "TIMESTAMP_US" / "TIMESTAMP_NS"
           / "REF16" / "STRING" / "BYTES" / "CBOR"
pil-array = "ARRAY<BOOL>" / "ARRAY<I8>" / "ARRAY<I16>" / "ARRAY<I32>" / "ARRAY<I64>"
          / "ARRAY<U8>" / "ARRAY<U16>" / "ARRAY<U32>" / "ARRAY<U64>"
          / "ARRAY<F32>" / "ARRAY<F64>" / "ARRAY<UUID>"
          / "ARRAY<TIMESTAMP_MS>" / "ARRAY<TIMESTAMP_US>" / "ARRAY<TIMESTAMP_NS>"
          / "ARRAY<REF16>" / "ARRAY<STRING>" / "ARRAY<BYTES>" / "ARRAY<CBOR>"
; Concatenate pill-packer/schemas/definition.cddl when validating this profile.
; Use trunk-definition as the entry rule. This binding is owned by Trie-Trunk.
trunk-definition = {
  pil-layout,
  pil-members,
  resource: trunk-resource,
  * tstr => any
}
trunk-resource = {
  format: 6,
  service: tstr,
  resource: tstr,
  major: 1..4095,
  minor: 0..1048575,
  timezone: tstr, ; validated IANA timezone name; storage uses UTC
  roles: {
    event_id: tstr,
    ? id: tstr,
    ? revision_id: tstr,
    ? duration: tstr,
    ? shared: tstr
  },
  ? path: [* tstr],
  ? aggregations: [* tstr],
  ? references: [* reference-translation]
}
reference-translation = {
  source_definition: tstr,
  field: tstr,
  values: {+ (0..65535) => (0..65535)}
}
