move framing creation into shared place

This commit is contained in:
Joel Wetzell
2025-12-06 16:02:35 -06:00
parent 04103cc6ca
commit 4c0f7c1723
4 changed files with 35 additions and 40 deletions

View File

@@ -1,7 +1,26 @@
package framing
import (
"fmt"
)
type Framer interface {
Decode([]byte) [][]byte
Encode([]byte) []byte
Clear()
}
func GetFramer(framingType string) (Framer, error) {
switch framingType {
case "CR":
return NewByteSeparatorFramer([]byte{'\r'}), nil
case "LF":
return NewByteSeparatorFramer([]byte{'\n'}), nil
case "CRLF":
return NewByteSeparatorFramer([]byte{'\r', '\n'}), nil
case "SLIP":
return NewSlipFramer(), nil
default:
return nil, fmt.Errorf("unknown framing method: %s", framingType)
}
}