<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd" [
  <!ENTITY compile_forms2
  '<seealso marker="compiler:compile#forms-2">compile:forms/2</seealso>'>
  <!ENTITY filename
  '<seealso marker="kernel:file#type-name">file:name()</seealso>'>
  <!ENTITY dictionary
  '<seealso marker="diameter_dict">dictionary file</seealso>'>
  <!ENTITY % also SYSTEM "seealso.ent" >
  <!ENTITY % here SYSTEM "seehere.ent" >
  %also;
  %here;
]>

<erlref>
<header>
<copyright>
<year>2012</year>
<year>2016</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

</legalnotice>

<title>diameter_make(3)</title>
<prepared>Anders Svensson</prepared>
<responsible></responsible>
<docno></docno>
<approved></approved>
<checked></checked>
<date></date>
<rev></rev>
<file>diameter_make.xml</file>
</header>

<module since="OTP R14B03">diameter_make</module>
<modulesummary>Diameter dictionary compilation.</modulesummary>

<description>

<p>
The function &codec; is used to compile a diameter
&dictionary; into Erlang source.
The resulting source implements the interface diameter requires
to encode and decode the dictionary's messages and AVPs.</p>

<p>
The utility &man_compile; provides an alternate compilation
interface.</p>

</description>

<!-- ===================================================================== -->

<funcs>

<func>
<name since="OTP R15B">codec(File :: iolist() | binary(), [Opt]) -> ok
                                                 | {ok, [Out]}
                                                 | {error, Reason}</name>
<fsummary>Compile a dictionary file into Erlang source.</fsummary>
<desc>

<p>
Compile a single dictionary file.
The input <c>File</c> can be either a path or a literal dictionary,
the occurrence of newline (ascii NL) or carriage return (ascii CR)
identifying the latter.
<c>Opt</c> determines the format of the results and whether they are
written to file or returned, and can have the following types.</p>

<taglist>

<tag><c>parse | forms | erl | hrl</c></tag>
<item>
<p>
Specifies an output format.
Whether the output is returned or written to file depends on whether
or not option <c>return</c> is specified.
When written to file, the resulting file(s) will have extensions
<c>.D</c>, <c>.F</c>, <c>.erl</c>, and <c>.hrl</c>
respectively, basenames defaulting to <c>dictionary</c> if the input
dictionary is literal and does not specify <c>&dict_name;</c>.
When returned, results are in the order of the corresponding format
options.
Format options default to <c>erl</c> and <c>hrl</c> (in this order) if
unspecified.</p>

<p>
The <c>parse</c> format is an internal representation that can be
passed to &flatten; and &format;, while the <c>forms</c> format can be
passed to &compile_forms2;.
The <c>erl</c> and <c>hrl</c> formats are returned as
iolists.</p>
<!-- That codec/2 can take the parsed format is undocumented, and
     options name and inherits have no effect in this case. -->
</item>

<tag><c>{include, string()}</c></tag>
<item>
<p>
Prepend the specified directory to the code path.
Use to point at beam files compiled from inherited dictionaries,
<c>&dict_inherits;</c> in a dictionary file creating a beam
dependency, not an erl/hrl dependency.</p>

<p>
Multiple <c>include</c> options can be specified.</p>
</item>

<tag><c>{outdir, string()}</c></tag>
<item>
<p>
Write generated source to the specified directory.
Defaults to the current working directory.
Has no effect if option <c>return</c> is specified.</p>
</item>

<tag><c>return</c></tag>
<item>
<p>
Return results in a <c>{ok, [Out]}</c> tuple instead of writing to
file and returning <c>ok</c>.</p>
</item>

<tag><c>{name|prefix, string()}</c></tag>
<item>
<p>
Transform the input dictionary before compilation, setting
<c>&dict_name;</c> or <c>&dict_prefix;</c> to the specified
string.</p>
</item>

<tag><c>{inherits, string()}</c></tag>
<item>
<p>
Transform the input dictionary before compilation, appending
<c>&dict_inherits;</c> of the specified string.</p>

<p>
Two forms have special meaning:</p>

<pre>
{inherits, "-"}
{inherits, "Prev/Mod"}
</pre>

<p>
The first has the effect of clearing any previous inherits, the second
of replacing a previous inherits of <c>Prev</c> to one of <c>Mod</c>.
This allows the semantics of the input dictionary to be changed without
modifying the file itself.</p>

<p>
Multiple <c>inherits</c> options can be specified.</p>
</item>

</taglist>

<p>
Note that a dictionary's <c>&dict_name;</c>, together with the
<c>outdir</c> option, determine the output paths when the
<c>return</c> option is not specified.
The <c>&dict_name;</c> of a literal input dictionary defaults to
<c>dictionary</c>.</p>

<p>
A returned error reason can be converted into a readable string using
&format_error;.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R16B03">format(Parsed) -> iolist()</name>
<fsummary>Format a parsed dictionary.</fsummary>
<desc>
<p>
Turns a parsed dictionary, as returned by &codec;, back into the
dictionary format.</p>
</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R16B03">flatten(Parsed) -> term()</name>
<fsummary>Flatten a parsed dictionary.</fsummary>
<desc>

<p>
Reconstitute a parsed dictionary, as returned by &codec;, without
using <c>&dict_inherits;</c>.
That is, construct an equivalent dictionary in which all AVP's are
definined in the dictionary itself.
The return value is also a parsed dictionary.</p>
</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP 17.0">format_error(Reason) -> string()</name>
<fsummary>Turn an error reason into a readable string.</fsummary>
<desc>

<p>
Turn an error reason returned by &codec; into a readable string.</p>
</desc>
</func>

</funcs>

<!-- ===================================================================== -->

<section>
<title>BUGS</title>

<p>
Unrecognized options are silently ignored.</p>
</section>

<!-- ===================================================================== -->

<section>
<title>SEE ALSO</title>

<p>
&man_compile;, &man_dict;</p>

</section>

</erlref>
