Skip to content

Commit

Permalink
docs: document public modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamez committed Feb 28, 2025
1 parent 7c57ab8 commit f3a5cf6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 40 deletions.
4 changes: 1 addition & 3 deletions lib/protox/encode.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
defmodule Protox.Encode do
@moduledoc """
This module contains the functions necessary to encode protobuf messages.
"""
@moduledoc false

use Protox.{
Float,
Expand Down
46 changes: 10 additions & 36 deletions lib/protox/kind.ex
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion lib/protox/message_schema.ex
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
20 changes: 20 additions & 0 deletions lib/protox/one_of.ex
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions lib/protox/scalar.ex
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f3a5cf6

Please sign in to comment.