mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 21:35:30 +00:00
30 lines
577 B
Go
30 lines
577 B
Go
package framer
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type Framer interface {
|
|
Decode([]byte) [][]byte
|
|
Encode([]byte) []byte
|
|
Clear()
|
|
Buffer() []byte
|
|
}
|
|
|
|
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
|
|
case "RAW":
|
|
return NewRawFramer(), nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown framing method: %s", framingType)
|
|
}
|
|
}
|