thrift_generator_emitter (thrift_generator v0.7.0)

View Source

Turns the semantic model into Erlang modules.

Per IDL file a <mod>_types.erl is emitted: records for structs and unions (map representation via the erl.struct_type = "map" annotation, tagged-tuple sums via erl.union_type = "sum" on a union or its namespace header), the introspection surface (struct_info/1, enum_info/1, function_info/2, service_info/0) and the record-field index (record_fields/1) that thrift_runtime_record uses to bridge records and the wire.

Per service: <svc>_handler.erl (the -callback behaviour), <svc>_server.erl (a thrift_runtime_service implementation plus the server entry points) and <svc>_client.erl (typed call wrappers that convert records at the boundary).

Forms are built with erl_syntax and rendered with erl_prettypr. Descriptors are plain data: most function bodies are abstract/1 of the descriptor terms, which keeps the emitter declarative. compile_sources/1 compiles the same forms in memory for tests.

Summary

Functions

Compiles every generated module in memory (compile:forms).

The method's declared exceptions as wire descriptors.

Whether the definition declares a record (record mode, not a sum union).

The method's params struct as a wire descriptor.

The typed record declaration of a record-mode struct (remote type references under qualify).

The method's reply type as a wire descriptor, undefined for void.

The module key with dots replaced by underscores (an atom-safe module name).

The section divider label naming an IDL definition (the declared name, not the derived tag).

Renders every generated module as a source map with its hrl when present.

The struct_type axis of a definition: map, native, or record when absent or unrecognized.

Whether the union is generated as a tagged-tuple sum type.

Converts a model type into the wire descriptor vocabulary the runtime codecs consume (resolving references, expanding typedefs and inlining enum descriptors); shared with the codec emitter.

Types

annotations()

-type annotations() :: #{binary() := true | binary()}.

ast_node()

-type ast_node() ::
          #thrift_generator_node{line :: non_neg_integer(),
                                 col :: non_neg_integer(),
                                 doc :: doc(),
                                 annotations :: erl_annotations(),
                                 payload :: term(),
                                 type_module :: module()}.

base_type()

-type base_type() :: bool | i8 | i16 | i32 | i64 | double | string | binary | uuid.

compiled()

-type compiled() :: {ok, module(), binary()} | {error, {module(), [tuple()]}}.

const_value()

-type const_value() ::
          {ref, Name :: binary()} |
          boolean() |
          integer() |
          float() |
          binary() |
          {list, [const_value()]} |
          {map, [{const_value(), const_value()}]}.

constant()

-type constant() ::
          #thrift_generator_constant{name :: constant_name(),
                                     type :: thrift_type(),
                                     value :: const_value()}.

constant_name()

-nominal constant_name() :: binary().

cpp_include()

-type cpp_include() :: #thrift_generator_cpp_include{path :: include_path()}.

desc()

-type desc() :: term().

doc()

-type doc() :: binary() | undefined.

document()

-type document() :: #thrift_generator_document{headers :: [ast_node()], definitions :: [ast_node()]}.

enum_()

-type enum_() :: #thrift_generator_enum{name :: enum_name(), values :: [enum_value()]}.

enum_name()

-nominal enum_name() :: binary().

enum_value()

-type enum_value() :: {Name :: binary(), Value :: integer() | undefined, annotations(), doc()}.

erl_annotations()

-type erl_annotations() :: #{atom() := true | binary()}.

exception_()

-type exception_() :: #thrift_generator_exception{name :: exception_name(), fields :: [ast_node()]}.

exception_name()

-nominal exception_name() :: binary().

field_()

-type field_() ::
          #thrift_generator_field{id :: integer() | undefined,
                                  required :: requiredness(),
                                  type :: thrift_type(),
                                  name :: field_name(),
                                  default :: const_value() | undefined}.

field_name()

-nominal field_name() :: binary().

function_()

-type function_() ::
          #thrift_generator_function{oneway :: boolean(),
                                     return_type :: thrift_type() | void,
                                     name :: function_name(),
                                     fields :: [ast_node()],
                                     throws :: [ast_node()]}.

function_name()

-nominal function_name() :: binary().

