diff options
| author | 2026-03-06 13:01:12 +0800 | |
|---|---|---|
| committer | 2026-03-06 13:57:57 +0800 | |
| commit | 3307715a8d8bdeac1b2d7df66ec2abb6e503ba9a (patch) | |
| tree | 4505d11668a6160aa0b04f38811f7a0a721b5db0 /format/pktline/errors.go | |
| parent | *: go fix ./... (diff) | |
| signature | No signature | |
format/pktline: Add pktline v0.1.62
Diffstat (limited to 'format/pktline/errors.go')
| -rw-r--r-- | format/pktline/errors.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/format/pktline/errors.go b/format/pktline/errors.go new file mode 100644 index 00000000..d07227e6 --- /dev/null +++ b/format/pktline/errors.go @@ -0,0 +1,34 @@ +package pktline + +import ( + "errors" + "fmt" +) + +var ( + // ErrInvalidLength indicates a malformed 4-byte hexadecimal length header. + ErrInvalidLength = errors.New("pktline: invalid length header") + // ErrTooLarge indicates a payload exceeds configured packet data limits. + ErrTooLarge = errors.New("pktline: payload too large") +) + +// ProtocolError reports invalid pkt-line framing. +// +// It is returned for protocol violations such as invalid control values +// (for example 0003) or non-hex length headers. +type ProtocolError struct { + Header [4]byte + Reason string +} + +func (e *ProtocolError) Error() string { + if e == nil { + return "<nil>" + } + + if e.Reason == "" { + return "pktline: protocol error" + } + + return fmt.Sprintf("pktline: protocol error: %s", e.Reason) +} |
