megaco_encoder(3)

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

πŸ’– megaco_encoder(3) β€” the Erlang Module Definition, but make it make sense πŸ’–

okay bestie, sit DOWN, because this is megaco_encoder, the Megaco encoder behaviour. It's an Erlang module definition, and it's basically the vibe contract that your own encoder callback module has to slay at. No cap.

So here's the whole thing: the functions your megaco_encoder callback module is supposed to export. Let's get into it 🌸


✨ DATA TYPES (the vibes-first warning) ✨

⚠️ NOTE: the actual definition of (some of) these records depends on the megaco protocol version you're using. Like, for instance, the 'TransactionReply' record has two more fields in version 3, so a simple Erlang type definition just cannot be made here. Fr fr. It's giving "it depends".
protocol_version() = integer()
segment_no()       = integer()
megaco_message() = #'MegacoMessage{}'
transaction() = {transactionRequest,     transaction_request()}      |
                {transactionPending,     transaction_reply()}        |
                {transactionReply,       transaction_pending()}      |
                {transactionResponseAck, transaction_response_ack()} |
                {segmentReply,           segment_reply()}
transaction_request() = #'TransactionRequest'{}
transaction_pending() = #'TransactionPending'{}
transaction_reply() = #'TransactionReply'{}
transaction_response_ack() = [transaction_ack()]
transaction_ack() = #'TransactionAck'{}
segment_reply() = #'SegmentReply'{}
action_request() = #'ActionRequest'{}
action_reply() = #'ActionReply'{}
command_request() = #'CommandRequest'{}
error_desc()   = #'ErrorDescriptor'{}

🌈 DATA TYPES 🌈

Here's every single type, one by one, no skipping, iykyk 🫢

  • action_reply() :: {'ActionReply', _, _, _, _}.
  • action_request() :: {'ActionRequest', _, _, _, _}.
  • alpha() :: 65..90 | 97..122.

Alpha Numeric characters: A..Z | a..z

  • command_request() :: {'CommandRequest', _, _, _}.
  • deviceName() :: pathName().
  • digit() :: 48..57.

Decimal digits: 0..9

  • domainName() :: #'DomainName'{}.
  • error_desc() :: #'ErrorDescriptor'{}.
  • ip4Address() :: #'IP4Address'{}.
  • ip6Address() :: #'IP6Address'{}.
  • megaco_message() :: #'MegacoMessage'{}.
  • mtpAddress() :: octet_string().

There is no way to properly express this type in the Erlang type system, so this is the best we can do. 😭

A proper definition would be: -type mtpAddress() :: octet_string(2..4).

  • octet() :: 0..255.
  • octet_string() :: [octet()].
  • pathName() ::
[$* | alpha() | digit() | $_ | $/ | $$ | $@ | $- | $.].

There is no way to properly express this type in the Erlang type system, so this is the best we can do. The minimum length is 1 and the maximum length is 64. πŸ’…

Here is the ABNF (copied from the megaco standard) to fill in the blanks:

# Total length of pathNAME must not exceed 64 chars.

pathNAME = ["*"] NAME *("/" / "*"/ ALPHA / DIGIT /"_" / "$" )
["@" pathDomainName ]

# ABNF allows two or more consecutive "." although it is meaningless in a path domain name.

pathDomainName = (ALPHA / DIGIT / "*" ) *63(ALPHA / DIGIT / "-" /
"*" / ".")

NAME = ALPHA *63(ALPHA / DIGIT / "_" )
  • protocol_version() :: pos_integer().
  • segment_no() :: 0..65535.
  • segment_reply() :: #'SegmentReply'{}.
  • transaction() ::
{transactionRequest, transaction_request()} |
{transactionPending, transaction_reply()} |
{transactionReply, transaction_pending()} |
{transactionResponseAck, transaction_response_ack()} |
{segmentReply, segment_reply()}.
  • transaction_ack() :: #'TransactionAck'{}.
  • transaction_pending() :: #'TransactionPending'{}.
  • transaction_reply() ::
{'TransactionReply', _, _} | {'TransactionReply', _, _, _, _}.

The problem with TransactionReply is that its definition depend on which version of the protocol we are using. As of version 3, it has two more fields. πŸ™ˆ

  • transaction_request() :: #'TransactionRequest'{}.
  • transaction_response_ack() :: [transaction_ack()].

πŸŽ€ CALLBACKS πŸŽ€

These are the functions your callback module exports. Main character energy only πŸ‘‘


decode_message(EncodingConfig, Version, Bin)

Decode a megaco message. Decode-a. A message. That's the whole job bestie.

Note that if the Version argument is dynamic, the decoder should try to figure out the actual version from the message itself and then use the proper decoder, e.g. version 1. If on the other hand the Version argument is an integer, it means that this is the expected version of the message and the decoder for that version should be used. So like… dynamic = detective mode πŸ•΅οΈ, integer = "we already know, just decode it".


decode_mini_message(EncodingConfig, Version, Bin)

Perform a minimal decode of a megaco message. The mini version, the snack-sized one πŸ“.

The purpose of this function is to do a minimal decode of Megaco message. A successfull result is a 'MegacoMessage' in which only version and mid has been initiated. This function is used by the megaco_messenger module when the decode_message/3 function fails to figure out the mid (the actual sender) of the message.

Note again that a successfull decode only returns a partially initiated message. Like, it's a trailer, not the whole movie. Don't @ me.


encode_action_reply(EncodingConfig, Version, AR)

Encode a megaco action reply. If this, for whatever reason, is not supported, the function should return the error reason not_implemented.

This function is used when segmentation has been configured. So, for this to work, this function must be fully supported! Not optional, not negotiable, no half-sending it πŸ’€


encode_action_requests(EncodingConfig, Version, ARs)

Encode megaco action requests. This function is called when the user calls the function encode_actions/3. If that function is never used or if the codec cannot support this (the encoding of individual actions), then return with error reason not_implemented.


encode_message(EncodingConfig, Version, Message)

Encode a megaco message. That's it, that's the paragraph ✨


encode_transaction(EncodingConfig, Version, Transaction)

Encode a megaco transaction. If this, for whatever reason, is not supported, the function should return the error reason not_implemented.

This functionality is used both when the transaction sender is used and for segmentation. So, for either of those to work, this function must be fully supported! Same deal as before, bestie, this one is mandatory πŸ”₯


πŸ’Œ cute lil sign-off: this whole page is brought to you by Ericsson AB, from megaco 4.9.2, and it's the manual for megaco_encoder(3). Go forth and encode responsibly, mwah πŸ’…πŸ’–
πŸ“¦ where this page comes from