include_()

-type include_() :: #thrift_generator_include{path :: include_path()}.

include_path()

-nominal include_path() :: binary().

module_key()

-type module_key() :: binary().

namespace_()

-type namespace_() :: #thrift_generator_namespace{scope :: namespace_scope(), name :: namespace_name()}.

namespace_name()

-nominal namespace_name() :: binary().

namespace_scope()

-nominal namespace_scope() :: binary().

node_payload()

-type node_payload() ::
          document() |
          include_() |
          cpp_include() |
          namespace_() |
          constant() |
          typedef() |
          enum_() |
          struct_() |
          union_def() |
          exception_() |
          service() |
          function_() |
          field_().

requiredness()

-type requiredness() :: required | optional | default.

service()

-type service() ::
          #thrift_generator_service{name :: service_name(),
                                    extends :: service_parent() | undefined,
                                    functions :: [ast_node()]}.

service_name()

-nominal service_name() :: binary().

service_parent()

-nominal service_parent() :: binary().

source()

-type source() :: #{module := module(), source := binary(), hrl => binary()}.

struct_()

-type struct_() :: #thrift_generator_struct{name :: struct_name(), fields :: [ast_node()]}.

struct_name()

-nominal struct_name() :: binary().

thrift_type()

-type thrift_type() ::
          {base, base_type(), annotations()} |
          type_ref() |
          {list, Element :: thrift_type(), annotations()} |
          {set, Element :: thrift_type(), annotations()} |
          {map, Key :: thrift_type(), Value :: thrift_type(), annotations()}.

type_ref()

-type type_ref() :: {ref, Name :: binary(), annotations()}.

typedef()

-type typedef() :: #thrift_generator_typedef{name :: typedef_name(), type :: thrift_type()}.

typedef_name()

-nominal typedef_name() :: binary().

union_def()

-type union_def() :: #thrift_generator_union{name :: union_name(), fields :: [ast_node()]}.

union_name()

-nominal union_name() :: binary().

Functions

compile_sources(Model)

-spec compile_sources(#tg_model{root :: binary(),
                                modules ::
                                    [#tg_module{name :: binary(),
                                                prefix :: binary(),
                                                path :: binary(),
                                                includes :: [binary()],
                                                structs ::
                                                    [#tg_struct{kind :: struct | union | exception,
                                                                name :: binary(),
                                                                fields ::
                                                                    [#tg_field{id :: integer(),
                                                                               required ::
                                                                                   requiredness(),
                                                                               type :: thrift_type(),
                                                                               name :: binary(),
                                                                               default ::
                                                                                   const_value() |
                                                                                   undefined,
                                                                               doc :: doc()}],
                                                                erl :: erl_annotations(),
                                                                doc :: doc(),
                                                                line :: non_neg_integer(),
                                                                col :: non_neg_integer()}],
                                                enums ::
                                                    [#tg_enum{name :: binary(),
                                                              values :: [{integer(), binary()}],
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}],
                                                typedefs ::
                                                    [#tg_typedef{name :: binary(),
                                                                 type :: thrift_type(),
                                                                 erl :: erl_annotations(),
                                                                 doc :: doc(),
                                                                 line :: non_neg_integer(),
                                                                 col :: non_neg_integer()}],
                                                consts ::
                                                    [#tg_const{name :: binary(),
                                                               type :: thrift_type(),
                                                               value :: const_value(),
                                                               doc :: doc(),
                                                               line :: non_neg_integer(),
                                                               col :: non_neg_integer()}],
                                                services ::
                                                    [#tg_service{name :: binary(),
                                                                 extends :: binary() | undefined,
                                                                 functions ::
                                                                     [#tg_function{name :: binary(),
                                                                                   oneway :: boolean(),
                                                                                   return_type ::
                                                                                       thrift_type() |
                                                                                       void,
                                                                                   params ::
                                                                                       [#tg_field{id ::
                                                                                                      integer(),
                                                                                                  required ::
                                                                                                      requiredness(),
                                                                                                  type ::
                                                                                                      thrift_type(),
                                                                                                  name ::
                                                                                                      binary(),
                                                                                                  default ::
                                                                                                      const_value() |
                                                                                                      undefined,
                                                                                                  doc ::
                                                                                                      doc()}],
                                                                                   throws ::
                                                                                       [#tg_field{id ::
                                                                                                      integer(),
                                                                                                  required ::
                                                                                                      requiredness(),
                                                                                                  type ::
                                                                                                      thrift_type(),
                                                                                                  name ::
                                                                                                      binary(),
                                                                                                  default ::
                                                                                                      const_value() |
                                                                                                      undefined,
                                                                                                  doc ::
                                                                                                      doc()}],
                                                                                   doc :: doc()}],
                                                                 doc :: doc(),
                                                                 line :: non_neg_integer(),
                                                                 col :: non_neg_integer()}]}]}) ->
                         [compiled()].

Compiles every generated module in memory (compile:forms).

erlang_type/2

-spec erlang_type(thrift_type(),
                  #ectx{modules ::
                            #{module_key() =>
                                  #tg_module{name :: binary(),
                                             prefix :: binary(),
                                             path :: binary(),
                                             includes :: [binary()],
                                             structs ::
                                                 [#tg_struct{kind :: struct | union | exception,
                                                             name :: binary(),
                                                             fields ::
                                                                 [#tg_field{id :: integer(),
                                                                            required :: requiredness(),
                                                                            type :: thrift_type(),
                                                                            name :: binary(),
                                                                            default ::
                                                                                const_value() |
                                                                                undefined,
                                                                            doc :: doc()}],
                                                             erl :: erl_annotations(),
                                                             doc :: doc(),
                                                             line :: non_neg_integer(),
                                                             col :: non_neg_integer()}],
                                             enums ::
                                                 [#tg_enum{name :: binary(),
                                                           values :: [{integer(), binary()}],
                                                           doc :: doc(),
                                                           line :: non_neg_integer(),
                                                           col :: non_neg_integer()}],
                                             typedefs ::
                                                 [#tg_typedef{name :: binary(),
                                                              type :: thrift_type(),
                                                              erl :: erl_annotations(),
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}],
                                             consts ::
                                                 [#tg_const{name :: binary(),
                                                            type :: thrift_type(),
                                                            value :: const_value(),
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}],
                                             services ::
                                                 [#tg_service{name :: binary(),
                                                              extends :: binary() | undefined,
                                                              functions ::
                                                                  [#tg_function{name :: binary(),
                                                                                oneway :: boolean(),
                                                                                return_type ::
                                                                                    thrift_type() | void,
                                                                                params ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                throws ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                doc :: doc()}],
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}]}},
                        type_modules :: #{module_key() => module()},
                        include_modules :: #{module_key() => module_key()},
                        current :: undefined | module_key(),
                        qualify :: boolean()}) ->
                     erl_syntax:syntaxTree().

exceptions_desc(F, Ctx)

-spec exceptions_desc(#tg_function{name :: binary(),
                                   oneway :: boolean(),
                                   return_type :: thrift_type() | void,
                                   params ::
                                       [#tg_field{id :: integer(),
                                                  required :: requiredness(),
                                                  type :: thrift_type(),
                                                  name :: binary(),
                                                  default :: const_value() | undefined,
                                                  doc :: doc()}],
                                   throws ::
                                       [#tg_field{id :: integer(),
                                                  required :: requiredness(),
                                                  type :: thrift_type(),
                                                  name :: binary(),
                                                  default :: const_value() | undefined,
                                                  doc :: doc()}],
                                   doc :: doc()},
                      #ectx{modules ::
                                #{module_key() =>
                                      #tg_module{name :: binary(),
                                                 prefix :: binary(),
                                                 path :: binary(),
                                                 includes :: [binary()],
                                                 structs ::
                                                     [#tg_struct{kind :: struct | union | exception,
                                                                 name :: binary(),
                                                                 fields ::
                                                                     [#tg_field{id :: integer(),
                                                                                required ::
                                                                                    requiredness(),
                                                                                type :: thrift_type(),
                                                                                name :: binary(),
                                                                                default ::
                                                                                    const_value() |
                                                                                    undefined,
                                                                                doc :: doc()}],
                                                                 erl :: erl_annotations(),
                                                                 doc :: doc(),
                                                                 line :: non_neg_integer(),
                                                                 col :: non_neg_integer()}],
                                                 enums ::
                                                     [#tg_enum{name :: binary(),
                                                               values :: [{integer(), binary()}],
                                                               doc :: doc(),
                                                               line :: non_neg_integer(),
                                                               col :: non_neg_integer()}],
                                                 typedefs ::
                                                     [#tg_typedef{name :: binary(),
                                                                  type :: thrift_type(),
                                                                  erl :: erl_annotations(),
                                                                  doc :: doc(),
                                                                  line :: non_neg_integer(),
                                                                  col :: non_neg_integer()}],
                                                 consts ::
                                                     [#tg_const{name :: binary(),
                                                                type :: thrift_type(),
                                                                value :: const_value(),
                                                                doc :: doc(),
                                                                line :: non_neg_integer(),
                                                                col :: non_neg_integer()}],
                                                 services ::
                                                     [#tg_service{name :: binary(),
                                                                  extends :: binary() | undefined,
                                                                  functions ::
                                                                      [#tg_function{name :: binary(),
                                                                                    oneway :: boolean(),
                                                                                    return_type ::
                                                                                        thrift_type() |
                                                                                        void,
                                                                                    params ::
                                                                                        [#tg_field{id ::
                                                                                                       integer(),
                                                                                                   required ::
                                                                                                       requiredness(),
                                                                                                   type ::
                                                                                                       thrift_type(),
                                                                                                   name ::
                                                                                                       binary(),
                                                                                                   default ::
                                                                                                       const_value() |
                                                                                                       undefined,
                                                                                                   doc ::
                                                                                                       doc()}],
                                                                                    throws ::
                                                                                        [#tg_field{id ::
                                                                                                       integer(),
                                                                                                   required ::
                                                                                                       requiredness(),
                                                                                                   type ::
                                                                                                       thrift_type(),
                                                                                                   name ::
                                                                                                       binary(),
                                                                                                   default ::
                                                                                                       const_value() |
                                                                                                       undefined,
                                                                                                   doc ::
                                                                                                       doc()}],
                                                                                    doc :: doc()}],
                                                                  doc :: doc(),
                                                                  line :: non_neg_integer(),
                                                                  col :: non_neg_integer()}]}},
                            type_modules :: #{module_key() => module()},
                            include_modules :: #{module_key() => module_key()},
                            current :: undefined | module_key(),
                            qualify :: boolean()}) ->
                         [desc()].

The method's declared exceptions as wire descriptors.

has_record(S)

-spec has_record(#tg_struct{kind :: struct | union | exception,
                            name :: binary(),
                            fields ::
                                [#tg_field{id :: integer(),
                                           required :: requiredness(),
                                           type :: thrift_type(),
                                           name :: binary(),
                                           default :: const_value() | undefined,
                                           doc :: doc()}],
                            erl :: erl_annotations(),
                            doc :: doc(),
                            line :: non_neg_integer(),
                            col :: non_neg_integer()}) ->
                    boolean().

Whether the definition declares a record (record mode, not a sum union).

params_desc(F, Ctx)

-spec params_desc(#tg_function{name :: binary(),
                               oneway :: boolean(),
                               return_type :: thrift_type() | void,
                               params ::
                                   [#tg_field{id :: integer(),
                                              required :: requiredness(),
                                              type :: thrift_type(),
                                              name :: binary(),
                                              default :: const_value() | undefined,
                                              doc :: doc()}],
                               throws ::
                                   [#tg_field{id :: integer(),
                                              required :: requiredness(),
                                              type :: thrift_type(),
                                              name :: binary(),
                                              default :: const_value() | undefined,
                                              doc :: doc()}],
                               doc :: doc()},
                  #ectx{modules ::
                            #{module_key() =>
                                  #tg_module{name :: binary(),
                                             prefix :: binary(),
                                             path :: binary(),
                                             includes :: [binary()],
                                             structs ::
                                                 [#tg_struct{kind :: struct | union | exception,
                                                             name :: binary(),
                                                             fields ::
                                                                 [#tg_field{id :: integer(),
                                                                            required :: requiredness(),
                                                                            type :: thrift_type(),
                                                                            name :: binary(),
                                                                            default ::
                                                                                const_value() |
                                                                                undefined,
                                                                            doc :: doc()}],
                                                             erl :: erl_annotations(),
                                                             doc :: doc(),
                                                             line :: non_neg_integer(),
                                                             col :: non_neg_integer()}],
                                             enums ::
                                                 [#tg_enum{name :: binary(),
                                                           values :: [{integer(), binary()}],
                                                           doc :: doc(),
                                                           line :: non_neg_integer(),
                                                           col :: non_neg_integer()}],
                                             typedefs ::
                                                 [#tg_typedef{name :: binary(),
                                                              type :: thrift_type(),
                                                              erl :: erl_annotations(),
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}],
                                             consts ::
                                                 [#tg_const{name :: binary(),
                                                            type :: thrift_type(),
                                                            value :: const_value(),
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}],
                                             services ::
                                                 [#tg_service{name :: binary(),
                                                              extends :: binary() | undefined,
                                                              functions ::
                                                                  [#tg_function{name :: binary(),
                                                                                oneway :: boolean(),
                                                                                return_type ::
                                                                                    thrift_type() | void,
                                                                                params ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                throws ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                doc :: doc()}],
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}]}},
                        type_modules :: #{module_key() => module()},
                        include_modules :: #{module_key() => module_key()},
                        current :: undefined | module_key(),
                        qualify :: boolean()}) ->
                     desc().

The method's params struct as a wire descriptor.

record_form(S, Prefix, Ctx)

-spec record_form(#tg_struct{kind :: struct | union | exception,
                             name :: binary(),
                             fields ::
                                 [#tg_field{id :: integer(),
                                            required :: requiredness(),
                                            type :: thrift_type(),
                                            name :: binary(),
                                            default :: const_value() | undefined,
                                            doc :: doc()}],
                             erl :: erl_annotations(),
                             doc :: doc(),
                             line :: non_neg_integer(),
                             col :: non_neg_integer()},
                  binary(),
                  #ectx{modules ::
                            #{module_key() =>
                                  #tg_module{name :: binary(),
                                             prefix :: binary(),
                                             path :: binary(),
                                             includes :: [binary()],
                                             structs ::
                                                 [#tg_struct{kind :: struct | union | exception,
                                                             name :: binary(),
                                                             fields ::
                                                                 [#tg_field{id :: integer(),
                                                                            required :: requiredness(),
                                                                            type :: thrift_type(),
                                                                            name :: binary(),
                                                                            default ::
                                                                                const_value() |
                                                                                undefined,
                                                                            doc :: doc()}],
                                                             erl :: erl_annotations(),
                                                             doc :: doc(),
                                                             line :: non_neg_integer(),
                                                             col :: non_neg_integer()}],
                                             enums ::
                                                 [#tg_enum{name :: binary(),
                                                           values :: [{integer(), binary()}],
                                                           doc :: doc(),
                                                           line :: non_neg_integer(),
                                                           col :: non_neg_integer()}],
                                             typedefs ::
                                                 [#tg_typedef{name :: binary(),
                                                              type :: thrift_type(),
                                                              erl :: erl_annotations(),
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}],
                                             consts ::
                                                 [#tg_const{name :: binary(),
                                                            type :: thrift_type(),
                                                            value :: const_value(),
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}],
                                             services ::
                                                 [#tg_service{name :: binary(),
                                                              extends :: binary() | undefined,
                                                              functions ::
                                                                  [#tg_function{name :: binary(),
                                                                                oneway :: boolean(),
                                                                                return_type ::
                                                                                    thrift_type() | void,
                                                                                params ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                throws ::
                                                                                    [#tg_field{id ::
                                                                                                   integer(),
                                                                                               required ::
                                                                                                   requiredness(),
                                                                                               type ::
                                                                                                   thrift_type(),
                                                                                               name ::
                                                                                                   binary(),
                                                                                               default ::
                                                                                                   const_value() |
                                                                                                   undefined,
                                                                                               doc ::
                                                                                                   doc()}],
                                                                                doc :: doc()}],
                                                              doc :: doc(),
                                                              line :: non_neg_integer(),
                                                              col :: non_neg_integer()}]}},
                        type_modules :: #{module_key() => module()},
                        include_modules :: #{module_key() => module_key()},
                        current :: undefined | module_key(),
                        qualify :: boolean()}) ->
                     erl_syntax:forms().

