📄 megaco_compact_text_encoder_v1.erl
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%%----------------------------------------------------------------------%% Purpose: Encode COMPACT Megaco/H.248 text messages from internal form%%-----------------------------------------------------------------------module(megaco_compact_text_encoder_v1).-export([encode_message/2, encode_transaction/2, encode_action_requests/2, encode_action_request/2, encode_command_request/2, encode_action_reply/2]).-export([token_tag2string/1]).-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-define(encoder_version_pre_prev3c,true).-include("megaco_text_tokens.hrl").%%----------------------------------------------------------------------%% Convert a 'MegacoMessage' record into a binary%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_message(EC, MegaMsg) when is_list(EC) and is_record(MegaMsg, 'MegacoMessage') -> case (catch enc_MegacoMessage(MegaMsg)) of {'EXIT', Reason} -> {error, Reason}; Bin when binary(Bin) -> {ok, Bin}; DeepIoList -> Bin = erlang:list_to_binary(DeepIoList), {ok, Bin} end;encode_message(EncodingConfig, MegaMsg) when is_record(MegaMsg, 'MegacoMessage') -> {error, {bad_encoding_config, EncodingConfig}};encode_message(_EncodingConfig, _MegaMsg) -> {error, bad_megaco_message}.%%----------------------------------------------------------------------%% Convert a transaction record into a deep io list%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_transaction(_EC, Trans) -> case (catch enc_Transaction(Trans)) of {'EXIT', Reason} -> {error, Reason}; Bin when binary(Bin) -> {ok, Bin}; DeepIoList -> Bin = erlang:list_to_binary(DeepIoList), {ok, Bin} end.%%----------------------------------------------------------------------%% Convert a list of ActionRequest record's into a binary%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_action_requests(_EC, ActReqs) -> case (catch enc_ActionRequests(ActReqs)) of {'EXIT', Reason} -> {error, Reason}; Bin when binary(Bin) -> {ok, Bin}; DeepIoList -> Bin = erlang:list_to_binary(DeepIoList), {ok, Bin} end.%%----------------------------------------------------------------------%% Convert a ActionRequest record into a binary%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_action_request(_EC, ActReq) when record(ActReq, 'ActionRequest') -> case (catch enc_ActionRequest(ActReq)) of {'EXIT', Reason} -> {error, Reason}; Bin when binary(Bin) -> {ok, Bin}; DeepIoList -> Bin = erlang:list_to_binary(DeepIoList), {ok, Bin} end.%%----------------------------------------------------------------------%% Convert a CommandRequest record into a deep io list%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_command_request(_EC, CmdReq) when record(CmdReq, 'CommandRequest') -> case (catch enc_CommandRequest(CmdReq)) of {'EXIT', Reason} -> {error, Reason}; Bin when binary(Bin) -> {ok, Bin}; DeepIoList -> Bin = erlang:list_to_binary(DeepIoList), {ok, Bin} end.%%----------------------------------------------------------------------%% Convert a action reply into a deep io list%% Return {ok, DeepIoList} | {error, Reason}%%----------------------------------------------------------------------encode_action_reply(_EC, ActRep) when record(ActRep, 'ActionReply') -> case (catch enc_ActionReply(ActRep)) of {'EXIT', Reason} -> {error, Reason}; DeepIoList -> {ok, DeepIoList} end.%%----------------------------------------------------------------------%% A utility function to pretty print the tags found in a megaco message%%----------------------------------------------------------------------token_tag2string(addReq) -> ?CompactAddToken;token_tag2string(addReply) -> ?CompactAddToken;token_tag2string(auditDescriptor) -> ?CompactAuditToken;token_tag2string(auditCapRequest) -> ?CompactAuditCapToken;token_tag2string(auditCapReply) -> ?CompactAuditCapToken;token_tag2string(auditValueRequest) -> ?CompactAuditValueToken;token_tag2string(auditValueReply) -> ?CompactAuditValueToken;%% token_tag2string(X) -> ?CompactAuthToken;token_tag2string(bothway) -> ?CompactBothwayToken;token_tag2string(brief) -> ?CompactBriefToken;%% token_tag2string(X) -> ?CompactBufferToken;%% token_tag2string(X) -> ?CompactCtxToken;%% token_tag2string(X) -> ?CompactContextAuditToken;token_tag2string(digitMapDescriptor) -> ?CompactDigitMapToken;token_tag2string(digitMapToken) -> ?CompactDigitMapToken;%% token_tag2string(X) -> ?CompactDiscardToken;%% token_tag2string(X) -> ?CompactDisconnectedToken;%% token_tag2string(X) -> ?CompactDelayToken;token_tag2string(duration) -> ?CompactDurationToken;%% token_tag2string(X) -> ?CompactEmbedToken;token_tag2string(emergencyAudit) -> ?CompactEmergencyToken;token_tag2string(errorDescriptor) -> ?CompactErrorToken;token_tag2string(eventBufferDescriptor) -> ?CompactEventBufferToken;token_tag2string(eventBufferToken) -> ?CompactEventBufferToken;token_tag2string(eventsDescriptor) -> ?CompactEventsToken;token_tag2string(eventsToken) -> ?CompactEventsToken;%% token_tag2string(X) -> ?CompactFailoverToken;%% token_tag2string(X) -> ?CompactForcedToken;%% token_tag2string(X) -> ?CompactGracefulToken;%% token_tag2string(X) -> ?CompactH221Token;%% token_tag2string(X) -> ?CompactH223Token;%% token_tag2string(X) -> ?CompactH226Token;%% token_tag2string(X) -> ?CompactHandOffToken;%% token_tag2string(X) -> ?CompactImmAckRequiredToken;token_tag2string(inactive) -> ?CompactInactiveToken;token_tag2string(onInterruptByEvent) -> ?CompactInterruptByEventToken;token_tag2string(onInterruptByNewSignalDescr) -> ?CompactInterruptByNewSignalsDescrToken;token_tag2string(isolate) -> ?CompactIsolateToken;token_tag2string(inSvc) -> ?CompactInSvcToken;token_tag2string(keepActive) -> ?CompactKeepActiveToken;token_tag2string(localDescriptor) -> ?CompactLocalToken;token_tag2string(localControlDescriptor) -> ?CompactLocalControlToken;token_tag2string(lockStep) -> ?CompactLockStepToken;token_tag2string(loopBack) -> ?CompactLoopbackToken;token_tag2string(mediaDescriptor) -> ?CompactMediaToken;token_tag2string(mediaToken) -> ?CompactMediaToken;%% token_tag2string(X) -> ?CompactMegacopToken;%% token_tag2string(X) -> ?CompactMethodToken;%% token_tag2string(X) -> ?CompactMgcIdToken;%% token_tag2string(X) -> ?CompactModeToken;token_tag2string(modReq) -> ?CompactModifyToken;token_tag2string(modReply) -> ?CompactModifyToken;token_tag2string(modemDescriptor) -> ?CompactModemToken;token_tag2string(modemToken) -> ?CompactModemToken;token_tag2string(moveReq) -> ?CompactMoveToken;token_tag2string(moveReply) -> ?CompactMoveToken;%% token_tag2string(X) -> ?CompactMtpToken;token_tag2string(muxDescriptor) -> ?CompactMuxToken;token_tag2string(muxToken) -> ?CompactMuxToken;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -