Files
pig-farm-controller/internal/infra/transport/transport.go
2025-10-20 19:31:19 +08:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package transport
import "time"
// Communicator 用于其他设备通信
type Communicator interface {
// Send 用于发送一条单向数据(不等待回信)
// 成功时,它返回一个包含 MessageID 的 SendResult以便调用方追踪。
Send(address string, payload []byte) (*SendResult, error)
}
// SendResult 包含了 SendGo 方法成功执行后返回的结果。
type SendResult struct {
// MessageID 是通信服务为此次发送分配的唯一标识符。
// 调用方需要保存此 ID以便后续关联 ACK 等事件。
MessageID string
// AcknowledgedAt 记录设备确认收到下行消息的时间。
// 并非所有发送实现都会同步返回收到时间
AcknowledgedAt *time.Time
// ReceivedSuccess 表示设备是否成功接收到下行消息。
// 并非所有发送实现都会同步返回是否送达
ReceivedSuccess *bool
}
// Listener 用于监听其他设备发送过来的数据
type Listener interface {
// Listen 用于开始监听其他设备发送过来的数据
Listen() error
// Stop 用于停止监听
Stop() error
}