The typed record declaration of a record-mode struct (remote type references under qualify).

reply_desc(F, Ctx)

-spec reply_desc(#tg_function{name :: binary(),
                              oneway :: boolean(),
                              return_type :: thrift_type() | void,
                              params ::
                                  [#tg_field{id :: integer(),
                                             required :: requiredness(),
                                             type :: thrift_type(),
                                             name :: binary(),
                                             default :: const_value() | undefined,
                                             doc :: doc()}],
                              throws ::
                                  [#tg_field{id :: integer(),
                                             required :: requiredness(),
                                             type :: thrift_type(),
                                             name :: binary(),
                                             default :: const_value() | undefined,
                                             doc :: doc()}],
                              doc :: doc()},
                 #ectx{modules ::
                           #{module_key() =>
                                 #tg_module{name :: binary(),
                                            prefix :: binary(),
                                            path :: binary(),
                                            includes :: [binary()],
                                            structs ::
                                                [#tg_struct{kind :: struct | union | exception,
                                                            name :: binary(),
                                                            fields ::
                                                                [#tg_field{id :: integer(),
                                                                           required :: requiredness(),
                                                                           type :: thrift_type(),
                                                                           name :: binary(),
                                                                           default ::
                                                                               const_value() | undefined,
                                                                           doc :: doc()}],
                                                            erl :: erl_annotations(),
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}],
                                            enums ::
                                                [#tg_enum{name :: binary(),
                                                          values :: [{integer(), binary()}],
                                                          doc :: doc(),
                                                          line :: non_neg_integer(),
                                                          col :: non_neg_integer()}],
                                            typedefs ::
                                                [#tg_typedef{name :: binary(),
                                                             type :: thrift_type(),
                                                             erl :: erl_annotations(),
                                                             doc :: doc(),
                                                             line :: non_neg_integer(),
                                                             col :: non_neg_integer()}],
                                            consts ::
                                                [#tg_const{name :: binary(),
                                                           type :: thrift_type(),
                                                           value :: const_value(),
                                                           doc :: doc(),
                                                           line :: non_neg_integer(),
                                                           col :: non_neg_integer()}],
                                            services ::
                                                [#tg_service{name :: binary(),
                                                             extends :: binary() | undefined,
                                                             functions ::
                                                                 [#tg_function{name :: binary(),
                                                                               oneway :: boolean(),
                                                                               return_type ::
                                                                                   thrift_type() | void,
                                                                               params ::
                                                                                   [#tg_field{id ::
                                                                                                  integer(),
                                                                                              required ::
                                                                                                  requiredness(),
                                                                                              type ::
                                                                                                  thrift_type(),
                                                                                              name ::
                                                                                                  binary(),
                                                                                              default ::
                                                                                                  const_value() |
                                                                                                  undefined,
                                                                                              doc ::
                                                                                                  doc()}],
                                                                               throws ::
                                                                                   [#tg_field{id ::
                                                                                                  integer(),
                                                                                              required ::
                                                                                                  requiredness(),
                                                                                              type ::
                                                                                                  thrift_type(),
                                                                                              name ::
                                                                                                  binary(),
                                                                                              default ::
                                                                                                  const_value() |
                                                                                                  undefined,
                                                                                              doc ::
                                                                                                  doc()}],
                                                                               doc :: doc()}],
                                                             doc :: doc(),
                                                             line :: non_neg_integer(),
                                                             col :: non_neg_integer()}]}},
                       type_modules :: #{module_key() => module()},
                       include_modules :: #{module_key() => module_key()},
                       current :: undefined | module_key(),
                       qualify :: boolean()}) ->
                    desc() | undefined.

The method's reply type as a wire descriptor, undefined for void.

