diameter_codec(3)
π NAME π
okay so bestie, welcome to diameter_codec, a page straight out of the Erlang Module Definition collection β¨ and it does exactly one thing: Decode and encode of Diameter messages. that's it, that's the girl. π
πΈ DESCRIPTION πΈ
so here's the tea, fr fr: incoming Diameter messages get decoded from binary() before they're ever communicated to your diameter_app callbacks. and on the flip side, outgoing Diameter messages get encoded into binary() before being passed to the appropriate diameter_transport module for transmission. the functions documented right here are the ones implementing the default encode/decode. slay. β¨
β οΈ WARNING bestie, listen closely: the diameter user does not need to call functions here explicitly when sending and receiving messages usingdiameter:call/4and the callback interface documented indiameter_app. diameter itself provides encode/decode as a consequence of configuration passed todiameter:start_service/2, and the results may differ from those returned by the functions documented here, depending on configuration. so don't be out here hand-rolling calls and then acting shocked at the output π
The header() and packet() records below are defined in diameter.hrl, which can be included as follows. π«Ά
-include_lib("diameter/include/diameter.hrl").
Application-specific records are defined in the hrl files resulting from dictionary file compilation. no cap. π
π¦ DATA TYPES π¦
uint8()=0..255uint24()=0..16777215uint32()=0..4294967295
these three cuties are the 8-bit, 24-bit and 32-bit integers occurring in Diameter and AVP headers. π
avp()=#diameter_avp{}β the application-neutral representation of an AVP. Primarily intended for use by relay applications that need to handle arbitrary Diameter applications. a service implementing a specific Diameter application (for which it configures a dictionary) can manipulate values of typemessage()instead. bestie, this one has fields, and here's what they're giving:code=uint32()is_mandatory=boolean()need_encryption=boolean()vendor_id=uint32() | undefinedβ these are the values in the AVP header, corresponding to AVP Code, the M flag, P flags and Vendor-ID respectively. a Vendor-ID other thanundefinedimplies a set V flag. βdata=iolist()β the data bytes of the AVP.name=atom()β the name of the AVP as defined in the dictionary file in question, orundefinedif the AVP is unknown to the dictionary file in question.value=term()β the decoded value of an AVP. will beundefinedon decode if the data bytes could not be decoded, the AVP is unknown, or if the decode format isnone. the type of a decoded value is as document indiameter_dict(4). πtype=atom()β the type of the AVP as specified in the dictionary file in question (or one it inherits). possible types areundefinedand the Diameter types:OctetString,Integer32,Integer64,Unsigned32,Unsigned64,Float32,Float64,Grouped,Enumerated,Address,Time,UTF8String,DiameterIdentity,DiameterURI,IPFilterRuleandQoSFilterRule. the range is ranging, literally. π
dictionary()=module()β the name of a generated dictionary module as generated bydiameterc(1)ordiameter_make:codec/2. the interface provided by a dictionary module is an implementation detail that may change. iykyk. πheader()=#diameter_header{}β the record representation of the Diameter header. Values in apacket()returned bydecode/2are as extracted from the incoming message. Values set in anpacket()passed toencode/2are preserved in the encodedbinary(), with the exception oflength,cmd_codeandapplication_id, all of which are determined by thedictionary()in question.
π NOTE: it is not necessary to set header fields explicitly in outgoing messages as diameter itself will set appropriate values. Setting inappropriate values can be useful for test purposes. (chaotic. love that for you. π)
the fields, and their types:
version=uint8()length=uint24()cmd_code=uint24()application_id=uint32()hop_by_hop_id=uint32()end_to_end_id=uint32()β these are the Values of the Version, Message Length, Command-Code, Application-ID, Hop-by-Hop Identifier and End-to-End Identifier fields of the Diameter header. πis_request=boolean()is_proxiable=boolean()is_error=boolean()is_retransmitted=boolean()β Values corresponding to the R(equest), P(roxiable), E(rror) and T(Potentially re-transmitted message) flags of the Diameter header. β¨
message()=record() | maybe_improper_list()β the representation of a Diameter message as passed todiameter:call/4or returned from ahandle_request/3callback. the record representation is as outlined indiameter_dict(4): a message as defined in a dictionary file is encoded as a record with one field for each component AVP. Equivalently, a message can also be encoded as a list whose head is the atom-valued message name (as specified in the relevant dictionary file) and whose tail is either a list of AVP name/values pairs or a map with values keyed on AVP names. the format at decode is determined bydiameter:service_opt()decode_format. any of the formats is accepted at encode. π¦
Another list-valued representation allows a message to be specified as a list whose head is a header() and whose tail is an avp() list. this representation is used by diameter itself when relaying requests as directed by the return value of a handle_request/3 callback. it differs from the other two in that it bypasses the checks for messages that do not agree with their definitions in the dictionary in question: messages are sent exactly as specified. main character energy, zero notes. π
packet()=#diameter_packet{}β a container for incoming and outgoing Diameter messages. the fields have the following types:header=header() | undefinedβ the Diameter header of the message. Can be (and typically should be)undefinedfor an outgoing message in a non-relay application, in which case diameter provides appropriate values.avps=[avp()] | undefinedβ the AVPs of the message. Ignored for an outgoing message if themsgfield is set to a value other thanundefined.msg=message() | undefinedβ the incoming/outgoing message. For an incoming message, a term corresponding to the configured decode format if the message can be decoded in a non-relay application,undefinedotherwise. For an outgoing message, setting a[header()|avp()]list is equivalent to setting theheaderandavpsfields to the corresponding values.
β οΈ WARNING: a value in themsgfield does not imply an absence of decode errors. theerrorsfield should also be examined. don't skip the vibe check on that one bestie π
bin=binary()β the incoming message prior to encode or the outgoing message after encode.errors=[5000..5999 | {5000..5999, avp()}]β Errors detected at decode of an incoming message, as identified by a corresponding 5xxx series Result-Code (Permanent Failures). For an incoming request, these should be used to formulate an appropriate answer as documented for thehandle_request/3callback indiameter_app. For an incoming answer, thediameter:application_opt()answer_errorsdetermines the behaviour.transport_data=term()β an arbitrary term of meaning only to the transport process in question, as documented indiameter_transport. π
π SEE ALSO π
diameterc(1)diameter_appdiameter_dict(4)diameter_make
go read those too, bestie, they're all linked in the group chat π«Ά
π DATA TYPES π (the encore)
yes she's back, she's the same girl, she just wanted a second moment π
dictionary()::module().
the name of a generated dictionary module as generated by diameterc(1) or diameter_make:codec/2. the interface provided by a dictionary module is an implementation detail that may change. β
message()::record() | maybe_improper_list().
the representation of a Diameter message as passed to diameter:call/4 or returned from a handle_request/3 callback. πΈ
packet()::#diameter_packet{}.
a container for incoming and outgoing Diameter messages. π
π₯ FUNCTIONS π₯
decode(Mod, Bin) -> Pkt
decode(Mod, Bin) -> Pkt
when
Mod :: dictionary(),
Bin :: binary(),
Pkt :: packet().
Decode a Diameter message. that's it, that's the job. decode and thrive. β¨
encode(Mod, Msg) -> Pkt
encode(Mod, Msg) -> Pkt
when
Mod :: dictionary(),
Msg :: message() | packet(),
Pkt :: packet().
Encode a Diameter message. the remix. the return. π₯
okay that's the whole page bestie, you ate this π
this was brought to you by Ericsson AB, rockin' diameter 2.7.2, and it's diameter_codec(3), dated and everything β so go forth, decode, encode, and be iconic. periodt. πππ¦
π¦ where this page comes from
- nixos 26.05: erlang 29.1.2
- nixpkgs unstable: erlang 29.1.2
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms