%% Generated by the Erlang ASN.1 BER-compiler version, utilizing bit-syntax:1.3.1.4
%% Purpose: encoder and decoder to the types in mod P-Record
-module('P-Record').
-include("P-Record.hrl").
-define('RT_PER',asn1rt_per_bin).
-export([encoding_rule/0]).
-export([
'enc_PersonnelRecord'/1,
'enc_ChildInformation'/1,
'enc_Name'/1,
'enc_EmployeeNumber'/1,
'enc_Date'/1
]).
-export([
'dec_PersonnelRecord'/2,
'dec_ChildInformation'/2,
'dec_Name'/2,
'dec_EmployeeNumber'/2,
'dec_Date'/2
]).
-export([
'v'/0
]).
-export([encode/2,decode/2,encode_disp/2,decode_disp/2]).
encoding_rule() ->
per_bin.
encode(Type,Data) ->
case catch ?RT_PER:complete(encode_disp(Type,Data)) of
{'EXIT',{error,Reason}} ->
{error,Reason};
{'EXIT',Reason} ->
{error,{asn1,Reason}};
{Bytes,Len} ->
{ok,Bytes};
X ->
{ok,X}
end.
decode(Type,Data) ->
case catch decode_disp(Type,Data) of
{'EXIT',{error,Reason}} ->
{error,Reason};
{'EXIT',Reason} ->
{error,{asn1,Reason}};
{X,_Rest} ->
{ok,X};
{X,_Rest,_Len} ->
{ok,X}
end.
encode_disp('PersonnelRecord',Data) -> 'enc_PersonnelRecord'(Data);
encode_disp('ChildInformation',Data) -> 'enc_ChildInformation'(Data);
encode_disp('Name',Data) -> 'enc_Name'(Data);
encode_disp('EmployeeNumber',Data) -> 'enc_EmployeeNumber'(Data);
encode_disp('Date',Data) -> 'enc_Date'(Data);
encode_disp(Type,Data) -> exit({error,{asn1,{undefined_type,Type}}}).
decode_disp('PersonnelRecord',Data) -> 'dec_PersonnelRecord'(Data,mandatory);
decode_disp('ChildInformation',Data) -> 'dec_ChildInformation'(Data,mandatory);
decode_disp('Name',Data) -> 'dec_Name'(Data,mandatory);
decode_disp('EmployeeNumber',Data) -> 'dec_EmployeeNumber'(Data,mandatory);
decode_disp('Date',Data) -> 'dec_Date'(Data,mandatory);
decode_disp(Type,Data) -> exit({error,{asn1,{undefined_type,Type}}}).
'enc_PersonnelRecord'(Val) ->
{Val1,Opt} = ?RT_PER:fixoptionals([{children,6}],Val),
[
?RT_PER:setoptionals(Opt),
%% attribute number 1 with type Externaltypereference6P-RecordName
'enc_Name'(?RT_PER:cindex(2,Val1,name)),
%% attribute number 2 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(3,Val1,title)),
%% attribute number 3 with type INTEGER
?RT_PER:encode_integer([],?RT_PER:cindex(4,Val1,number)),
%% attribute number 4 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(5,Val1,dateOfHire)),
%% attribute number 5 with type Externaltypereference10P-RecordName
'enc_Name'(?RT_PER:cindex(6,Val1,nameOfSpouse)),
case ?RT_PER:cindex(7,Val1,children) of
asn1_DEFAULT -> [];
_ ->
%% attribute number 6 with type SEQUENCE OF
'enc_PersonnelRecord_children'(?RT_PER:cindex(7,Val1,children))
end].
'enc_PersonnelRecord_children'({'PersonnelRecord_children',Val}) ->
'enc_PersonnelRecord_children'(Val);
'enc_PersonnelRecord_children'(Val) ->
[
?RT_PER:encode_length(undefined,length(Val)),
'enc_PersonnelRecord_children_components'(Val, [])
].
'enc_PersonnelRecord_children_components'([], Acc) -> lists:reverse(Acc);
'enc_PersonnelRecord_children_components'([H|T], Acc) ->
'enc_PersonnelRecord_children_components'(T, ['enc_ChildInformation'(H)
| Acc]).
'dec_PersonnelRecord_children'(Bytes,Telltype) ->
{Num,Bytes1} = ?RT_PER:decode_length(Bytes,undefined),
'dec_PersonnelRecord_children_components'(Num, Bytes1, Telltype, []).
'dec_PersonnelRecord_children_components'(0, Bytes, Telltype, Acc) ->
{lists:reverse(Acc), Bytes};
'dec_PersonnelRecord_children_components'(Num, Bytes, Telltype, Acc) ->
{Term,Remain} = 'P-Record':'dec_ChildInformation'(Bytes,Telltype),
'dec_PersonnelRecord_children_components'(Num-1, Remain, Telltype, [Term|Acc]).
'dec_PersonnelRecord'(Bytes,Telltype) ->
{Opt,Bytes1} = ?RT_PER:getoptionals(Bytes,1),
%% attribute number 1 with type Name
{Term1,Bytes2} = 'dec_Name'(Bytes1,telltype),
%% attribute number 2 with type VisibleString
{Term2,Bytes3} = ?RT_PER:decode_VisibleString(Bytes2,[]),
%% attribute number 3 with type INTEGER
{Term3,Bytes4} = ?RT_PER:decode_integer(Bytes3,[]),
%% attribute number 4 with type VisibleString
{Term4,Bytes5} = ?RT_PER:decode_VisibleString(Bytes4,[]),
%% attribute number 5 with type Name
{Term5,Bytes6} = 'dec_Name'(Bytes5,telltype),
%% attribute number 6 with type SEQUENCE OF
{Term6,Bytes7} = case element(1,Opt) of
1 ->'dec_PersonnelRecord_children'(Bytes6, Telltype);
0 ->{[],Bytes6}
end,
{{'PersonnelRecord',Term1,Term2,Term3,Term4,Term5,Term6},Bytes7}.
'enc_ChildInformation'(Val) ->
{Val1,Opt} = ?RT_PER:fixoptionals([{name,1},{dateOfBirth,2}],Val),
[
?RT_PER:setoptionals(Opt),
case ?RT_PER:cindex(2,Val1,name) of
asn1_NOVALUE -> [];
_ ->
%% attribute number 1 with type Externaltypereference15P-RecordName
'enc_Name'(?RT_PER:cindex(2,Val1,name))
end,
case ?RT_PER:cindex(3,Val1,dateOfBirth) of
asn1_NOVALUE -> [];
_ ->
%% attribute number 2 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(3,Val1,dateOfBirth))
end].
'dec_ChildInformation'(Bytes,Telltype) ->
{Opt,Bytes1} = ?RT_PER:getoptionals(Bytes,2),
%% attribute number 1 with type Name
{Term1,Bytes2} = case element(1,Opt) of
1 ->'dec_Name'(Bytes1,telltype);
0 ->{asn1_NOVALUE,Bytes1}
end,
%% attribute number 2 with type VisibleString
{Term2,Bytes3} = case element(2,Opt) of
1 ->?RT_PER:decode_VisibleString(Bytes2,[]);
0 ->{asn1_NOVALUE,Bytes2}
end,
{{'ChildInformation',Term1,Term2},Bytes3}.
'enc_Name'(Val) ->
Val1 = ?RT_PER:list_to_record('Name', Val),
[
%% attribute number 1 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(2,Val1,givenName)),
%% attribute number 2 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(3,Val1,initial)),
%% attribute number 3 with type VisibleString
?RT_PER:encode_VisibleString([],?RT_PER:cindex(4,Val1,familyName))].
'dec_Name'(Bytes,Telltype) ->
%% attribute number 1 with type VisibleString
{Term1,Bytes1} = ?RT_PER:decode_VisibleString(Bytes,[]),
%% attribute number 2 with type VisibleString
{Term2,Bytes2} = ?RT_PER:decode_VisibleString(Bytes1,[]),
%% attribute number 3 with type VisibleString
{Term3,Bytes3} = ?RT_PER:decode_VisibleString(Bytes2,[]),
{{'Name',Term1,Term2,Term3},Bytes3}.
'enc_EmployeeNumber'({'EmployeeNumber',Val}) ->
'enc_EmployeeNumber'(Val);
'enc_EmployeeNumber'(Val) ->
?RT_PER:encode_integer([],Val).
'dec_EmployeeNumber'(Bytes,Telltype) ->
?RT_PER:decode_integer(Bytes,[]).
'enc_Date'({'Date',Val}) ->
'enc_Date'(Val);
'enc_Date'(Val) ->
?RT_PER:encode_VisibleString([],Val).
'dec_Date'(Bytes,Telltype) ->
?RT_PER:decode_VisibleString(Bytes,[]).
'v'() ->
{'PersonnelRecord',{'Name',{74,111,104,110},[80],[83,109,105,116,104]},[68,105,114,101,99,116,111,114],51,[49,57,55,49,48,57,49,55],{'Name',{77,97,114,121},[84],[83,109,105,116,104]},[{'ChildInformation',{'Name',[82,97,108,112,104],[84],[83,109,105,116,104]},[49,57,53,55,49,49,49,49]},{'ChildInformation',{'Name',[83,117,115,97,110],[66],[74,111,110,101,115]},[49,57,53,57,48,55,49,55]}]}.