protocol

package
v0.1.0-alpha.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MulanPSL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MagicSize 为魔数字节长度。
	MagicSize = 4
	// HeaderSize 为二进制头长度(魔数 + seq + dir)。
	HeaderSize = 9
)
View Source
const (
	DirUL uint8 = 0
	DirDL uint8 = 1
)

DirUL 与 DirDL 为数据包方向常量。

Variables

This section is empty.

Functions

func DecodePacket

func DecodePacket(data []byte) (seq uint32, dir uint8, payloadLen int, err error)

DecodePacket 解析数据包,返回 seq、dir、payload 长度(不含头)。

func EncodePacket

func EncodePacket(seq uint32, dir uint8, payloadLen int) []byte

EncodePacket 构造 UDP 负载:头 + payloadLen 字节零填充。

func EncodeStart

func EncodeStart(m StartMessage) ([]byte, error)

EncodeStart 序列化 START 消息。

func LooksLikeJSON

func LooksLikeJSON(payload []byte) bool

LooksLikeJSON 判断 UDP 负载是否为 JSON(START)消息。

Types

type StartMessage

type StartMessage struct {
	Cmd            string  `json:"cmd"`
	TestID         string  `json:"test_id"`
	DLSize         int     `json:"dl_size"`
	DLIntervalNs   int64   `json:"dl_interval_ns"`
	ULIntervalNs   int64   `json:"ul_interval_ns"`
	DurationSec    float64 `json:"duration_s"`
	TimeDeltaNs    int64   `json:"time_delta_ns"`
	ULPacketCount  int64   `json:"ul_packet_count"`
	DLPacketCount  int64   `json:"dl_packet_count"`
	PcapReplay     bool    `json:"pcap_replay,omitempty"`
	PcapPlanName   string  `json:"pcap_plan_name,omitempty"`
	ReplayAnchorNs int64   `json:"replay_anchor_unix_ns,omitempty"`
	PcapPlanSHA256 string  `json:"pcap_plan_sha256,omitempty"`
	// PcapReplaySpeed 回放时间缩放,>0;1 为原速;omitempty 时按 1 处理。
	PcapReplaySpeed float64 `json:"pcap_replay_speed,omitempty"`
}

StartMessage 为客户端发往服务端的 START JSON(见 docs/design-pulse.md)。

func DecodeStart

func DecodeStart(data []byte) (StartMessage, error)

DecodeStart 反序列化并校验 START 消息。

func (StartMessage) PcapReplayMode

func (m StartMessage) PcapReplayMode() bool

PcapReplayMode 为 true 时服务端按 plan 墙钟发 DL。

Source Files

  • packet.go
  • start.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL