mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2025-04-19 20:53:45 +01:00
Compare commits
No commits in common. "e36af2c05948a334be046acb131ae420c998a71b" and "d72c6a2d17824627345a12b671886287e4550396" have entirely different histories.
e36af2c059
...
d72c6a2d17
@ -11,12 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
# [0.2.1] - 2024-11-07
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- {packet}.header() now uses a reusable buffer.
|
|
||||||
|
|
||||||
# [0.2.0] - 2024-10-27
|
# [0.2.0] - 2024-10-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
35
packet.go
35
packet.go
@ -1,7 +1,6 @@
|
|||||||
package vbantxt
|
package vbantxt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -18,24 +17,19 @@ var BpsOpts = []int{0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200,
|
|||||||
1000000, 1500000, 2000000, 3000000}
|
1000000, 1500000, 2000000, 3000000}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
streamname []byte
|
name string
|
||||||
bpsIndex int
|
bpsIndex int
|
||||||
channel int
|
channel int
|
||||||
framecounter []byte
|
framecounter []byte
|
||||||
hbuf *bytes.Buffer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newPacket returns a packet struct with default values, framecounter at 0.
|
// newPacket returns a packet struct with default values, framecounter at 0.
|
||||||
func newPacket(streamname string) packet {
|
func newPacket(streamname string) packet {
|
||||||
streamnameBuf := make([]byte, streamNameSz)
|
|
||||||
copy(streamnameBuf, streamname)
|
|
||||||
|
|
||||||
return packet{
|
return packet{
|
||||||
streamname: streamnameBuf,
|
name: streamname,
|
||||||
bpsIndex: 0,
|
bpsIndex: 0,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
framecounter: make([]byte, 4),
|
framecounter: make([]byte, 4),
|
||||||
hbuf: bytes.NewBuffer(make([]byte, headerSz)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,17 +43,24 @@ func (p *packet) nbc() byte {
|
|||||||
return byte(p.channel)
|
return byte(p.channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// streamname defines the stream name of the text request
|
||||||
|
func (p *packet) streamname() []byte {
|
||||||
|
b := make([]byte, streamNameSz)
|
||||||
|
copy(b, p.name)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// header returns a fully formed packet header
|
// header returns a fully formed packet header
|
||||||
func (p *packet) header() []byte {
|
func (p *packet) header() []byte {
|
||||||
p.hbuf.Reset()
|
h := make([]byte, 0, headerSz)
|
||||||
p.hbuf.WriteString("VBAN")
|
h = append(h, []byte("VBAN")...)
|
||||||
p.hbuf.WriteByte(p.sr())
|
h = append(h, p.sr())
|
||||||
p.hbuf.WriteByte(byte(0))
|
h = append(h, byte(0))
|
||||||
p.hbuf.WriteByte(p.nbc())
|
h = append(h, p.nbc())
|
||||||
p.hbuf.WriteByte(byte(0x10))
|
h = append(h, byte(0x10))
|
||||||
p.hbuf.Write(p.streamname)
|
h = append(h, p.streamname()...)
|
||||||
p.hbuf.Write(p.framecounter)
|
h = append(h, p.framecounter...)
|
||||||
return p.hbuf.Bytes()
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// bumpFrameCounter increments the frame counter by 1
|
// bumpFrameCounter increments the frame counter by 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user