no need for framer to return two values

This commit is contained in:
Joel Wetzell
2025-12-24 18:17:41 -06:00
parent 076a13f48a
commit efdcbae5c4
4 changed files with 18 additions and 22 deletions

View File

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

View File

@@ -56,10 +56,10 @@ func init() {
framingMethod = framingMethodString framingMethod = framingMethodString
} }
framer, err := framer.GetFramer(framingMethod) framer := framer.GetFramer(framingMethod)
if err != nil { if framer == nil {
return nil, err return nil, fmt.Errorf("serial.client unknown framing method: %s", framingMethod)
} }
buadRate, ok := params["baudRate"] buadRate, ok := params["baudRate"]

View File

@@ -64,15 +64,15 @@ func init() {
framingMethodString, ok := framingMethodRaw.(string) framingMethodString, ok := framingMethodRaw.(string)
if !ok { if !ok {
return nil, errors.New("misc.serial.client framing method must be a string") return nil, errors.New("net.tcp.client framing method must be a string")
} }
framingMethod = framingMethodString framingMethod = framingMethodString
} }
framer, err := framer.GetFramer(framingMethod) framer := framer.GetFramer(framingMethod)
if err != nil { if framer == nil {
return nil, err return nil, fmt.Errorf("net.tcp.client unknown framing method: %s", framingMethod)
} }
return &TCPClient{framer: framer, Addr: addr, config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil return &TCPClient{framer: framer, Addr: addr, config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil

View File

@@ -53,15 +53,15 @@ func init() {
framingMethodString, ok := framingMethodRaw.(string) framingMethodString, ok := framingMethodRaw.(string)
if !ok { if !ok {
return nil, errors.New("misc.serial.client framing method must be a string") return nil, errors.New("net.tcp.server framing method must be a string")
} }
framingMethod = framingMethodString framingMethod = framingMethodString
} }
framer, err := framer.GetFramer(framingMethod) framer := framer.GetFramer(framingMethod)
if err != nil { if framer == nil {
return nil, err return nil, fmt.Errorf("net.tcp.server unknown framing method: %s", framingMethod)
} }
ipString := "0.0.0.0" ipString := "0.0.0.0"