<!-- Code generated by gomarkdoc. DO NOT EDIT -->

```go
import "github.com/Azure/iot-operations-sdks/go/protocol"
```

## Index

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func Must\[T any\]\(t T, e error\) T](<#Must>)
- [func WithLogger\(logger \*slog.Logger\) interface \{
    Option
    ApplicationOption
    CommandExecutorOption
    CommandInvokerOption
    TelemetryReceiverOption
    TelemetrySenderOption
\}](<#WithLogger>)
- [type Application](<#Application>)
  - [func NewApplication\(opt ...ApplicationOption\) \(\*Application, error\)](<#NewApplication>)
  - [func \(a \*Application\) GetHLC\(\) \(hlc.HybridLogicalClock, error\)](<#Application.GetHLC>)
  - [func \(a \*Application\) SetHLC\(val hlc.HybridLogicalClock\) error](<#Application.SetHLC>)
- [type ApplicationOption](<#ApplicationOption>)
- [type ApplicationOptions](<#ApplicationOptions>)
  - [func \(o \*ApplicationOptions\) Apply\(opts \[\]ApplicationOption, rest ...ApplicationOption\)](<#ApplicationOptions.Apply>)
- [type CloudEvent](<#CloudEvent>)
  - [func CloudEventFromTelemetry\[T any\]\(msg \*TelemetryMessage\[T\]\) \(\*CloudEvent, error\)](<#CloudEventFromTelemetry>)
  - [func \(ce \*CloudEvent\) Attrs\(\) \[\]slog.Attr](<#CloudEvent.Attrs>)
- [type CommandExecutor](<#CommandExecutor>)
  - [func NewCommandExecutor\[Req, Res any\]\(app \*Application, client MqttClient, requestEncoding Encoding\[Req\], responseEncoding Encoding\[Res\], requestTopicPattern string, handler CommandHandler\[Req, Res\], opt ...CommandExecutorOption\) \(ce \*CommandExecutor\[Req, Res\], err error\)](<#NewCommandExecutor>)
  - [func \(ce \*CommandExecutor\[Req, Res\]\) Close\(\)](<#CommandExecutor[Req, Res].Close>)
  - [func \(ce \*CommandExecutor\[Req, Res\]\) Start\(ctx context.Context\) error](<#CommandExecutor[Req, Res].Start>)
- [type CommandExecutorOption](<#CommandExecutorOption>)
- [type CommandExecutorOptions](<#CommandExecutorOptions>)
  - [func \(o \*CommandExecutorOptions\) Apply\(opts \[\]CommandExecutorOption, rest ...CommandExecutorOption\)](<#CommandExecutorOptions.Apply>)
  - [func \(o \*CommandExecutorOptions\) ApplyOptions\(opts \[\]Option, rest ...Option\)](<#CommandExecutorOptions.ApplyOptions>)
- [type CommandHandler](<#CommandHandler>)
- [type CommandInvoker](<#CommandInvoker>)
  - [func NewCommandInvoker\[Req, Res any\]\(app \*Application, client MqttClient, requestEncoding Encoding\[Req\], responseEncoding Encoding\[Res\], requestTopicPattern string, opt ...CommandInvokerOption\) \(ci \*CommandInvoker\[Req, Res\], err error\)](<#NewCommandInvoker>)
  - [func \(ci \*CommandInvoker\[Req, Res\]\) Close\(\)](<#CommandInvoker[Req, Res].Close>)
  - [func \(ci \*CommandInvoker\[Req, Res\]\) Invoke\(ctx context.Context, req Req, opt ...InvokeOption\) \(res \*CommandResponse\[Res\], err error\)](<#CommandInvoker[Req, Res].Invoke>)
  - [func \(ci \*CommandInvoker\[Req, Res\]\) Start\(ctx context.Context\) error](<#CommandInvoker[Req, Res].Start>)
- [type CommandInvokerOption](<#CommandInvokerOption>)
- [type CommandInvokerOptions](<#CommandInvokerOptions>)
  - [func \(o \*CommandInvokerOptions\) Apply\(opts \[\]CommandInvokerOption, rest ...CommandInvokerOption\)](<#CommandInvokerOptions.Apply>)
  - [func \(o \*CommandInvokerOptions\) ApplyOptions\(opts \[\]Option, rest ...Option\)](<#CommandInvokerOptions.ApplyOptions>)
- [type CommandRequest](<#CommandRequest>)
- [type CommandResponse](<#CommandResponse>)
  - [func Respond\[Res any\]\(payload Res, opt ...RespondOption\) \(\*CommandResponse\[Res\], error\)](<#Respond>)
- [type Custom](<#Custom>)
  - [func \(Custom\) Deserialize\(data \*Data\) \(Data, error\)](<#Custom.Deserialize>)
  - [func \(Custom\) Serialize\(t Data\) \(\*Data, error\)](<#Custom.Serialize>)
- [type Data](<#Data>)
- [type Empty](<#Empty>)
  - [func \(Empty\) Deserialize\(data \*Data\) \(any, error\)](<#Empty.Deserialize>)
  - [func \(Empty\) Serialize\(t any\) \(\*Data, error\)](<#Empty.Serialize>)
- [type Encoding](<#Encoding>)
- [type InvokeOption](<#InvokeOption>)
- [type InvokeOptions](<#InvokeOptions>)
  - [func \(o \*InvokeOptions\) Apply\(opts \[\]InvokeOption, rest ...InvokeOption\)](<#InvokeOptions.Apply>)
- [type JSON](<#JSON>)
  - [func \(JSON\[T\]\) Deserialize\(data \*Data\) \(T, error\)](<#JSON[T].Deserialize>)
  - [func \(JSON\[T\]\) Serialize\(t T\) \(\*Data, error\)](<#JSON[T].Serialize>)
- [type Listener](<#Listener>)
- [type Listeners](<#Listeners>)
  - [func \(ls Listeners\) Close\(\)](<#Listeners.Close>)
  - [func \(ls Listeners\) Start\(ctx context.Context\) error](<#Listeners.Start>)
- [type Message](<#Message>)
- [type MqttClient](<#MqttClient>)
- [type Option](<#Option>)
- [type Raw](<#Raw>)
  - [func \(Raw\) Deserialize\(data \*Data\) \(\[\]byte, error\)](<#Raw.Deserialize>)
  - [func \(Raw\) Serialize\(t \[\]byte\) \(\*Data, error\)](<#Raw.Serialize>)
- [type RespondOption](<#RespondOption>)
- [type RespondOptions](<#RespondOptions>)
  - [func \(o \*RespondOptions\) Apply\(opts \[\]RespondOption, rest ...RespondOption\)](<#RespondOptions.Apply>)
- [type SendOption](<#SendOption>)
  - [func WithCloudEvent\(ce \*CloudEvent\) SendOption](<#WithCloudEvent>)
- [type SendOptions](<#SendOptions>)
  - [func \(o \*SendOptions\) Apply\(opts \[\]SendOption, rest ...SendOption\)](<#SendOptions.Apply>)
- [type TelemetryHandler](<#TelemetryHandler>)
- [type TelemetryMessage](<#TelemetryMessage>)
- [type TelemetryReceiver](<#TelemetryReceiver>)
  - [func NewTelemetryReceiver\[T any\]\(app \*Application, client MqttClient, encoding Encoding\[T\], topicPattern string, handler TelemetryHandler\[T\], opt ...TelemetryReceiverOption\) \(tr \*TelemetryReceiver\[T\], err error\)](<#NewTelemetryReceiver>)
  - [func \(tr \*TelemetryReceiver\[T\]\) Close\(\)](<#TelemetryReceiver[T].Close>)
  - [func \(tr \*TelemetryReceiver\[T\]\) Start\(ctx context.Context\) error](<#TelemetryReceiver[T].Start>)
- [type TelemetryReceiverOption](<#TelemetryReceiverOption>)
- [type TelemetryReceiverOptions](<#TelemetryReceiverOptions>)
  - [func \(o \*TelemetryReceiverOptions\) Apply\(opts \[\]TelemetryReceiverOption, rest ...TelemetryReceiverOption\)](<#TelemetryReceiverOptions.Apply>)
  - [func \(o \*TelemetryReceiverOptions\) ApplyOptions\(opts \[\]Option, rest ...Option\)](<#TelemetryReceiverOptions.ApplyOptions>)
- [type TelemetrySender](<#TelemetrySender>)
  - [func NewTelemetrySender\[T any\]\(app \*Application, client MqttClient, encoding Encoding\[T\], topicPattern string, opt ...TelemetrySenderOption\) \(ts \*TelemetrySender\[T\], err error\)](<#NewTelemetrySender>)
  - [func \(ts \*TelemetrySender\[T\]\) Send\(ctx context.Context, val T, opt ...SendOption\) \(err error\)](<#TelemetrySender[T].Send>)
- [type TelemetrySenderOption](<#TelemetrySenderOption>)
- [type TelemetrySenderOptions](<#TelemetrySenderOptions>)
  - [func \(o \*TelemetrySenderOptions\) Apply\(opts \[\]TelemetrySenderOption, rest ...TelemetrySenderOption\)](<#TelemetrySenderOptions.Apply>)
  - [func \(o \*TelemetrySenderOptions\) ApplyOptions\(opts \[\]Option, rest ...Option\)](<#TelemetrySenderOptions.ApplyOptions>)
- [type WithConcurrency](<#WithConcurrency>)
- [type WithFencingToken](<#WithFencingToken>)
- [type WithIdempotent](<#WithIdempotent>)
- [type WithManualAck](<#WithManualAck>)
- [type WithMaxClockDrift](<#WithMaxClockDrift>)
- [type WithMetadata](<#WithMetadata>)
- [type WithPersist](<#WithPersist>)
- [type WithResponseTopicPattern](<#WithResponseTopicPattern>)
- [type WithResponseTopicPrefix](<#WithResponseTopicPrefix>)
- [type WithResponseTopicSuffix](<#WithResponseTopicSuffix>)
- [type WithRetain](<#WithRetain>)
- [type WithShareName](<#WithShareName>)
- [type WithTimeout](<#WithTimeout>)
- [type WithTopicNamespace](<#WithTopicNamespace>)
- [type WithTopicTokenNamespace](<#WithTopicTokenNamespace>)
- [type WithTopicTokens](<#WithTopicTokens>)


## Constants

<a name="DefaultCloudEventSpecVersion"></a>

```go
const (
    DefaultCloudEventSpecVersion = "1.0"
    DefaultCloudEventType        = "ms.aio.telemetry"
)
```

<a name="DefaultTimeout"></a>DefaultTimeout is the timeout applied to Invoke or Send if none is specified.

```go
const DefaultTimeout = 10 * time.Second
```

## Variables

<a name="ErrUnsupportedContentType"></a>ErrUnsupportedContentType should be returned if the content type is not supported by this encoding.

```go
var ErrUnsupportedContentType = stderr.New("unsupported content type")
```

<a name="Must"></a>
## func [Must](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/util.go#L7>)

```go
func Must[T any](t T, e error) T
```

Must ensures an object is created, or panics on error. Used to create global instances, e.g. of an Application state.

<a name="WithLogger"></a>
## func [WithLogger](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L191-L198>)

```go
func WithLogger(logger *slog.Logger) interface {
    Option
    ApplicationOption
    CommandExecutorOption
    CommandInvokerOption
    TelemetryReceiverOption
    TelemetrySenderOption
}
```

WithLogger enables logging with the provided slog logger.

<a name="Application"></a>
## type [Application](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L15-L18>)

Application represents shared application state.

```go
type Application struct {
    // contains filtered or unexported fields
}
```

<a name="NewApplication"></a>
### func [NewApplication](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L36>)

```go
func NewApplication(opt ...ApplicationOption) (*Application, error)
```

NewApplication creates a new shared application state. Only one of these should be created per application.

<a name="Application.GetHLC"></a>
### func \(\*Application\) [GetHLC](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L49>)

```go
func (a *Application) GetHLC() (hlc.HybridLogicalClock, error)
```

GetHLC syncs the application HLC instance to the current time and returns it.

<a name="Application.SetHLC"></a>
### func \(\*Application\) [SetHLC](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L54>)

```go
func (a *Application) SetHLC(val hlc.HybridLogicalClock) error
```

SetHLC syncs the application HLC instance to the given HLC.

<a name="ApplicationOption"></a>
## type [ApplicationOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L21>)

ApplicationOption represents a single application option.

```go
type ApplicationOption interface {
    // contains filtered or unexported methods
}
```

<a name="ApplicationOptions"></a>
## type [ApplicationOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L24-L27>)

ApplicationOptions are the resolved application options.

```go
type ApplicationOptions struct {
    MaxClockDrift time.Duration
    Logger        *slog.Logger
}
```

<a name="ApplicationOptions.Apply"></a>
### func \(\*ApplicationOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L59-L62>)

```go
func (o *ApplicationOptions) Apply(opts []ApplicationOption, rest ...ApplicationOption)
```

Apply resolves the provided list of options.

<a name="CloudEvent"></a>
## type [CloudEvent](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_cloud_event.go#L19-L29>)

CloudEvent provides an implementation of the CloudEvents 1.0 spec; see: https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md

```go
type CloudEvent struct {
    ID          string
    Source      *url.URL
    SpecVersion string
    Type        string

    DataContentType string
    DataSchema      *url.URL
    Subject         string
    Time            time.Time
}
```

<a name="CloudEventFromTelemetry"></a>
### func [CloudEventFromTelemetry](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_cloud_event.go#L195-L197>)

```go
func CloudEventFromTelemetry[T any](msg *TelemetryMessage[T]) (*CloudEvent, error)
```

CloudEventFromTelemetry extracts cloud event data from the given telemetry message. It will return an error if any required properties are missing or any properties do not match the expected schema.

<a name="CloudEvent.Attrs"></a>
### func \(\*CloudEvent\) [Attrs](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_cloud_event.go#L61>)

```go
func (ce *CloudEvent) Attrs() []slog.Attr
```

Attrs returns additional attributes for slog.

<a name="CommandExecutor"></a>
## type [CommandExecutor](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L26-L33>)

CommandExecutor provides the ability to execute a single command.

```go
type CommandExecutor[Req any, Res any] struct {
    // contains filtered or unexported fields
}
```

<a name="NewCommandExecutor"></a>
### func [NewCommandExecutor](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L89-L97>)

```go
func NewCommandExecutor[Req, Res any](app *Application, client MqttClient, requestEncoding Encoding[Req], responseEncoding Encoding[Res], requestTopicPattern string, handler CommandHandler[Req, Res], opt ...CommandExecutorOption) (ce *CommandExecutor[Req, Res], err error)
```

NewCommandExecutor creates a new command executor.

<a name="CommandExecutor[Req, Res].Close"></a>
### func \(\*CommandExecutor\[Req, Res\]\) [Close](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L176>)

```go
func (ce *CommandExecutor[Req, Res]) Close()
```

Close the command executor to free its resources.

<a name="CommandExecutor[Req, Res].Start"></a>
### func \(\*CommandExecutor\[Req, Res\]\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L171>)

```go
func (ce *CommandExecutor[Req, Res]) Start(ctx context.Context) error
```

Start listening to the MQTT request topic.

<a name="CommandExecutorOption"></a>
## type [CommandExecutorOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L36>)

CommandExecutorOption represents a single command executor option.

```go
type CommandExecutorOption interface {
    // contains filtered or unexported methods
}
```

<a name="CommandExecutorOptions"></a>
## type [CommandExecutorOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L39-L49>)

CommandExecutorOptions are the resolved command executor options.

```go
type CommandExecutorOptions struct {
    Idempotent bool

    Concurrency uint
    Timeout     time.Duration
    ShareName   string

    TopicNamespace string
    TopicTokens    map[string]string
    Logger         *slog.Logger
}
```

<a name="CommandExecutorOptions.Apply"></a>
### func \(\*CommandExecutorOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L425-L428>)

```go
func (o *CommandExecutorOptions) Apply(opts []CommandExecutorOption, rest ...CommandExecutorOption)
```

Apply resolves the provided list of options.

<a name="CommandExecutorOptions.ApplyOptions"></a>
### func \(\*CommandExecutorOptions\) [ApplyOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L435>)

```go
func (o *CommandExecutorOptions) ApplyOptions(opts []Option, rest ...Option)
```

ApplyOptions filters and resolves the provided list of options.

<a name="CommandHandler"></a>
## type [CommandHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L54-L57>)

CommandHandler is the user\-provided implementation of a single command execution. It is treated as blocking; all parallelism is handled by the library. This \*must\* be thread\-safe.

```go
type CommandHandler[Req any, Res any] = func(
    context.Context,
    *CommandRequest[Req],
) (*CommandResponse[Res], error)
```

<a name="CommandInvoker"></a>
## type [CommandInvoker](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L24-L31>)

CommandInvoker provides the ability to invoke a single command.

```go
type CommandInvoker[Req any, Res any] struct {
    // contains filtered or unexported fields
}
```

<a name="NewCommandInvoker"></a>
### func [NewCommandInvoker](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L92-L99>)

```go
func NewCommandInvoker[Req, Res any](app *Application, client MqttClient, requestEncoding Encoding[Req], responseEncoding Encoding[Res], requestTopicPattern string, opt ...CommandInvokerOption) (ci *CommandInvoker[Req, Res], err error)
```

NewCommandInvoker creates a new command invoker.

<a name="CommandInvoker[Req, Res].Close"></a>
### func \(\*CommandInvoker\[Req, Res\]\) [Close](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L209>)

```go
func (ci *CommandInvoker[Req, Res]) Close()
```

Close the command invoker to free its resources.

<a name="CommandInvoker[Req, Res].Invoke"></a>
### func \(\*CommandInvoker\[Req, Res\]\) [Invoke](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L216-L220>)

```go
func (ci *CommandInvoker[Req, Res]) Invoke(ctx context.Context, req Req, opt ...InvokeOption) (res *CommandResponse[Res], err error)
```

Invoke calls the command. This call will block until the command returns; any desired parallelism between invocations should be handled by the caller using normal Go constructs.

<a name="CommandInvoker[Req, Res].Start"></a>
### func \(\*CommandInvoker\[Req, Res\]\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L204>)

```go
func (ci *CommandInvoker[Req, Res]) Start(ctx context.Context) error
```

Start listening to the response topic\(s\). Must be called before any calls to Invoke.

<a name="CommandInvokerOption"></a>
## type [CommandInvokerOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L34>)

CommandInvokerOption represents a single command invoker option.

```go
type CommandInvokerOption interface {
    // contains filtered or unexported methods
}
```

<a name="CommandInvokerOptions"></a>
## type [CommandInvokerOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L37-L45>)

CommandInvokerOptions are the resolved command invoker options.

```go
type CommandInvokerOptions struct {
    ResponseTopicPattern string
    ResponseTopicPrefix  string
    ResponseTopicSuffix  string

    TopicNamespace string
    TopicTokens    map[string]string
    Logger         *slog.Logger
}
```

<a name="CommandInvokerOptions.Apply"></a>
### func \(\*CommandInvokerOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L374-L377>)

```go
func (o *CommandInvokerOptions) Apply(opts []CommandInvokerOption, rest ...CommandInvokerOption)
```

Apply resolves the provided list of options.

<a name="CommandInvokerOptions.ApplyOptions"></a>
### func \(\*CommandInvokerOptions\) [ApplyOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L384>)

```go
func (o *CommandInvokerOptions) ApplyOptions(opts []Option, rest ...Option)
```

ApplyOptions filters and resolves the provided list of options.

<a name="CommandRequest"></a>
## type [CommandRequest](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L61-L63>)

CommandRequest contains per\-message data and methods that are exposed to the command handlers.

```go
type CommandRequest[Req any] struct {
    // contains filtered or unexported fields
}
```

<a name="CommandResponse"></a>
## type [CommandResponse](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L67-L69>)

CommandResponse contains per\-message data and methods that are returned by the command handlers.

```go
type CommandResponse[Res any] struct {
    // contains filtered or unexported fields
}
```

<a name="Respond"></a>
### func [Respond](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L411-L414>)

```go
func Respond[Res any](payload Res, opt ...RespondOption) (*CommandResponse[Res], error)
```

Respond is a shorthand to create a command response with required values and options set appropriately. Note that the response may be incomplete and will be filled out by the library after being returned.

<a name="Custom"></a>
## type [Custom](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L40>)

Custom represents data that is externally serialized into a byte stream via custom code.

```go
type Custom struct{}
```

<a name="Custom.Deserialize"></a>
### func \(Custom\) [Deserialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L171>)

```go
func (Custom) Deserialize(data *Data) (Data, error)
```

Deserialize returns the data unchanged.

<a name="Custom.Serialize"></a>
### func \(Custom\) [Serialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L166>)

```go
func (Custom) Serialize(t Data) (*Data, error)
```

Serialize returns the data unchanged.

<a name="Data"></a>
## type [Data](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L24-L28>)

Data represents encoded values along with their transmitted content type.

```go
type Data struct {
    Payload       []byte
    ContentType   string
    PayloadFormat byte
}
```

<a name="Empty"></a>
## type [Empty](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L34>)

Empty represents an encoding that contains no value.

```go
type Empty struct{}
```

<a name="Empty.Deserialize"></a>
### func \(Empty\) [Deserialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L138>)

```go
func (Empty) Deserialize(data *Data) (any, error)
```

Deserialize validates that the payload is empty.

<a name="Empty.Serialize"></a>
### func \(Empty\) [Serialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L127>)

```go
func (Empty) Serialize(t any) (*Data, error)
```

Serialize validates that the payload is empty.

<a name="Encoding"></a>
## type [Encoding](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L18-L21>)

Encoding is a translation between a concrete Go type T and encoded data. All methods \*must\* be thread\-safe.

```go
type Encoding[T any] interface {
    Serialize(T) (*Data, error)
    Deserialize(*Data) (T, error)
}
```

<a name="InvokeOption"></a>
## type [InvokeOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L48>)

InvokeOption represent a single per\-invoke option.

```go
type InvokeOption interface {
    // contains filtered or unexported methods
}
```

<a name="InvokeOptions"></a>
## type [InvokeOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L51-L55>)

InvokeOptions are the resolved per\-invoke options.

```go
type InvokeOptions struct {
    Timeout     time.Duration
    TopicTokens map[string]string
    Metadata    map[string]string
}
```

<a name="InvokeOptions.Apply"></a>
### func \(\*InvokeOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L417-L420>)

```go
func (o *InvokeOptions) Apply(opts []InvokeOption, rest ...InvokeOption)
```

Apply resolves the provided list of options.

<a name="JSON"></a>
## type [JSON](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L31>)

JSON is a simple implementation of a JSON encoding.

```go
type JSON[T any] struct{}
```

<a name="JSON[T].Deserialize"></a>
### func \(JSON\[T\]\) [Deserialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L117>)

```go
func (JSON[T]) Deserialize(data *Data) (T, error)
```

Deserialize translates JSON bytes into the Go type T.

<a name="JSON[T].Serialize"></a>
### func \(JSON\[T\]\) [Serialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L104>)

```go
func (JSON[T]) Serialize(t T) (*Data, error)
```

Serialize translates the Go type T into JSON bytes.

<a name="Listener"></a>
## type [Listener](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/listener.go#L23-L26>)

Listener represents an object which will listen to a MQTT topic.

```go
type Listener interface {
    Start(context.Context) error
    Close()
}
```

<a name="Listeners"></a>
## type [Listeners](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/listener.go#L29>)

Listeners represents a collection of MQTT listeners.

```go
type Listeners []Listener
```

<a name="Listeners.Close"></a>
### func \(Listeners\) [Close](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/listener.go#L226>)

```go
func (ls Listeners) Close()
```

Close all underlying MQTT topics and free resources.

<a name="Listeners.Start"></a>
### func \(Listeners\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/listener.go#L216>)

```go
func (ls Listeners) Start(ctx context.Context) error
```

Start listening to all underlying MQTT topics.

<a name="Message"></a>
## type [Message](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/types.go#L36-L61>)

Message contains common message data that is exposed to message handlers.

```go
type Message[T any] struct {
    // The message payload.
    Payload T

    // The ID of the calling MQTT client. This field is optional and should
    // be treated as purely informational; a required client ID (especially
    // for auth purposes) should be included in the topic.
    ClientID string

    // The data that identifies a single unique request. This field is
    // optional for telemetry.
    CorrelationData string

    // The timestamp of when the message was sent. This field is optional
    // and will be set to the zero value if unsent.
    Timestamp hlc.HybridLogicalClock

    // Any topic tokens resolved from the incoming topic.
    TopicTokens map[string]string

    // Any user-provided metadata values.
    Metadata map[string]string

    // The raw payload data.
    *Data
}
```

<a name="MqttClient"></a>
## type [MqttClient](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/types.go#L14-L33>)

MqttClient is the client used for the underlying MQTT connection.

```go
type MqttClient interface {
    ID() string
    Publish(
        context.Context,
        string,
        []byte,
        ...mqtt.PublishOption,
    ) (*mqtt.Ack, error)
    RegisterMessageHandler(mqtt.MessageHandler) func()
    Subscribe(
        context.Context,
        string,
        ...mqtt.SubscribeOption,
    ) (*mqtt.Ack, error)
    Unsubscribe(
        context.Context,
        string,
        ...mqtt.UnsubscribeOption,
    ) (*mqtt.Ack, error)
}
```

<a name="Option"></a>
## type [Option](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/types.go#L65>)

Option represents any of the option types, and can be filtered and applied by the ApplyOptions methods on the option structs.

```go
type Option interface {
    // contains filtered or unexported methods
}
```

<a name="Raw"></a>
## type [Raw](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L37>)

Raw represents a raw byte stream.

```go
type Raw struct{}
```

<a name="Raw.Deserialize"></a>
### func \(Raw\) [Deserialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L158>)

```go
func (Raw) Deserialize(data *Data) ([]byte, error)
```

Deserialize returns the bytes unchanged.

<a name="Raw.Serialize"></a>
### func \(Raw\) [Serialize](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/encoding.go#L149>)

```go
func (Raw) Serialize(t []byte) (*Data, error)
```

Serialize returns the bytes unchanged.

<a name="RespondOption"></a>
## type [RespondOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L75>)

RespondOption represent a single per\-response option.

```go
type RespondOption interface {
    // contains filtered or unexported methods
}
```

<a name="RespondOptions"></a>
## type [RespondOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L78-L80>)

RespondOptions are the resolved per\-response options.

```go
type RespondOptions struct {
    Metadata map[string]string
}
```

<a name="RespondOptions.Apply"></a>
### func \(\*RespondOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L456-L459>)

```go
func (o *RespondOptions) Apply(opts []RespondOption, rest ...RespondOption)
```

Apply resolves the provided list of options.

<a name="SendOption"></a>
## type [SendOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L37>)

SendOption represent a single per\-send option.

```go
type SendOption interface {
    // contains filtered or unexported methods
}
```

<a name="WithCloudEvent"></a>
### func [WithCloudEvent](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L212>)

```go
func WithCloudEvent(ce *CloudEvent) SendOption
```

WithCloudEvent adds a cloud event payload to the telemetry message.

<a name="SendOptions"></a>
## type [SendOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L40-L48>)

SendOptions are the resolved per\-send options.

```go
type SendOptions struct {
    CloudEvent *CloudEvent
    Retain     bool
    Persist    bool

    Timeout     time.Duration
    TopicTokens map[string]string
    Metadata    map[string]string
}
```

<a name="SendOptions.Apply"></a>
### func \(\*SendOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L188-L191>)

```go
func (o *SendOptions) Apply(opts []SendOption, rest ...SendOption)
```

Apply resolves the provided list of options.

<a name="TelemetryHandler"></a>
## type [TelemetryHandler](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L52>)

TelemetryHandler is the user\-provided implementation of a single telemetry event handler. It is treated as blocking; all parallelism is handled by the library. This \*must\* be thread\-safe.

```go
type TelemetryHandler[T any] = func(context.Context, *TelemetryMessage[T]) error
```

<a name="TelemetryMessage"></a>
## type [TelemetryMessage](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L56-L63>)

TelemetryMessage contains per\-message data and methods that are exposed to the telemetry handlers.

```go
type TelemetryMessage[T any] struct {

    // Ack provides a function to manually ack if enabled and if possible;
    // it will be nil otherwise. Note that, since QoS 0 messages cannot be
    // acked, this will be nil in this case even if manual ack is enabled.
    Ack func()
    // contains filtered or unexported fields
}
```

<a name="TelemetryReceiver"></a>
## type [TelemetryReceiver](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L23-L29>)

TelemetryReceiver provides the ability to handle the receipt of a single telemetry.

```go
type TelemetryReceiver[T any] struct {
    // contains filtered or unexported fields
}
```

<a name="NewTelemetryReceiver"></a>
### func [NewTelemetryReceiver](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L76-L83>)

```go
func NewTelemetryReceiver[T any](app *Application, client MqttClient, encoding Encoding[T], topicPattern string, handler TelemetryHandler[T], opt ...TelemetryReceiverOption) (tr *TelemetryReceiver[T], err error)
```

NewTelemetryReceiver creates a new telemetry receiver.

<a name="TelemetryReceiver[T].Close"></a>
### func \(\*TelemetryReceiver\[T\]\) [Close](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L154>)

```go
func (tr *TelemetryReceiver[T]) Close()
```

Close the telemetry receiver to free its resources.

<a name="TelemetryReceiver[T].Start"></a>
### func \(\*TelemetryReceiver\[T\]\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L149>)

```go
func (tr *TelemetryReceiver[T]) Start(ctx context.Context) error
```

Start listening to the MQTT telemetry topic.

<a name="TelemetryReceiverOption"></a>
## type [TelemetryReceiverOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L32-L34>)

TelemetryReceiverOption represents a single telemetry receiver option.

```go
type TelemetryReceiverOption interface {
    // contains filtered or unexported methods
}
```

<a name="TelemetryReceiverOptions"></a>
## type [TelemetryReceiverOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L37-L47>)

TelemetryReceiverOptions are the resolved telemetry receiver options.

```go
type TelemetryReceiverOptions struct {
    ManualAck bool

    Concurrency uint
    Timeout     time.Duration
    ShareName   string

    TopicNamespace string
    TopicTokens    map[string]string
    Logger         *slog.Logger
}
```

<a name="TelemetryReceiverOptions.Apply"></a>
### func \(\*TelemetryReceiverOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L262-L265>)

```go
func (o *TelemetryReceiverOptions) Apply(opts []TelemetryReceiverOption, rest ...TelemetryReceiverOption)
```

Apply resolves the provided list of options.

<a name="TelemetryReceiverOptions.ApplyOptions"></a>
### func \(\*TelemetryReceiverOptions\) [ApplyOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L272>)

```go
func (o *TelemetryReceiverOptions) ApplyOptions(opts []Option, rest ...Option)
```

ApplyOptions filters and resolves the provided list of options.

<a name="TelemetrySender"></a>
## type [TelemetrySender](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L19-L22>)

TelemetrySender provides the ability to send a single telemetry.

```go
type TelemetrySender[T any] struct {
    // contains filtered or unexported fields
}
```

<a name="NewTelemetrySender"></a>
### func [NewTelemetrySender](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L66-L72>)

```go
func NewTelemetrySender[T any](app *Application, client MqttClient, encoding Encoding[T], topicPattern string, opt ...TelemetrySenderOption) (ts *TelemetrySender[T], err error)
```

NewTelemetrySender creates a new telemetry sender.

<a name="TelemetrySender[T].Send"></a>
### func \(\*TelemetrySender\[T\]\) [Send](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L111-L115>)

```go
func (ts *TelemetrySender[T]) Send(ctx context.Context, val T, opt ...SendOption) (err error)
```

Send emits the telemetry. This will block until the message is ack'd.

<a name="TelemetrySenderOption"></a>
## type [TelemetrySenderOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L25-L27>)

TelemetrySenderOption represents a single telemetry sender option.

```go
type TelemetrySenderOption interface {
    // contains filtered or unexported methods
}
```

<a name="TelemetrySenderOptions"></a>
## type [TelemetrySenderOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L30-L34>)

TelemetrySenderOptions are the resolved telemetry sender options.

```go
type TelemetrySenderOptions struct {
    TopicNamespace string
    TopicTokens    map[string]string
    Logger         *slog.Logger
}
```

<a name="TelemetrySenderOptions.Apply"></a>
### func \(\*TelemetrySenderOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L163-L166>)

```go
func (o *TelemetrySenderOptions) Apply(opts []TelemetrySenderOption, rest ...TelemetrySenderOption)
```

Apply resolves the provided list of options.

<a name="TelemetrySenderOptions.ApplyOptions"></a>
### func \(\*TelemetrySenderOptions\) [ApplyOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L173>)

```go
func (o *TelemetrySenderOptions) ApplyOptions(opts []Option, rest ...Option)
```

ApplyOptions filters and resolves the provided list of options.

<a name="WithConcurrency"></a>
## type [WithConcurrency](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L13>)

WithConcurrency indicates how many handlers can execute in parallel.

```go
type WithConcurrency uint
```

<a name="WithFencingToken"></a>
## type [WithFencingToken](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L70>)

WithFencingToken provides a fencing token to be used by the executor.

```go
type WithFencingToken hlc.HybridLogicalClock
```

<a name="WithIdempotent"></a>
## type [WithIdempotent](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_executor.go#L72>)

WithIdempotent marks the command as idempotent.

```go
type WithIdempotent bool
```

<a name="WithManualAck"></a>
## type [WithManualAck](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_receiver.go#L67>)

WithManualAck indicates that the handler is responsible for manually acking the telemetry message.

```go
type WithManualAck bool
```

<a name="WithMaxClockDrift"></a>
## type [WithMaxClockDrift](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/app.go#L31>)

WithMaxClockDrift specifies how long HLCs are allowed to drift from the wall clock before they are considered no longer valid.

```go
type WithMaxClockDrift time.Duration
```

<a name="WithMetadata"></a>
## type [WithMetadata](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L32>)

WithMetadata specifies user\-provided metadata values.

```go
type WithMetadata map[string]string
```

<a name="WithPersist"></a>
## type [WithPersist](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L57>)

WithPersist indicates that the telemetry event should be retained by the broker and stored to disk. Note that this is only useable with the AIO Broker and implies the Retain option if enabled.

```go
type WithPersist bool
```

<a name="WithResponseTopicPattern"></a>
## type [WithResponseTopicPattern](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L59>)

WithResponseTopicPattern specifies a custom response topic pattern. Note that this overrides any provided response topic prefix or suffix.

```go
type WithResponseTopicPattern string
```

<a name="WithResponseTopicPrefix"></a>
## type [WithResponseTopicPrefix](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L64>)

WithResponseTopicPrefix specifies a custom prefix for the response topic. If no response topic options are specified, this will default to a value of "clients/\<MQTT client ID\>".

```go
type WithResponseTopicPrefix string
```

<a name="WithResponseTopicSuffix"></a>
## type [WithResponseTopicSuffix](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/command_invoker.go#L67>)

WithResponseTopicSuffix specifies a custom suffix for the response topic.

```go
type WithResponseTopicSuffix string
```

<a name="WithRetain"></a>
## type [WithRetain](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/telemetry_sender.go#L52>)

WithRetain indicates that the telemetry event should be retained by the broker.

```go
type WithRetain bool
```

<a name="WithShareName"></a>
## type [WithShareName](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L20>)

WithShareName connects this listener to a shared MQTT subscription.

```go
type WithShareName string
```

<a name="WithTimeout"></a>
## type [WithTimeout](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L17>)

WithTimeout applies a context timeout to the message invocation or handler execution, as appropriate.

```go
type WithTimeout time.Duration
```

<a name="WithTopicNamespace"></a>
## type [WithTopicNamespace](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L36>)

WithTopicNamespace specifies a namespace that will be prepended to the topic.

```go
type WithTopicNamespace string
```

<a name="WithTopicTokenNamespace"></a>
## type [WithTopicTokenNamespace](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L29>)

WithTopicTokenNamespace specifies a namespace that will be prepended to all previously\-specified topic tokens. Topic tokens specified after this option will not be namespaced, allowing this to differentiate user tokens from system tokens.

```go
type WithTopicTokenNamespace string
```

<a name="WithTopicTokens"></a>
## type [WithTopicTokens](<https://github.com/Azure/iot-operations-sdks/blob/main/go/protocol/common_options.go#L23>)

WithTopicTokens specifies topic token values.

```go
type WithTopicTokens map[string]string
```

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
