feat: add KISS protocol escape functions in new kiss.go interface
This commit is contained in:
25
pkg/interfaces/kiss.go
Normal file
25
pkg/interfaces/kiss.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// SPDX-License-Identifier: 0BSD
|
||||||
|
// Copyright (c) 2024-2026 Sudo-Ivan / Quad4.io
|
||||||
|
package interfaces
|
||||||
|
|
||||||
|
const (
|
||||||
|
KISS_FEND = 0xC0
|
||||||
|
KISS_FESC = 0xDB
|
||||||
|
KISS_TFEND = 0xDC
|
||||||
|
KISS_TFESC = 0xDD
|
||||||
|
)
|
||||||
|
|
||||||
|
func escapeKISS(data []byte) []byte {
|
||||||
|
escaped := make([]byte, 0, len(data)*2)
|
||||||
|
for _, b := range data {
|
||||||
|
if b == KISS_FEND {
|
||||||
|
escaped = append(escaped, KISS_FESC, KISS_TFEND)
|
||||||
|
} else if b == KISS_FESC {
|
||||||
|
escaped = append(escaped, KISS_FESC, KISS_TFESC)
|
||||||
|
} else {
|
||||||
|
escaped = append(escaped, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user