---
name: "megaco_encoder"
section: "3erl"
platform: "linux"
package: "erlang-manpages"
version: "1:25.2.3+dfsg-1+deb12u4"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/megaco_encoder"
---

# megaco\_encoder(3erl)

Megaco encoder behaviour.

## NAME

megaco\_encoder - Megaco encoder behaviour.

## DESCRIPTION

The following functions should be exported from a *megaco\_encoder* callback module:

## DATA TYPES

**Note:**

Note that the actual definition of (some of) these records depend on the megaco protocol version used. For instance, the *'TransactionReply'* record has two more fields in version 3, so a simple erlang type definition cannot be made here.

```
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'{}
```

## EXPORTS

**Module:encode\_message(EncodingConfig, Version, Message) -\> {ok, Bin} \| Error**\

Types:

EncodingConfig = list()\
 Version = integer()\
 Message = megaco\_message()\
 Bin = binary()\
 Error = term()\

Encode a megaco message.

**Module:decode\_message(EncodingConfig, Version, Bin) -\> {ok, Message} \| Error**\

Types:

EncodingConfig = list()\
 Version = integer() \| dynamic\
 Message = megaco\_message()\
 Bin = binary()\
 Error = term()\

Decode a megaco message.

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.

**Module:decode\_mini\_message(EncodingConfig, Version, Bin) -\> {ok, Message} \| Error**\

Types:

EncodingConfig = list()\
 Version = integer() \| dynamic\
 Message = megaco\_message()\
 Bin = binary()\
 Error = term()\

Perform a minimal decode of a megaco message.

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.

**Module:encode\_transaction(EncodingConfig, Version, Transaction) -\> OK \| Error**\

Types:

EncodingConfig = list()\
 Version = integer()\
 Transaction = transaction()\
 OK = {ok, Bin}\
 Bin = binary()\
 Error = {error, Reason}\
 Reason = not\_implemented \| OtherReason\
 OtherReason = term()\

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!

**Module:encode\_action\_requests(EncodingConfig, Version, ARs) -\> OK \| Error**\

Types:

EncodingConfig = list()\
 Version = integer()\
 ARs = action\_requests()\
 action\_requests() = \[action\_request()\]\
 OK = {ok, Bin}\
 Bin = binary()\
 Error = {error, Reason}\
 Reason = not\_implemented \| OtherReason\
 OtherReason = term()\

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*.

**Module:encode\_action\_reply(EncodingConfig, Version, AR) -\> OK \| Error**\

Types:

EncodingConfig = list()\
 Version = integer()\
 AR = action\_reply()\
 OK = {ok, Bin}\
 Bin = binary()\
 Error = {error, Reason}\
 Reason = not\_implemented \| OtherReason\
 OtherReason = term()\

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!
