diff --git a/lib/protox/encode.ex b/lib/protox/encode.ex index d3490b8b..0cbb5e5d 100644 --- a/lib/protox/encode.ex +++ b/lib/protox/encode.ex @@ -1,7 +1,5 @@ defmodule Protox.Encode do - @moduledoc """ - This module contains the functions necessary to encode protobuf messages. - """ + @moduledoc false use Protox.{ Float, diff --git a/lib/protox/kind.ex b/lib/protox/kind.ex index 6647bc50..8babc6fc 100644 --- a/lib/protox/kind.ex +++ b/lib/protox/kind.ex @@ -1,41 +1,15 @@ -defmodule Protox.Scalar do - @moduledoc false - - @typedoc """ - All the possible types that can be used as a default value for a scalar. - """ - @type scalar_default_value_type :: - binary() - | boolean() - | integer() - | float() - | atom() - | nil - - @type t() :: %__MODULE__{ - default_value: scalar_default_value_type() - } - - @enforce_keys [:default_value] - defstruct [:default_value] -end - -defmodule Protox.OneOf do - @moduledoc false - - @type t() :: %__MODULE__{ - parent: atom() - } - - @enforce_keys [:parent] - defstruct [:parent] -end - defmodule Protox.Kind do - @moduledoc false + @moduledoc """ + Defines the kind of a field. + + It can be one of the following: - @typedoc """ - This type indicates how a field is encoded. + - `Protox.Scalar` - A [scalar](https://protobuf.dev/programming-guides/proto3/#scalar) value. + - `:packed` - A [packed repeated](https://protobuf.dev/programming-guides/encoding/#packed) field. + - `:unpacked` - An [unpacked repeated](https://protobuf.dev/programming-guides/encoding/#optional) field. + - `:map` - A [map](https://protobuf.dev/programming-guides/encoding/#maps) field. + - `Protox.OneOf` - A [oneof](https://protobuf.dev/programming-guides/encoding/#oneofs) field. """ + @type t() :: Protox.Scalar.t() | :packed | :unpacked | :map | Protox.OneOf.t() end diff --git a/lib/protox/message_schema.ex b/lib/protox/message_schema.ex index 5dd5f720..ca7f573e 100644 --- a/lib/protox/message_schema.ex +++ b/lib/protox/message_schema.ex @@ -1,6 +1,17 @@ defmodule Protox.MessageSchema do - @moduledoc false + @moduledoc """ + Represents the schema of a Protocol Buffers message once it has been processed by Protox. + This struct contains all the necessary information to describe a message in a Protocol Buffers + schema, including its name, syntax version, fields, and optional file-level options. + + ## Fields + + * `:name` - The atom representing the name of the message + * `:syntax` - The Protocol Buffers syntax version (e.g., `:proto2` or `:proto3`) + * `:fields` - A map of field names to their definitions (`Protox.Field.t()`) + * `:file_options` - Optional file-level options, represented as a map if any. + """ @type t() :: %__MODULE__{ name: atom(), syntax: atom(), diff --git a/lib/protox/one_of.ex b/lib/protox/one_of.ex new file mode 100644 index 00000000..c8b6d657 --- /dev/null +++ b/lib/protox/one_of.ex @@ -0,0 +1,20 @@ +defmodule Protox.OneOf do + @moduledoc """ + Represents a [oneof field](https://protobuf.dev/programming-guides/proto3/#oneof) in protobuf. + + A oneof field represents a group of fields where only one of them can be set at a time. + This module provides a struct to store the parent field of this oneof group, that is, the + field that effectively contains the set value. + + ## Fields + + * `:parent` - The name the parent field of this oneof group. + """ + + @type t() :: %__MODULE__{ + parent: atom() + } + + @enforce_keys [:parent] + defstruct [:parent] +end diff --git a/lib/protox/scalar.ex b/lib/protox/scalar.ex new file mode 100644 index 00000000..83b8ab44 --- /dev/null +++ b/lib/protox/scalar.ex @@ -0,0 +1,29 @@ +defmodule Protox.Scalar do + @moduledoc """ + Represents a scalar field in a Protocol Buffer message. + + This module defines a struct that holds information about a scalar field, + particularly its default value. Scalar fields are the basic data types + such as integers, floats, booleans, strings. + + The default value is used when a field is not present in the encoded message. + """ + + @typedoc """ + All the possible types that can be used as a default value for a scalar. + """ + @type scalar_default_value_type :: + binary() + | boolean() + | integer() + | float() + | atom() + | nil + + @type t() :: %__MODULE__{ + default_value: scalar_default_value_type() + } + + @enforce_keys [:default_value] + defstruct [:default_value] +end