mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
add the concept of routes input/output
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package framing
|
||||
|
||||
type Framer interface {
|
||||
Frame([]byte) [][]byte
|
||||
Decode([]byte) [][]byte
|
||||
Encode([]byte) []byte
|
||||
Clear()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func NewByteSeparatorFramer(separator []byte) *ByteSeparatorFramer {
|
||||
return &ByteSeparatorFramer{separator: separator, buffer: []byte{}}
|
||||
}
|
||||
|
||||
func (bsf *ByteSeparatorFramer) Frame(data []byte) [][]byte {
|
||||
func (bsf *ByteSeparatorFramer) Decode(data []byte) [][]byte {
|
||||
messages := [][]byte{}
|
||||
|
||||
bsf.buffer = append(bsf.buffer, data...)
|
||||
@@ -28,6 +28,10 @@ func (bsf *ByteSeparatorFramer) Frame(data []byte) [][]byte {
|
||||
return messages
|
||||
}
|
||||
|
||||
func (bsf *ByteSeparatorFramer) Encode(data []byte) []byte {
|
||||
return append(data, bsf.separator...)
|
||||
}
|
||||
|
||||
func (bsf *ByteSeparatorFramer) Clear() {
|
||||
bsf.buffer = []byte{}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ func NewSlipFramer() *SlipFramer {
|
||||
return &SlipFramer{buffer: []byte{}}
|
||||
}
|
||||
|
||||
func (sf *SlipFramer) Frame(data []byte) [][]byte {
|
||||
func (sf *SlipFramer) Decode(data []byte) [][]byte {
|
||||
messages := [][]byte{}
|
||||
|
||||
END := byte(0xc0)
|
||||
ESC := byte(0xdb)
|
||||
ESC_END := byte(0xdc)
|
||||
@@ -47,6 +48,29 @@ func (sf *SlipFramer) Frame(data []byte) [][]byte {
|
||||
return messages
|
||||
}
|
||||
|
||||
func (sf *SlipFramer) Encode(data []byte) []byte {
|
||||
END := byte(0xc0)
|
||||
ESC := byte(0xdb)
|
||||
ESC_END := byte(0xdc)
|
||||
ESC_ESC := byte(0xdd)
|
||||
|
||||
var encodedBytes = []byte{END}
|
||||
|
||||
for _, byteToEncode := range data {
|
||||
switch byteToEncode {
|
||||
case END:
|
||||
encodedBytes = append(encodedBytes, ESC_END)
|
||||
case ESC:
|
||||
encodedBytes = append(encodedBytes, ESC_ESC)
|
||||
default:
|
||||
encodedBytes = append(encodedBytes, byteToEncode)
|
||||
}
|
||||
}
|
||||
|
||||
encodedBytes = append(encodedBytes, END)
|
||||
return encodedBytes
|
||||
}
|
||||
|
||||
func (sf *SlipFramer) Clear() {
|
||||
sf.buffer = []byte{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user