diameter_make(3)

πŸ“¦
version 29.0.6 Β· 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu stonking

πŸ’– diameter_make(3) πŸ’–

okay bestie, this is an Erlang Module Definition β€” the Diameter dictionary compilation one. buckle up, it's actually iconic πŸŽ€


✨ NAME ✨

diameter_make β€” Diameter dictionary compilation, fr fr πŸ¦‹

🌸 DESCRIPTION 🌸

so codec/2 is the function that takes a diameter dictionary file and compiles it into Erlang source. and like, that resulting source? it implements the interface diameter needs to encode and decode the dictionary's messages and AVPs. no cap, that's the whole job πŸ’…

also there's a utility called diameterc(1) which gives you an alternate compilation interface, if that's more your vibe.

πŸ’€ BUGS πŸ’€

Unrecognized options are silently ignored. literally they just ghost you. πŸ™ˆ

πŸ‘€ SEE ALSO πŸ‘€


🌈 DATA TYPES 🌈

dict() :: iolist() | binary() | parsed().

opt() ::
          {include | outdir | name | prefix | inherits, string()} |
          return | verbose | parse | forms | erl | hrl.

parsed() :: list().

like yes, parsed() is just a list. it's giving simplicity. it's giving ate. πŸ‘‘


πŸ”₯ FUNCTIONS πŸ”₯

⭐ codec(File, [opt()]) -> ok | {ok, list()} | {error, Reason}

when
    File :: dict() | {path, file:name_all()},
    Reason :: string().

Compile a single dictionary file. one file. that's it. slay ✨

The input File can be either a path or a literal dictionary β€” and the way you tell them apart? the occurrence of newline (ascii NL) or carriage return (ascii CR) is what identifies the literal dictionary one. sneaky but valid πŸ’…

Opt determines the format of the results and whether they get written to file or returned to you, and it can have the following types:

  • parse | forms | erl | hrl β€” Specifies an output format. Whether the output is returned or written to file depends on whether or not option return is specified. When written to file, the resulting file(s) will have extensions .D, .F, .erl, and .hrl respectively, basenames defaulting to dictionary if the input dictionary is literal and does not specify @name. When returned, results are in the order of the corresponding format options. Format options default to erl and hrl (in this order) if unspecified.
    • The parse format is an internal representation that can be passed to flatten/1 and format/1, while the forms format can be passed to compile:forms/2. The erl and hrl formats are returned as iolists. 🫢
  • {include, string()} β€” Prepend the specified directory to the code path. Use this to point at beam files compiled from inherited dictionaries β€” @inherits in a dictionary file creates a beam dependency, not an erl/hrl dependency. lowkey important.
    • Multiple include options can be specified. stack 'em up 🧚
  • {outdir, string()} β€” Write generated source to the specified directory. Defaults to the current working directory. Has no effect if option return is specified. (like, why would it, bestie)
  • return β€” Return results in a {ok, [Out]} tuple instead of writing to file and returning ok. the "hand it to me directly" option πŸ’–
  • {name|prefix, string()} β€” Transform the input dictionary before compilation, setting @name or @prefix to the specified string.
  • {inherits, string()} β€” Transform the input dictionary before compilation, appending @inherits of the specified string.
    • Two forms have special meaning:
{inherits, "-"}
{inherits, "Prev/Mod"}
  • The first has the effect of clearing any previous inherits, the second of replacing a previous inherits of Prev to one of Mod. This allows the semantics of the input dictionary to be changed without modifying the file itself. iconic behavior tbh 🌸
  • Multiple inherits options can be specified.
  • indirect_inherits β€” This option makes compiler support automatic recursive inheritance. When a dictionary file inherits another .dia, all ancestors of that .dia will also be considered in code generation. This enhancement removes the requirement to explicitly list all parent dictionaries via @inherits, preventing missing AVP/message encodings and runtime errors. πŸ”₯
    • Example: C.dia inherits B.dia and B.dia inherits A.dia.
    • Before (without indirect_inherits): If C.dia references AVPs from A.dia without directly inheriting it, the generated code will lack necessary definitions, causing encoding failures. πŸ’€
    • After (with indirect_inherits): C.dia can reference AVPs from A.dia without directly inheriting it, compiler will resolve the entire inheritance chain automatically, ensuring all relevant descendant definitions from A.dia are available without additional user declarations. periodt. πŸ‘‘
Note that a dictionary's @name, together with the outdir option, determine the output paths when the return option is not specified. The @name of a literal input dictionary defaults to dictionary.

A returned error reason can be converted into a readable string using format_error/1. πŸ™


πŸ¦‹ flatten(parsed()) -> parsed().

Reconstitute a parsed dictionary, as returned by codec/2, without using @inherits. That is, construct an equivalent dictionary in which all AVP's are definined in the dictionary itself. The return value is also a parsed dictionary. (yes bestie, "definined" β€” that's the original spelling, I don't make the rules πŸ’…)


✨ format(parsed()) -> iolist().

Turns a parsed dictionary, as returned by codec/2, back into the dictionary format. it's giving reverse uno card 🌈


πŸ’œ format_error(Reason) -> FormattedReason

when Reason :: term(), FormattedReason :: string().

Turn an error reason returned by codec/2 into a readable string. because raw error terms are not the vibe check you want at 3am 😭


πŸ₯Ί okay that's the whole page, you made it, I'm so proud of you bestie. this was Ericsson AB's work, from diameter 2.7.2, and it's been sitting there being iconic since forever β€” go compile something cute πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from