sanitize(Name)

-spec sanitize(binary()) -> binary().

The module key with dots replaced by underscores (an atom-safe module name).

section_label/1

-spec section_label(#tg_struct{kind :: struct | union | exception,
                               name :: binary(),
                               fields ::
                                   [#tg_field{id :: integer(),
                                              required :: requiredness(),
                                              type :: thrift_type(),
                                              name :: binary(),
                                              default :: const_value() | undefined,
                                              doc :: doc()}],
                               erl :: erl_annotations(),
                               doc :: doc(),
                               line :: non_neg_integer(),
                               col :: non_neg_integer()} |
                    #tg_enum{name :: binary(),
                             values :: [{integer(), binary()}],
                             doc :: doc(),
                             line :: non_neg_integer(),
                             col :: non_neg_integer()} |
                    #tg_typedef{name :: binary(),
                                type :: thrift_type(),
                                erl :: erl_annotations(),
                                doc :: doc(),
                                line :: non_neg_integer(),
                                col :: non_neg_integer()}) ->
                       string().

The section divider label naming an IDL definition (the declared name, not the derived tag).

sources(Model)

-spec sources(#tg_model{root :: binary(),
                        modules ::
                            [#tg_module{name :: binary(),
                                        prefix :: binary(),
                                        path :: binary(),
                                        includes :: [binary()],
                                        structs ::
                                            [#tg_struct{kind :: struct | union | exception,
                                                        name :: binary(),
                                                        fields ::
                                                            [#tg_field{id :: integer(),
                                                                       required :: requiredness(),
                                                                       type :: thrift_type(),
                                                                       name :: binary(),
                                                                       default ::
                                                                           const_value() | undefined,
                                                                       doc :: doc()}],
                                                        erl :: erl_annotations(),
                                                        doc :: doc(),
                                                        line :: non_neg_integer(),
                                                        col :: non_neg_integer()}],
                                        enums ::
                                            [#tg_enum{name :: binary(),
                                                      values :: [{integer(), binary()}],
                                                      doc :: doc(),
                                                      line :: non_neg_integer(),
                                                      col :: non_neg_integer()}],
                                        typedefs ::
                                            [#tg_typedef{name :: binary(),
                                                         type :: thrift_type(),
                                                         erl :: erl_annotations(),
                                                         doc :: doc(),
                                                         line :: non_neg_integer(),
                                                         col :: non_neg_integer()}],
                                        consts ::
                                            [#tg_const{name :: binary(),
                                                       type :: thrift_type(),
                                                       value :: const_value(),
                                                       doc :: doc(),
                                                       line :: non_neg_integer(),
                                                       col :: non_neg_integer()}],
                                        services ::
                                            [#tg_service{name :: binary(),
                                                         extends :: binary() | undefined,
                                                         functions ::
                                                             [#tg_function{name :: binary(),
                                                                           oneway :: boolean(),
                                                                           return_type ::
                                                                               thrift_type() | void,
                                                                           params ::
                                                                               [#tg_field{id ::
                                                                                              integer(),
                                                                                          required ::
                                                                                              requiredness(),
                                                                                          type ::
                                                                                              thrift_type(),
                                                                                          name ::
                                                                                              binary(),
                                                                                          default ::
                                                                                              const_value() |
                                                                                              undefined,
                                                                                          doc :: doc()}],
                                                                           throws ::
                                                                               [#tg_field{id ::
                                                                                              integer(),
                                                                                          required ::
                                                                                              requiredness(),
                                                                                          type ::
                                                                                              thrift_type(),
                                                                                          name ::
                                                                                              binary(),
                                                                                          default ::
                                                                                              const_value() |
                                                                                              undefined,
                                                                                          doc :: doc()}],
                                                                           doc :: doc()}],
                                                         doc :: doc(),
                                                         line :: non_neg_integer(),
                                                         col :: non_neg_integer()}]}]}) ->
                 [source()].

Renders every generated module as a source map with its hrl when present.

struct_type(S)

