Rewrite support MPEG-TS client

This commit is contained in:
Alexey Khit
2023-08-17 05:41:27 +03:00
parent 4a82eb3503
commit b3def6cfa2
11 changed files with 569 additions and 367 deletions
+53
View File
@@ -0,0 +1,53 @@
package bits
type Writer struct {
buf []byte // total buf
byte byte // current byte
bits byte // bits left in byte
len int // current len of buf
}
func NewWriter() *Writer {
return &Writer{}
}
func (w *Writer) WriteBit(b byte) {
if w.bits == 0 {
if w.len != 0 {
w.buf = append(w.buf, w.byte)
}
w.byte = 0
w.bits = 7
w.len++
} else {
w.bits--
}
w.byte |= b << w.bits
}
func (w *Writer) WriteBits(v uint32, n byte) {
for i := n - 1; i != 255; i-- {
w.WriteBit(byte(v>>i) & 0b1)
}
}
func (w *Writer) WriteBits16(v uint16, n byte) {
for i := n - 1; i != 255; i-- {
w.WriteBit(byte(v>>i) & 0b1)
}
}
func (w *Writer) WriteBits8(v, n byte) {
for i := n - 1; i != 255; i-- {
w.WriteBit((v >> i) & 0b1)
}
}
func (w *Writer) Bytes() []byte {
if w.bits == 0 {
return w.buf
}
return append(w.buf, w.byte)
}