-spec struct_type(#tg_struct{kind :: struct | union | exception,
                             name :: binary(),
                             fields ::
                                 [#tg_field{id :: integer(),
                                            required :: requiredness(),
                                            type :: thrift_type(),
                                            name :: binary(),
                                            default :: const_value() | undefined,
                                            doc :: doc()}],
                             erl :: erl_annotations(),
                             doc :: doc(),
                             line :: non_neg_integer(),
                             col :: non_neg_integer()}) ->
                     record | map | native.

The struct_type axis of a definition: map, native, or record when absent or unrecognized.

sum_mode(S)

-spec sum_mode(#tg_struct{kind :: struct | union | exception,
                          name :: binary(),
                          fields ::
                              [#tg_field{id :: integer(),
                                         required :: requiredness(),
                                         type :: thrift_type(),
                                         name :: binary(),
                                         default :: const_value() | undefined,
                                         doc :: doc()}],
                          erl :: erl_annotations(),
                          doc :: doc(),
                          line :: non_neg_integer(),
                          col :: non_neg_integer()}) ->
                  boolean().

Whether the union is generated as a tagged-tuple sum type.

type_desc/2

-spec type_desc(thrift_type(),
                #ectx{modules ::
                          #{module_key() =>
                                #tg_module{name :: binary(),
                                           prefix :: binary(),
                                           path :: binary(),
                                           includes :: [binary()],
                                           structs ::
                                               [#tg_struct{kind :: struct | union | exception,
                                                           name :: binary(),
                                                           fields ::
                                                               [#tg_field{id :: integer(),
                                                                          required :: requiredness(),
                                                                          type :: thrift_type(),
                                                                          name :: binary(),
                                                                          default ::
                                                                              const_value() | undefined,
                                                                          doc :: doc()}],
                                                           erl :: erl_annotations(),
                                                           doc :: doc(),
                                                           line :: non_neg_integer(),
                                                           col :: non_neg_integer()}],
                                           enums ::
                                               [#tg_enum{name :: binary(),
                                                         values :: [{integer(), binary()}],
                                                         doc :: doc(),
                                                         line :: non_neg_integer(),
                                                         col :: non_neg_integer()}],
                                           typedefs ::
                                               [#tg_typedef{name :: binary(),
                                                            type :: thrift_type(),
                                                            erl :: erl_annotations(),
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}],
                                           consts ::
                                               [#tg_const{name :: binary(),
                                                          type :: thrift_type(),
                                                          value :: const_value(),
                                                          doc :: doc(),
                                                          line :: non_neg_integer(),
                                                          col :: non_neg_integer()}],
                                           services ::
                                               [#tg_service{name :: binary(),
                                                            extends :: binary() | undefined,
                                                            functions ::
                                                                [#tg_function{name :: binary(),
                                                                              oneway :: boolean(),
                                                                              return_type ::
                                                                                  thrift_type() | void,
                                                                              params ::
                                                                                  [#tg_field{id ::
                                                                                                 integer(),
                                                                                             required ::
                                                                                                 requiredness(),
                                                                                             type ::
                                                                                                 thrift_type(),
                                                                                             name ::
                                                                                                 binary(),
                                                                                             default ::
                                                                                                 const_value() |
                                                                                                 undefined,
                                                                                             doc ::
                                                                                                 doc()}],
                                                                              throws ::
                                                                                  [#tg_field{id ::
                                                                                                 integer(),
                                                                                             required ::
                                                                                                 requiredness(),
                                                                                             type ::
                                                                                                 thrift_type(),
                                                                                             name ::
                                                                                                 binary(),
                                                                                             default ::
                                                                                                 const_value() |
                                                                                                 undefined,
                                                                                             doc ::
                                                                                                 doc()}],
                                                                              doc :: doc()}],
                                                            doc :: doc(),
                                                            line :: non_neg_integer(),
                                                            col :: non_neg_integer()}]}},
                      type_modules :: #{module_key() => module()},
                      include_modules :: #{module_key() => module_key()},
                      current :: undefined | module_key(),
                      qualify :: boolean()}) ->
                   desc().

Converts a model type into the wire descriptor vocabulary the runtime codecs consume (resolving references, expanding typedefs and inlining enum descriptors); shared with the codec emitter.