diff --git a/astits/main.go b/astits/main.go index 8ae645e..8a4e12e 100644 --- a/astits/main.go +++ b/astits/main.go @@ -13,9 +13,8 @@ import ( "strings" "syscall" + "github.com/asticode/go-astikit" "github.com/asticode/go-astilog" - "github.com/asticode/go-astitools/flag" - "github.com/asticode/go-astitools/io" "github.com/asticode/go-astits" "github.com/pkg/errors" "github.com/pkg/profile" @@ -25,7 +24,7 @@ import ( var ( ctx, cancel = context.WithCancel(context.Background()) cpuProfiling = flag.Bool("cp", false, "if yes, cpu profiling is enabled") - dataTypes = astiflag.NewStringsMap() + dataTypes = astikit.NewFlagStrings() format = flag.String("f", "", "the format") inputPath = flag.String("i", "", "the input path") memoryProfiling = flag.Bool("mp", false, "if yes, memory profiling is enabled") @@ -38,7 +37,8 @@ func main() { flag.PrintDefaults() } flag.Var(dataTypes, "d", "the datatypes whitelist (all, pat, pmt, pes, eit, nit, sdt, tot)") - var s = astiflag.Subcommand() + cmd := astikit.FlagCmd() + astilog.SetHandyFlags() flag.Parse() astilog.FlagInit() @@ -68,8 +68,8 @@ func main() { // Create the demuxer var dmx = astits.New(ctx, r) - // Switch on subcommand - switch s { + // Switch on command + switch cmd { case "data": // Fetch data if err = data(dmx); err != nil { @@ -117,8 +117,8 @@ func handleSignals() { switch s { case syscall.SIGABRT, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM: cancel() + return } - return } }() } @@ -154,14 +154,7 @@ func buildReader(ctx context.Context) (r io.Reader, err error) { return } c.SetReadBuffer(4096) - - // Initialize linearizer - // It will read 4096 bytes at each iteration, and will store up to 2MB in its buffer - var l = astiio.NewLinearizer(ctx, c, 4096, 2048*1024) - - // Start linearizer - go l.Start() - r = l + r = c default: // Open file var f *os.File diff --git a/data.go b/data.go index f8859f9..23aaa51 100644 --- a/data.go +++ b/data.go @@ -1,8 +1,8 @@ package astits import ( + "github.com/asticode/go-astikit" "github.com/pkg/errors" - "github.com/asticode/go-astitools/byte" ) // PIDs @@ -52,8 +52,8 @@ func parseData(ps []*Packet, prs PacketsParser, pm programMap) (ds []*Data, err c += copy(payload[c:], p.Payload) } - // Create iterator - i := astibyte.NewIterator(payload) + // Create reader + i := astikit.NewBytesIterator(payload) // Parse PID pid := ps[0].Header.PID diff --git a/data_eit.go b/data_eit.go index 21fa892..48d9dcd 100644 --- a/data_eit.go +++ b/data_eit.go @@ -3,7 +3,7 @@ package astits import ( "time" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -29,7 +29,7 @@ type EITDataEvent struct { } // parseEITSection parses an EIT section -func parseEITSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtension uint16) (d *EITData, err error) { +func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExtension uint16) (d *EITData, err error) { // Create data d = &EITData{ServiceID: tableIDExtension} @@ -108,7 +108,7 @@ func parseEITSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtensi e.HasFreeCSAMode = uint8(b&0x10) > 0 // We need to rewind since the current byte is used by the descriptor as well - i.FastForward(-1) + i.Skip(-1) // Descriptors if e.Descriptors, err = parseDescriptors(i); err != nil { diff --git a/data_eit_test.go b/data_eit_test.go index 0a76269..2b3f494 100644 --- a/data_eit_test.go +++ b/data_eit_test.go @@ -1,11 +1,11 @@ package astits import ( + "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" - "github.com/asticode/go-astitools/byte" ) var eit = &EITData{ @@ -25,7 +25,8 @@ var eit = &EITData{ } func eitBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(2)) // Transport stream ID w.Write(uint16(3)) // Original network ID w.Write(uint8(4)) // Segment last section number @@ -36,12 +37,12 @@ func eitBytes() []byte { w.Write("111") // Event #1 running status w.Write("1") // Event #1 free CA mode descriptorsBytes(w) // Event #1 descriptors - return w.Bytes() + return buf.Bytes() } func TestParseEITSection(t *testing.T) { var b = eitBytes() - d, err := parseEITSection(astibyte.NewIterator(b), len(b), uint16(1)) + d, err := parseEITSection(astikit.NewBytesIterator(b), len(b), uint16(1)) assert.Equal(t, d, eit) assert.NoError(t, err) } diff --git a/data_nit.go b/data_nit.go index ecff474..3d39d5f 100644 --- a/data_nit.go +++ b/data_nit.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -21,7 +21,7 @@ type NITDataTransportStream struct { } // parseNITSection parses a NIT section -func parseNITSection(i *astibyte.Iterator, tableIDExtension uint16) (d *NITData, err error) { +func parseNITSection(i *astikit.BytesIterator, tableIDExtension uint16) (d *NITData, err error) { // Create data d = &NITData{NetworkID: tableIDExtension} diff --git a/data_nit_test.go b/data_nit_test.go index d26cc4c..902f20d 100644 --- a/data_nit_test.go +++ b/data_nit_test.go @@ -1,10 +1,10 @@ package astits import ( + "bytes" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -19,7 +19,8 @@ var nit = &NITData{ } func nitBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("0000") // Reserved for future use descriptorsBytes(w) // Network descriptors w.Write("0000") // Reserved for future use @@ -28,12 +29,12 @@ func nitBytes() []byte { w.Write(uint16(3)) // Transport stream #1 original network id w.Write("0000") // Transport stream #1 reserved for future use descriptorsBytes(w) // Transport stream #1 descriptors - return w.Bytes() + return buf.Bytes() } func TestParseNITSection(t *testing.T) { var b = nitBytes() - d, err := parseNITSection(astibyte.NewIterator(b), uint16(1)) + d, err := parseNITSection(astikit.NewBytesIterator(b), uint16(1)) assert.Equal(t, d, nit) assert.NoError(t, err) } diff --git a/data_pat.go b/data_pat.go index eadacb5..a684a5b 100644 --- a/data_pat.go +++ b/data_pat.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -19,7 +19,7 @@ type PATProgram struct { } // parsePATSection parses a PAT section -func parsePATSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtension uint16) (d *PATData, err error) { +func parsePATSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExtension uint16) (d *PATData, err error) { // Create data d = &PATData{TransportStreamID: tableIDExtension} diff --git a/data_pat_test.go b/data_pat_test.go index c2e212c..21a5db4 100644 --- a/data_pat_test.go +++ b/data_pat_test.go @@ -1,11 +1,11 @@ package astits import ( + "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" - "github.com/asticode/go-astitools/byte" ) var pat = &PATData{ @@ -17,19 +17,20 @@ var pat = &PATData{ } func patBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(2)) // Program #1 number w.Write("111") // Program #1 reserved bits w.Write("0000000000011") // Program #1 map ID w.Write(uint16(4)) // Program #2 number w.Write("111") // Program #2 reserved bits w.Write("0000000000101") // Program #3 map ID - return w.Bytes() + return buf.Bytes() } func TestParsePATSection(t *testing.T) { var b = patBytes() - d, err := parsePATSection(astibyte.NewIterator(b), len(b), uint16(1)) + d, err := parsePATSection(astikit.NewBytesIterator(b), len(b), uint16(1)) assert.Equal(t, d, pat) assert.NoError(t, err) } diff --git a/data_pes.go b/data_pes.go index aa9236c..49f619f 100644 --- a/data_pes.go +++ b/data_pes.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -102,7 +102,7 @@ type DSMTrickMode struct { } // parsePESData parses a PES data -func parsePESData(i *astibyte.Iterator) (d *PESData, err error) { +func parsePESData(i *astikit.BytesIterator) (d *PESData, err error) { // Create data d = &PESData{} @@ -133,7 +133,7 @@ func hasPESOptionalHeader(streamID uint8) bool { } // parsePESData parses a PES header -func parsePESHeader(i *astibyte.Iterator) (h *PESHeader, dataStart, dataEnd int, err error) { +func parsePESHeader(i *astikit.BytesIterator) (h *PESHeader, dataStart, dataEnd int, err error) { // Create header h = &PESHeader{} @@ -177,7 +177,7 @@ func parsePESHeader(i *astibyte.Iterator) (h *PESHeader, dataStart, dataEnd int, } // parsePESOptionalHeader parses a PES optional header -func parsePESOptionalHeader(i *astibyte.Iterator) (h *PESOptionalHeader, dataStart int, err error) { +func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dataStart int, err error) { // Create header h = &PESOptionalHeader{} @@ -390,7 +390,7 @@ func parseDSMTrickMode(i byte) (m *DSMTrickMode) { } // parsePTSOrDTS parses a PTS or a DTS -func parsePTSOrDTS(i *astibyte.Iterator) (cr *ClockReference, err error) { +func parsePTSOrDTS(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(5); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") @@ -401,7 +401,7 @@ func parsePTSOrDTS(i *astibyte.Iterator) (cr *ClockReference, err error) { } // parseESCR parses an ESCR -func parseESCR(i *astibyte.Iterator) (cr *ClockReference, err error) { +func parseESCR(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(6); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") diff --git a/data_pes_test.go b/data_pes_test.go index c5528c0..f241904 100644 --- a/data_pes_test.go +++ b/data_pes_test.go @@ -1,10 +1,10 @@ package astits import ( + "bytes" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -24,20 +24,22 @@ var dsmTrickModeSlow = &DSMTrickMode{ } func dsmTrickModeSlowBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("001") // Control w.Write("10101") // Repeat control - return w.Bytes() + return buf.Bytes() } func TestParseDSMTrickMode(t *testing.T) { // Fast - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("011") // Control w.Write("10") // Field ID w.Write("1") // Intra slice refresh w.Write("11") // Frequency truncation - assert.Equal(t, parseDSMTrickMode(w.Bytes()[0]), &DSMTrickMode{ + assert.Equal(t, parseDSMTrickMode(buf.Bytes()[0]), &DSMTrickMode{ FieldID: 2, FrequencyTruncation: 3, IntraSliceRefresh: 1, @@ -45,11 +47,11 @@ func TestParseDSMTrickMode(t *testing.T) { }) // Freeze - w.Reset() + buf.Reset() w.Write("010") // Control w.Write("10") // Field ID w.Write("000") // Reserved - assert.Equal(t, parseDSMTrickMode(w.Bytes()[0]), &DSMTrickMode{ + assert.Equal(t, parseDSMTrickMode(buf.Bytes()[0]), &DSMTrickMode{ FieldID: 2, TrickModeControl: TrickModeControlFreezeFrame, }) @@ -61,7 +63,8 @@ func TestParseDSMTrickMode(t *testing.T) { var ptsClockReference = &ClockReference{Base: 5726623061} func ptsBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("0010") // Flag w.Write("101") // 32...30 w.Write("0") // Dummy @@ -69,13 +72,14 @@ func ptsBytes() []byte { w.Write("0") // Dummy w.Write("101010101010101") // 14...0 w.Write("0") // Dummy - return w.Bytes() + return buf.Bytes() } var dtsClockReference = &ClockReference{Base: 5726623060} func dtsBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("0010") // Flag w.Write("101") // 32...30 w.Write("0") // Dummy @@ -83,17 +87,18 @@ func dtsBytes() []byte { w.Write("0") // Dummy w.Write("101010101010100") // 14...0 w.Write("0") // Dummy - return w.Bytes() + return buf.Bytes() } func TestParsePTSOrDTS(t *testing.T) { - v, err := parsePTSOrDTS(astibyte.NewIterator(ptsBytes())) + v, err := parsePTSOrDTS(astikit.NewBytesIterator(ptsBytes())) assert.Equal(t, v, ptsClockReference) assert.NoError(t, err) } func escrBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("00") // Dummy w.Write("011") // 32...30 w.Write("1") // Dummy @@ -103,11 +108,11 @@ func escrBytes() []byte { w.Write("1") // Dummy w.Write("000111010") // Ext w.Write("1") // Dummy - return w.Bytes() + return buf.Bytes() } func TestParseESCR(t *testing.T) { - v, err := parseESCR(astibyte.NewIterator(escrBytes())) + v, err := parseESCR(astikit.NewBytesIterator(escrBytes())) assert.Equal(t, v, clockReference) assert.NoError(t, err) } @@ -121,12 +126,13 @@ var pesWithoutHeader = &PESData{ } func pesWithoutHeaderBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("000000000000000000000001") // Prefix w.Write(uint8(StreamIDPaddingStream)) // Stream ID w.Write(uint16(4)) // Packet length w.Write([]byte("datastuff")) // Data - return w.Bytes() + return buf.Bytes() } var pesWithHeader = &PESData{ @@ -175,7 +181,8 @@ var pesWithHeader = &PESData{ } func pesWithHeaderBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("000000000000000000000001") // Prefix w.Write(uint8(1)) // Stream ID w.Write(uint16(69)) // Packet length @@ -214,17 +221,17 @@ func pesWithHeaderBytes() []byte { w.Write([]byte("extension2")) // Extension 2 data w.Write([]byte("stuff")) // Optional header stuffing bytes w.Write([]byte("datastuff")) // Data - return w.Bytes() + return buf.Bytes() } func TestParsePESData(t *testing.T) { // No optional header and specific packet length - d, err := parsePESData(astibyte.NewIterator(pesWithoutHeaderBytes())) + d, err := parsePESData(astikit.NewBytesIterator(pesWithoutHeaderBytes())) assert.NoError(t, err) assert.Equal(t, pesWithoutHeader, d) // Optional header and no specific header length - d, err = parsePESData(astibyte.NewIterator(pesWithHeaderBytes())) + d, err = parsePESData(astikit.NewBytesIterator(pesWithHeaderBytes())) assert.NoError(t, err) assert.Equal(t, pesWithHeader, d) } diff --git a/data_pmt.go b/data_pmt.go index fd94ad1..6f45e86 100644 --- a/data_pmt.go +++ b/data_pmt.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -30,7 +30,7 @@ type PMTElementaryStream struct { } // parsePMTSection parses a PMT section -func parsePMTSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtension uint16) (d *PMTData, err error) { +func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExtension uint16) (d *PMTData, err error) { // Create data d = &PMTData{ProgramNumber: tableIDExtension} diff --git a/data_pmt_test.go b/data_pmt_test.go index 6a85e37..15b8423 100644 --- a/data_pmt_test.go +++ b/data_pmt_test.go @@ -1,11 +1,11 @@ package astits import ( + "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" - "github.com/asticode/go-astitools/byte" ) var pmt = &PMTData{ @@ -20,7 +20,8 @@ var pmt = &PMTData{ } func pmtBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("111") // Reserved bits w.Write("1010101010101") // PCR PID w.Write("1111") // Reserved @@ -30,12 +31,12 @@ func pmtBytes() []byte { w.Write("0101010101010") // Stream #1 PID w.Write("1111") // Stream #1 reserved descriptorsBytes(w) // Stream #1 descriptors - return w.Bytes() + return buf.Bytes() } func TestParsePMTSection(t *testing.T) { var b = pmtBytes() - d, err := parsePMTSection(astibyte.NewIterator(b), len(b), uint16(1)) + d, err := parsePMTSection(astikit.NewBytesIterator(b), len(b), uint16(1)) assert.Equal(t, d, pmt) assert.NoError(t, err) } diff --git a/data_psi.go b/data_psi.go index c7beb8f..851a294 100644 --- a/data_psi.go +++ b/data_psi.go @@ -3,8 +3,8 @@ package astits import ( "fmt" + "github.com/asticode/go-astikit" "github.com/asticode/go-astilog" - astibyte "github.com/asticode/go-astitools/byte" "github.com/pkg/errors" ) @@ -75,7 +75,7 @@ type PSISectionSyntaxData struct { } // parsePSIData parses a PSI data -func parsePSIData(i *astibyte.Iterator) (d *PSIData, err error) { +func parsePSIData(i *astikit.BytesIterator) (d *PSIData, err error) { // Init data d = &PSIData{} @@ -90,7 +90,7 @@ func parsePSIData(i *astibyte.Iterator) (d *PSIData, err error) { d.PointerField = int(b) // Pointer filler bytes - i.FastForward(d.PointerField) + i.Skip(d.PointerField) // Parse sections var s *PSISection @@ -106,7 +106,7 @@ func parsePSIData(i *astibyte.Iterator) (d *PSIData, err error) { } // parsePSISection parses a PSI section -func parsePSISection(i *astibyte.Iterator) (s *PSISection, stop bool, err error) { +func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err error) { // Init section s = &PSISection{} @@ -171,7 +171,7 @@ func parsePSISection(i *astibyte.Iterator) (s *PSISection, stop bool, err error) } // parseCRC32 parses a CRC32 -func parseCRC32(i *astibyte.Iterator) (c uint32, err error) { +func parseCRC32(i *astikit.BytesIterator) (c uint32, err error) { var bs []byte if bs, err = i.NextBytes(4); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") @@ -204,7 +204,7 @@ func shouldStopPSIParsing(tableType string) bool { } // parsePSISectionHeader parses a PSI section header -func parsePSISectionHeader(i *astibyte.Iterator) (h *PSISectionHeader, offsetStart, offsetSectionsStart, offsetSectionsEnd, offsetEnd int, err error) { +func parsePSISectionHeader(i *astikit.BytesIterator) (h *PSISectionHeader, offsetStart, offsetSectionsStart, offsetSectionsEnd, offsetEnd int, err error) { // Init h = &PSISectionHeader{} offsetStart = i.Offset() @@ -300,7 +300,7 @@ func psiTableType(tableID int) string { } // parsePSISectionSyntax parses a PSI section syntax -func parsePSISectionSyntax(i *astibyte.Iterator, h *PSISectionHeader, offsetSectionsEnd int) (s *PSISectionSyntax, err error) { +func parsePSISectionSyntax(i *astikit.BytesIterator, h *PSISectionHeader, offsetSectionsEnd int) (s *PSISectionSyntax, err error) { // Init s = &PSISectionSyntax{} @@ -330,7 +330,7 @@ func hasPSISyntaxHeader(tableType string) bool { } // parsePSISectionSyntaxHeader parses a PSI section syntax header -func parsePSISectionSyntaxHeader(i *astibyte.Iterator) (h *PSISectionSyntaxHeader, err error) { +func parsePSISectionSyntaxHeader(i *astikit.BytesIterator) (h *PSISectionSyntaxHeader, err error) { // Init h = &PSISectionSyntaxHeader{} @@ -378,7 +378,7 @@ func parsePSISectionSyntaxHeader(i *astibyte.Iterator) (h *PSISectionSyntaxHeade } // parsePSISectionSyntaxData parses a PSI section data -func parsePSISectionSyntaxData(i *astibyte.Iterator, h *PSISectionHeader, sh *PSISectionSyntaxHeader, offsetSectionsEnd int) (d *PSISectionSyntaxData, err error) { +func parsePSISectionSyntaxData(i *astikit.BytesIterator, h *PSISectionHeader, sh *PSISectionSyntaxHeader, offsetSectionsEnd int) (d *PSISectionSyntaxData, err error) { // Init d = &PSISectionSyntaxData{} diff --git a/data_psi_test.go b/data_psi_test.go index f7b1993..e55b8b0 100644 --- a/data_psi_test.go +++ b/data_psi_test.go @@ -1,10 +1,10 @@ package astits import ( + "bytes" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -99,7 +99,8 @@ var psi = &PSIData{ } func psiBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(4)) // Pointer field w.Write([]byte("test")) // Pointer field bytes w.Write(uint8(78)) // EIT table ID @@ -151,12 +152,13 @@ func psiBytes() []byte { w.Write(uint32(0x6969b13)) // TOT CRC32 w.Write(uint8(254)) // Unknown table ID w.Write(uint8(0)) // PAT table ID - return w.Bytes() + return buf.Bytes() } func TestParsePSIData(t *testing.T) { // Invalid CRC32 - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(0)) // Pointer field w.Write(uint8(115)) // TOT table ID w.Write("1") // TOT syntax section indicator @@ -165,11 +167,11 @@ func TestParsePSIData(t *testing.T) { w.Write("000000001110") // TOT section length w.Write(totBytes()) // TOT data w.Write(uint32(32)) // TOT CRC32 - _, err := parsePSIData(astibyte.NewIterator(w.Bytes())) + _, err := parsePSIData(astikit.NewBytesIterator(buf.Bytes())) assert.EqualError(t, err, "astits: parsing PSI table failed: astits: Table CRC32 20 != computed CRC32 6969b13") // Valid - d, err := parsePSIData(astibyte.NewIterator(psiBytes())) + d, err := parsePSIData(astikit.NewBytesIterator(psiBytes())) assert.NoError(t, err) assert.Equal(t, d, psi) } @@ -183,22 +185,24 @@ var psiSectionHeader = &PSISectionHeader{ } func psiSectionHeaderBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(0)) // Table ID w.Write("1") // Syntax section indicator w.Write("1") // Private bit w.Write("11") // Reserved w.Write("101010101010") // Section length - return w.Bytes() + return buf.Bytes() } func TestParsePSISectionHeader(t *testing.T) { // Unknown table type - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(254)) // Table ID w.Write("1") // Syntax section indicator w.Write("0000000") // Finish the byte - d, _, _, _, _, err := parsePSISectionHeader(astibyte.NewIterator(w.Bytes())) + d, _, _, _, _, err := parsePSISectionHeader(astikit.NewBytesIterator(buf.Bytes())) assert.Equal(t, d, &PSISectionHeader{ TableID: 254, TableType: PSITableTypeUnknown, @@ -206,7 +210,7 @@ func TestParsePSISectionHeader(t *testing.T) { assert.NoError(t, err) // Valid table type - d, offsetStart, offsetSectionsStart, offsetSectionsEnd, offsetEnd, err := parsePSISectionHeader(astibyte.NewIterator(psiSectionHeaderBytes())) + d, offsetStart, offsetSectionsStart, offsetSectionsEnd, offsetEnd, err := parsePSISectionHeader(astikit.NewBytesIterator(psiSectionHeaderBytes())) assert.Equal(t, d, psiSectionHeader) assert.Equal(t, 0, offsetStart) assert.Equal(t, 3, offsetSectionsStart) @@ -245,18 +249,19 @@ var psiSectionSyntaxHeader = &PSISectionSyntaxHeader{ } func psiSectionSyntaxHeaderBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(1)) // Table ID extension w.Write("11") // Reserved bits w.Write("10101") // Version number w.Write("1") // Current/next indicator w.Write(uint8(2)) // Section number w.Write(uint8(3)) // Last section number - return w.Bytes() + return buf.Bytes() } func TestParsePSISectionSyntaxHeader(t *testing.T) { - h, err := parsePSISectionSyntaxHeader(astibyte.NewIterator(psiSectionSyntaxHeaderBytes())) + h, err := parsePSISectionSyntaxHeader(astikit.NewBytesIterator(psiSectionSyntaxHeaderBytes())) assert.Equal(t, psiSectionSyntaxHeader, h) assert.NoError(t, err) } diff --git a/data_sdt.go b/data_sdt.go index a4207a5..58bebf8 100644 --- a/data_sdt.go +++ b/data_sdt.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -34,7 +34,7 @@ type SDTDataService struct { } // parseSDTSection parses an SDT section -func parseSDTSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtension uint16) (d *SDTData, err error) { +func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExtension uint16) (d *SDTData, err error) { // Create data d = &SDTData{TransportStreamID: tableIDExtension} @@ -49,7 +49,7 @@ func parseSDTSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtensi d.OriginalNetworkID = uint16(bs[0])<<8 | uint16(bs[1]) // Reserved for future use - i.FastForward(1) + i.Skip(1) // Loop until end of section data is reached for i.Offset() < offsetSectionsEnd { @@ -91,7 +91,7 @@ func parseSDTSection(i *astibyte.Iterator, offsetSectionsEnd int, tableIDExtensi s.HasFreeCSAMode = uint8(b&0x10) > 0 // We need to rewind since the current byte is used by the descriptor as well - i.FastForward(-1) + i.Skip(-1) // Descriptors if s.Descriptors, err = parseDescriptors(i); err != nil { diff --git a/data_sdt_test.go b/data_sdt_test.go index e97ad55..cc59c9d 100644 --- a/data_sdt_test.go +++ b/data_sdt_test.go @@ -1,10 +1,10 @@ package astits import ( + "bytes" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -22,7 +22,8 @@ var sdt = &SDTData{ } func sdtBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(2)) // Original network ID w.Write(uint8(0)) // Reserved for future use w.Write(uint16(3)) // Service #1 id @@ -32,12 +33,12 @@ func sdtBytes() []byte { w.Write("101") // Service #1 running status w.Write("1") // Service #1 free CA mode descriptorsBytes(w) // Service #1 descriptors - return w.Bytes() + return buf.Bytes() } func TestParseSDTSection(t *testing.T) { var b = sdtBytes() - d, err := parseSDTSection(astibyte.NewIterator(b), len(b), uint16(1)) + d, err := parseSDTSection(astikit.NewBytesIterator(b), len(b), uint16(1)) assert.Equal(t, d, sdt) assert.NoError(t, err) } diff --git a/data_test.go b/data_test.go index de6244c..428671b 100644 --- a/data_test.go +++ b/data_test.go @@ -1,9 +1,10 @@ package astits import ( + "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -77,10 +78,11 @@ func TestIsPSIPayload(t *testing.T) { } func TestIsPESPayload(t *testing.T) { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("0000000000000001") - assert.False(t, isPESPayload(w.Bytes())) - w.Reset() + assert.False(t, isPESPayload(buf.Bytes())) + buf.Reset() w.Write("000000000000000000000001") - assert.True(t, isPESPayload(w.Bytes())) + assert.True(t, isPESPayload(buf.Bytes())) } diff --git a/data_tot.go b/data_tot.go index ffc4123..69aeaac 100644 --- a/data_tot.go +++ b/data_tot.go @@ -3,7 +3,7 @@ package astits import ( "time" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -15,7 +15,7 @@ type TOTData struct { } // parseTOTSection parses a TOT section -func parseTOTSection(i *astibyte.Iterator) (d *TOTData, err error) { +func parseTOTSection(i *astikit.BytesIterator) (d *TOTData, err error) { // Create data d = &TOTData{} diff --git a/data_tot_test.go b/data_tot_test.go index 99e642d..0f2756c 100644 --- a/data_tot_test.go +++ b/data_tot_test.go @@ -1,11 +1,11 @@ package astits import ( + "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" - "github.com/asticode/go-astitools/byte" ) var tot = &TOTData{ @@ -14,15 +14,16 @@ var tot = &TOTData{ } func totBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(dvbTimeBytes) // UTC time w.Write("0000") // Reserved descriptorsBytes(w) // Service #1 descriptors - return w.Bytes() + return buf.Bytes() } func TestParseTOTSection(t *testing.T) { - d, err := parseTOTSection(astibyte.NewIterator(totBytes())) + d, err := parseTOTSection(astikit.NewBytesIterator(totBytes())) assert.Equal(t, d, tot) assert.NoError(t, err) } diff --git a/demuxer_test.go b/demuxer_test.go index 28e8705..d5dfee5 100644 --- a/demuxer_test.go +++ b/demuxer_test.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -27,12 +27,13 @@ func TestDemuxerNextPacket(t *testing.T) { assert.Error(t, err) // Valid - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) b1, p1 := packet(*packetHeader, *packetAdaptationField, []byte("1")) w.Write(b1) b2, p2 := packet(*packetHeader, *packetAdaptationField, []byte("2")) w.Write(b2) - dmx = New(context.Background(), bytes.NewReader(w.Bytes())) + dmx = New(context.Background(), bytes.NewReader(buf.Bytes())) // First packet p, err := dmx.NextPacket() @@ -52,13 +53,14 @@ func TestDemuxerNextPacket(t *testing.T) { func TestDemuxerNextData(t *testing.T) { // Init - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) b := psiBytes() b1, _ := packet(PacketHeader{ContinuityCounter: uint8(0), PayloadUnitStartIndicator: true, PID: PIDPAT}, PacketAdaptationField{}, b[:147]) w.Write(b1) b2, _ := packet(PacketHeader{ContinuityCounter: uint8(1), PID: PIDPAT}, PacketAdaptationField{}, b[147:]) w.Write(b2) - dmx := New(context.Background(), bytes.NewReader(w.Bytes())) + dmx := New(context.Background(), bytes.NewReader(buf.Bytes())) p, err := dmx.NextPacket() assert.NoError(t, err) _, err = dmx.Rewind() diff --git a/descriptor.go b/descriptor.go index eb21645..5cd939f 100644 --- a/descriptor.go +++ b/descriptor.go @@ -3,8 +3,8 @@ package astits import ( "time" + "github.com/asticode/go-astikit" "github.com/asticode/go-astilog" - "github.com/asticode/go-astitools/byte" "github.com/pkg/errors" ) @@ -132,7 +132,7 @@ type DescriptorAC3 struct { MainID uint8 } -func newDescriptorAC3(i *astibyte.Iterator, offsetEnd int) (d *DescriptorAC3, err error) { +func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -207,7 +207,7 @@ type DescriptorAVCVideo struct { ProfileIDC uint8 } -func newDescriptorAVCVideo(i *astibyte.Iterator) (d *DescriptorAVCVideo, err error) { +func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err error) { // Init d = &DescriptorAVCVideo{} @@ -267,7 +267,7 @@ type DescriptorComponent struct { Text []byte } -func newDescriptorComponent(i *astibyte.Iterator, offsetEnd int) (d *DescriptorComponent, err error) { +func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorComponent, err error) { // Init d = &DescriptorComponent{} @@ -332,7 +332,7 @@ type DescriptorContentItem struct { UserByte uint8 } -func newDescriptorContent(i *astibyte.Iterator, offsetEnd int) (d *DescriptorContent, err error) { +func newDescriptorContent(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorContent, err error) { // Init d = &DescriptorContent{} @@ -360,7 +360,7 @@ type DescriptorDataStreamAlignment struct { Type uint8 } -func newDescriptorDataStreamAlignment(i *astibyte.Iterator) (d *DescriptorDataStreamAlignment, err error) { +func newDescriptorDataStreamAlignment(i *astikit.BytesIterator) (d *DescriptorDataStreamAlignment, err error) { var b byte if b, err = i.NextByte(); err != nil { err = errors.Wrap(err, "astits: fetching next byte failed") @@ -391,7 +391,7 @@ type DescriptorEnhancedAC3 struct { SubStream3 uint8 } -func newDescriptorEnhancedAC3(i *astibyte.Iterator, offsetEnd int) (d *DescriptorEnhancedAC3, err error) { +func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorEnhancedAC3, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -508,7 +508,7 @@ type DescriptorExtendedEventItem struct { Description []byte } -func newDescriptorExtendedEvent(i *astibyte.Iterator) (d *DescriptorExtendedEvent, err error) { +func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtendedEvent, err error) { // Init d = &DescriptorExtendedEvent{} @@ -571,7 +571,7 @@ func newDescriptorExtendedEvent(i *astibyte.Iterator) (d *DescriptorExtendedEven return } -func newDescriptorExtendedEventItem(i *astibyte.Iterator) (d *DescriptorExtendedEventItem, err error) { +func newDescriptorExtendedEventItem(i *astikit.BytesIterator) (d *DescriptorExtendedEventItem, err error) { // Init d = &DescriptorExtendedEventItem{} @@ -615,7 +615,7 @@ type DescriptorExtension struct { Tag uint8 } -func newDescriptorExtension(i *astibyte.Iterator, offsetEnd int) (d *DescriptorExtension, err error) { +func newDescriptorExtension(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorExtension, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -650,7 +650,7 @@ type DescriptorExtensionSupplementaryAudio struct { PrivateData []byte } -func newDescriptorExtensionSupplementaryAudio(i *astibyte.Iterator, offsetEnd int) (d *DescriptorExtensionSupplementaryAudio, err error) { +func newDescriptorExtensionSupplementaryAudio(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorExtensionSupplementaryAudio, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -691,7 +691,7 @@ type DescriptorISO639LanguageAndAudioType struct { } // In some actual cases, the length is 3 and the language is described in only 2 bytes -func newDescriptorISO639LanguageAndAudioType(i *astibyte.Iterator, offsetEnd int) (d *DescriptorISO639LanguageAndAudioType, err error) { +func newDescriptorISO639LanguageAndAudioType(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorISO639LanguageAndAudioType, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { @@ -724,7 +724,7 @@ type DescriptorLocalTimeOffsetItem struct { TimeOfChange time.Time } -func newDescriptorLocalTimeOffset(i *astibyte.Iterator, offsetEnd int) (d *DescriptorLocalTimeOffset, err error) { +func newDescriptorLocalTimeOffset(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorLocalTimeOffset, err error) { // Init d = &DescriptorLocalTimeOffset{} @@ -781,7 +781,7 @@ type DescriptorMaximumBitrate struct { Bitrate uint32 // In bytes/second } -func newDescriptorMaximumBitrate(i *astibyte.Iterator) (d *DescriptorMaximumBitrate, err error) { +func newDescriptorMaximumBitrate(i *astikit.BytesIterator) (d *DescriptorMaximumBitrate, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(3); err != nil { @@ -800,7 +800,7 @@ type DescriptorNetworkName struct { Name []byte } -func newDescriptorNetworkName(i *astibyte.Iterator, offsetEnd int) (d *DescriptorNetworkName, err error) { +func newDescriptorNetworkName(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorNetworkName, err error) { // Create descriptor d = &DescriptorNetworkName{} @@ -834,7 +834,7 @@ func (d DescriptorParentalRatingItem) MinimumAge() int { return int(d.Rating) + 3 } -func newDescriptorParentalRating(i *astibyte.Iterator, offsetEnd int) (d *DescriptorParentalRating, err error) { +func newDescriptorParentalRating(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorParentalRating, err error) { // Create descriptor d = &DescriptorParentalRating{} @@ -861,7 +861,7 @@ type DescriptorPrivateDataIndicator struct { Indicator uint32 } -func newDescriptorPrivateDataIndicator(i *astibyte.Iterator) (d *DescriptorPrivateDataIndicator, err error) { +func newDescriptorPrivateDataIndicator(i *astikit.BytesIterator) (d *DescriptorPrivateDataIndicator, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { @@ -879,7 +879,7 @@ type DescriptorPrivateDataSpecifier struct { Specifier uint32 } -func newDescriptorPrivateDataSpecifier(i *astibyte.Iterator) (d *DescriptorPrivateDataSpecifier, err error) { +func newDescriptorPrivateDataSpecifier(i *astikit.BytesIterator) (d *DescriptorPrivateDataSpecifier, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { @@ -899,7 +899,7 @@ type DescriptorRegistration struct { FormatIdentifier uint32 } -func newDescriptorRegistration(i *astibyte.Iterator, offsetEnd int) (d *DescriptorRegistration, err error) { +func newDescriptorRegistration(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorRegistration, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { @@ -928,7 +928,7 @@ type DescriptorService struct { Type uint8 } -func newDescriptorService(i *astibyte.Iterator) (d *DescriptorService, err error) { +func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -979,7 +979,7 @@ type DescriptorShortEvent struct { Text []byte } -func newDescriptorShortEvent(i *astibyte.Iterator) (d *DescriptorShortEvent, err error) { +func newDescriptorShortEvent(i *astikit.BytesIterator) (d *DescriptorShortEvent, err error) { // Create descriptor d = &DescriptorShortEvent{} @@ -1026,7 +1026,7 @@ func newDescriptorShortEvent(i *astibyte.Iterator) (d *DescriptorShortEvent, err // Chapter: 6.2.39 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf type DescriptorStreamIdentifier struct{ ComponentTag uint8 } -func newDescriptorStreamIdentifier(i *astibyte.Iterator) (d *DescriptorStreamIdentifier, err error) { +func newDescriptorStreamIdentifier(i *astikit.BytesIterator) (d *DescriptorStreamIdentifier, err error) { var b byte if b, err = i.NextByte(); err != nil { err = errors.Wrap(err, "astits: fetching next byte failed") @@ -1051,7 +1051,7 @@ type DescriptorSubtitlingItem struct { Type uint8 } -func newDescriptorSubtitling(i *astibyte.Iterator, offsetEnd int) (d *DescriptorSubtitling, err error) { +func newDescriptorSubtitling(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorSubtitling, err error) { // Create descriptor d = &DescriptorSubtitling{} @@ -1116,7 +1116,7 @@ type DescriptorTeletextItem struct { Type uint8 } -func newDescriptorTeletext(i *astibyte.Iterator, offsetEnd int) (d *DescriptorTeletext, err error) { +func newDescriptorTeletext(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorTeletext, err error) { // Create descriptor d = &DescriptorTeletext{} @@ -1179,7 +1179,7 @@ type DescriptorVBIDataDescriptor struct { LineOffset uint8 } -func newDescriptorVBIData(i *astibyte.Iterator, offsetEnd int) (d *DescriptorVBIData, err error) { +func newDescriptorVBIData(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorVBIData, err error) { // Create descriptor d = &DescriptorVBIData{} @@ -1237,7 +1237,7 @@ func newDescriptorVBIData(i *astibyte.Iterator, offsetEnd int) (d *DescriptorVBI } // parseDescriptors parses descriptors -func parseDescriptors(i *astibyte.Iterator) (o []*Descriptor, err error) { +func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { diff --git a/descriptor_test.go b/descriptor_test.go index 61324ec..d41551c 100644 --- a/descriptor_test.go +++ b/descriptor_test.go @@ -1,10 +1,10 @@ package astits import ( + "bytes" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -14,7 +14,7 @@ var descriptors = []*Descriptor{{ Tag: DescriptorTagStreamIdentifier, }} -func descriptorsBytes(w *astibinary.Writer) { +func descriptorsBytes(w *astikit.BitsWriter) { w.Write("000000000011") // Overall length w.Write(uint8(DescriptorTagStreamIdentifier)) // Tag w.Write(uint8(1)) // Length @@ -23,7 +23,8 @@ func descriptorsBytes(w *astibinary.Writer) { func TestParseDescriptor(t *testing.T) { // Init - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(242)) // Descriptors length // AC3 w.Write(uint8(DescriptorTagAC3)) // Tag @@ -215,7 +216,7 @@ func TestParseDescriptor(t *testing.T) { w.Write([]byte("test")) // Additional identification info // Assert - ds, err := parseDescriptors(astibyte.NewIterator(w.Bytes())) + ds, err := parseDescriptors(astikit.NewBytesIterator(buf.Bytes())) assert.NoError(t, err) assert.Equal(t, *ds[0].AC3, DescriptorAC3{ AdditionalInfo: []byte("info"), diff --git a/dvb.go b/dvb.go index 6f47b91..c831c4e 100644 --- a/dvb.go +++ b/dvb.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -14,7 +14,7 @@ import ( // field are set to "1". // I apologize for the computation which is really messy but details are given in the documentation // Page: 160 | Annex C | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf -func parseDVBTime(i *astibyte.Iterator) (t time.Time, err error) { +func parseDVBTime(i *astikit.BytesIterator) (t time.Time, err error) { // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { @@ -47,7 +47,7 @@ func parseDVBTime(i *astibyte.Iterator) (t time.Time, err error) { // parseDVBDurationMinutes parses a minutes duration // 16 bit field containing the duration of the event in hours, minutes. format: 4 digits, 4 - bit BCD = 18 bit -func parseDVBDurationMinutes(i *astibyte.Iterator) (d time.Duration, err error) { +func parseDVBDurationMinutes(i *astikit.BytesIterator) (d time.Duration, err error) { var bs []byte if bs, err = i.NextBytes(2); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") @@ -59,7 +59,7 @@ func parseDVBDurationMinutes(i *astibyte.Iterator) (d time.Duration, err error) // parseDVBDurationSeconds parses a seconds duration // 24 bit field containing the duration of the event in hours, minutes, seconds. format: 6 digits, 4 - bit BCD = 24 bit -func parseDVBDurationSeconds(i *astibyte.Iterator) (d time.Duration, err error) { +func parseDVBDurationSeconds(i *astikit.BytesIterator) (d time.Duration, err error) { var bs []byte if bs, err = i.NextBytes(3); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") diff --git a/dvb_test.go b/dvb_test.go index 013e3c5..8e71ef2 100644 --- a/dvb_test.go +++ b/dvb_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) @@ -18,19 +18,19 @@ var ( ) func TestParseDVBTime(t *testing.T) { - d, err := parseDVBTime(astibyte.NewIterator(dvbTimeBytes)) + d, err := parseDVBTime(astikit.NewBytesIterator(dvbTimeBytes)) assert.Equal(t, dvbTime, d) assert.NoError(t, err) } func TestParseDVBDurationMinutes(t *testing.T) { - d, err := parseDVBDurationMinutes(astibyte.NewIterator(dvbDurationMinutesBytes)) + d, err := parseDVBDurationMinutes(astikit.NewBytesIterator(dvbDurationMinutesBytes)) assert.Equal(t, dvbDurationMinutes, d) assert.NoError(t, err) } func TestParseDVBDurationSeconds(t *testing.T) { - d, err := parseDVBDurationSeconds(astibyte.NewIterator(dvbDurationSecondsBytes)) + d, err := parseDVBDurationSeconds(astikit.NewBytesIterator(dvbDurationSecondsBytes)) assert.Equal(t, dvbDurationSeconds, d) assert.NoError(t, err) } diff --git a/go.mod b/go.mod index 33fc2e2..e03477f 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/asticode/go-astits go 1.13 require ( - github.com/asticode/go-astilog v1.2.0 - github.com/asticode/go-astitools v1.2.1 + github.com/asticode/go-astikit v0.0.9 + github.com/asticode/go-astilog v1.4.0 github.com/pkg/errors v0.8.1 github.com/pkg/profile v1.4.0 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index d3e58ee..5197b82 100644 --- a/go.sum +++ b/go.sum @@ -1,65 +1,39 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/asticode/go-astiamqp v1.0.0/go.mod h1:PDHG8FjHJDtbDNNHixFCm80+7Ma1dKvwYl325Mj5DI4= -github.com/asticode/go-astiamqp v1.0.1/go.mod h1:Xe27K2GHnsEoIgAtHi+udd7xXV5YSQG4nE3ggZoyU/4= -github.com/asticode/go-astilog v1.0.0/go.mod h1:Vg6SGUYb3tVyFeGQe0Mqmh0RMygpwy+huFKcyL92EVc= -github.com/asticode/go-astilog v1.2.0 h1:p1jTI/4CgUgtkuAVP6DiRn6RTjX6CIqLdn9pu6tsz5w= -github.com/asticode/go-astilog v1.2.0/go.mod h1:0sGDwdYLRSFVbbvrXLbJC9niyGWL5JGTCEQWFJKHZr0= -github.com/asticode/go-astitools v1.0.0/go.mod h1:E7f1P0KkBNgafRCD0dHqn41jNHyYHjxrnK1jH2s4pmA= -github.com/asticode/go-astitools v1.2.0/go.mod h1:EfgrhUJK6nM17TckqASIqR2W71uNUAoIonm6mNhUtaQ= -github.com/asticode/go-astitools v1.2.1 h1:1KPzl1MquD7UlkPQULV3np+HlThfu1nDmKKJnmRT2Mw= -github.com/asticode/go-astitools v1.2.1/go.mod h1:7HUpcFY8dQwjwBFCEXAHCLF5gWCObPoE9GTlgQKmAPo= -github.com/asticode/go-astiws v1.0.1/go.mod h1:5F/0RkJTq1SZ0TsiheD3j/9lr9kla70c2q7w1aAG78Q= +github.com/asticode/go-astikit v0.0.9 h1:4r1jjQU3g+2RuoCJSrzoLogcKU+3AQcQGMPBQdnijq4= +github.com/asticode/go-astikit v0.0.9/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= +github.com/asticode/go-astilog v1.4.0 h1:81eNYAC04VPg1b9UXdQe3NCT1EPo9CtGa2UUDnQyvik= +github.com/asticode/go-astilog v1.4.0/go.mod h1:0sGDwdYLRSFVbbvrXLbJC9niyGWL5JGTCEQWFJKHZr0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.4.0 h1:uCmaf4vVbWAOZz36k1hrQD7ijGRzLwaME8Am/7a4jZI= github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/streadway/amqp v0.0.0-20181205114330-a314942b2fd9/go.mod h1:1WNBiOZtZQLpVAyu0iTduoJL9hEsMloAK5XWrtW0xdY= -github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e h1:egKlR8l7Nu9vHGWbcUV8lqR4987UfUbBd7GbhqGzNYU= golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a h1:+HHJiFUXVOIS9mr1ThqkQD1N8vpFCfCShqADBM12KTc= -golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/packet.go b/packet.go index 48d9834..ab72008 100644 --- a/packet.go +++ b/packet.go @@ -1,7 +1,7 @@ package astits import ( - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) @@ -66,7 +66,7 @@ type PacketAdaptationExtensionField struct { } // parsePacket parses a packet -func parsePacket(i *astibyte.Iterator) (p *Packet, err error) { +func parsePacket(i *astikit.BytesIterator) (p *Packet, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { @@ -119,7 +119,7 @@ func payloadOffset(offsetStart int, h *PacketHeader, a *PacketAdaptationField) ( } // parsePacketHeader parses the packet header -func parsePacketHeader(i *astibyte.Iterator) (h *PacketHeader, err error) { +func parsePacketHeader(i *astikit.BytesIterator) (h *PacketHeader, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(3); err != nil { @@ -142,7 +142,7 @@ func parsePacketHeader(i *astibyte.Iterator) (h *PacketHeader, err error) { } // parsePacketAdaptationField parses the packet adaptation field -func parsePacketAdaptationField(i *astibyte.Iterator) (a *PacketAdaptationField, err error) { +func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationField, err error) { // Create adaptation field a = &PacketAdaptationField{} @@ -275,7 +275,7 @@ func parsePacketAdaptationField(i *astibyte.Iterator) (a *PacketAdaptationField, a.AdaptationExtensionField.SpliceType = uint8(b&0xf0) >> 4 // We need to rewind since the current byte is used by the DTS next access unit as well - i.FastForward(-1) + i.Skip(-1) // DTS Next access unit if a.AdaptationExtensionField.DTSNextAccessUnit, err = parsePTSOrDTS(i); err != nil { @@ -291,7 +291,7 @@ func parsePacketAdaptationField(i *astibyte.Iterator) (a *PacketAdaptationField, // parsePCR parses a Program Clock Reference // Program clock reference, stored as 33 bits base, 6 bits reserved, 9 bits extension. -func parsePCR(i *astibyte.Iterator) (cr *ClockReference, err error) { +func parsePCR(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(6); err != nil { err = errors.Wrap(err, "astits: fetching next bytes failed") diff --git a/packet_buffer.go b/packet_buffer.go index 13832b8..cc2070c 100644 --- a/packet_buffer.go +++ b/packet_buffer.go @@ -4,13 +4,12 @@ import ( "fmt" "io" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/pkg/errors" ) // packetBuffer represents a packet buffer type packetBuffer struct { - b []*Packet packetSize int r io.Reader } @@ -104,7 +103,7 @@ func (pb *packetBuffer) next() (p *Packet, err error) { } // Parse packet - if p, err = parsePacket(astibyte.NewIterator(b)); err != nil { + if p, err = parsePacket(astikit.NewBytesIterator(b)); err != nil { err = errors.Wrap(err, "astits: building packet failed") return } diff --git a/packet_buffer_test.go b/packet_buffer_test.go index 3381e0d..b0c3d6e 100644 --- a/packet_buffer_test.go +++ b/packet_buffer_test.go @@ -4,20 +4,21 @@ import ( "bytes" "testing" - "github.com/asticode/go-astitools/binary" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) func TestAutoDetectPacketSize(t *testing.T) { // Packet should start with a sync byte - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(2)) w.Write(byte(syncByte)) - _, err := autoDetectPacketSize(bytes.NewReader(w.Bytes())) + _, err := autoDetectPacketSize(bytes.NewReader(buf.Bytes())) assert.EqualError(t, err, ErrPacketMustStartWithASyncByte.Error()) // Valid packet size - w.Reset() + buf.Reset() w.Write(byte(syncByte)) w.Write(make([]byte, 20)) w.Write(byte(syncByte)) @@ -25,7 +26,7 @@ func TestAutoDetectPacketSize(t *testing.T) { w.Write(byte(syncByte)) w.Write(make([]byte, 187)) w.Write([]byte("test")) - r := bytes.NewReader(w.Bytes()) + r := bytes.NewReader(buf.Bytes()) p, err := autoDetectPacketSize(r) assert.NoError(t, err) assert.Equal(t, 188, p) diff --git a/packet_test.go b/packet_test.go index a12be23..873582d 100644 --- a/packet_test.go +++ b/packet_test.go @@ -1,23 +1,24 @@ package astits import ( + "bytes" "fmt" "testing" - astibinary "github.com/asticode/go-astitools/binary" - astibyte "github.com/asticode/go-astitools/byte" + "github.com/asticode/go-astikit" "github.com/stretchr/testify/assert" ) func packet(h PacketHeader, a PacketAdaptationField, i []byte) ([]byte, *Packet) { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(syncByte)) // Sync byte w.Write([]byte("test")) // Sometimes packets are 192 bytes w.Write(packetHeaderBytes(h)) // Header w.Write(packetAdaptationFieldBytes(a)) // Adaptation field var payload = append(i, make([]byte, 147-len(i))...) // Payload w.Write(payload) - return w.Bytes(), &Packet{ + return buf.Bytes(), &Packet{ AdaptationField: packetAdaptationField, Header: packetHeader, Payload: payload, @@ -26,14 +27,15 @@ func packet(h PacketHeader, a PacketAdaptationField, i []byte) ([]byte, *Packet) func TestParsePacket(t *testing.T) { // Packet not starting with a sync - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint16(1)) // Invalid sync byte - _, err := parsePacket(astibyte.NewIterator(w.Bytes())) + _, err := parsePacket(astikit.NewBytesIterator(buf.Bytes())) assert.EqualError(t, err, ErrPacketMustStartWithASyncByte.Error()) // Valid b, ep := packet(*packetHeader, *packetAdaptationField, []byte("payload")) - p, err := parsePacket(astibyte.NewIterator(b)) + p, err := parsePacket(astikit.NewBytesIterator(b)) assert.NoError(t, err) assert.Equal(t, p, ep) } @@ -55,7 +57,8 @@ var packetHeader = &PacketHeader{ } func packetHeaderBytes(h PacketHeader) []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(h.TransportErrorIndicator) // Transport error indicator w.Write(h.PayloadUnitStartIndicator) // Payload unit start indicator w.Write("1") // Transport priority @@ -63,11 +66,11 @@ func packetHeaderBytes(h PacketHeader) []byte { w.Write("10") // Scrambling control w.Write("11") // Adaptation field control w.Write(fmt.Sprintf("%.4b", h.ContinuityCounter)) // Continuity counter - return w.Bytes() + return buf.Bytes() } func TestParsePacketHeader(t *testing.T) { - v, err := parsePacketHeader(astibyte.NewIterator(packetHeaderBytes(*packetHeader))) + v, err := parsePacketHeader(astikit.NewBytesIterator(packetHeaderBytes(*packetHeader))) assert.Equal(t, packetHeader, v) assert.NoError(t, err) } @@ -101,7 +104,8 @@ var packetAdaptationField = &PacketAdaptationField{ } func packetAdaptationFieldBytes(a PacketAdaptationField) []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write(uint8(36)) // Length w.Write(a.DiscontinuityIndicator) // Discontinuity indicator w.Write("1") // Random access indicator @@ -127,11 +131,11 @@ func packetAdaptationFieldBytes(a PacketAdaptationField) []byte { w.Write("1010101010101010101010") // Piecewise rate w.Write(dtsBytes()) // Splice type + DTS next access unit w.Write([]byte("stuff")) // Stuffing bytes - return w.Bytes() + return buf.Bytes() } func TestParsePacketAdaptationField(t *testing.T) { - v, err := parsePacketAdaptationField(astibyte.NewIterator(packetAdaptationFieldBytes(*packetAdaptationField))) + v, err := parsePacketAdaptationField(astikit.NewBytesIterator(packetAdaptationFieldBytes(*packetAdaptationField))) assert.Equal(t, packetAdaptationField, v) assert.NoError(t, err) } @@ -142,15 +146,16 @@ var pcr = &ClockReference{ } func pcrBytes() []byte { - w := astibinary.New() + buf := &bytes.Buffer{} + w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf}) w.Write("101010101010101010101010101010101") // Base w.Write("111111") // Reserved w.Write("101010101") // Extension - return w.Bytes() + return buf.Bytes() } func TestParsePCR(t *testing.T) { - v, err := parsePCR(astibyte.NewIterator(pcrBytes())) + v, err := parsePCR(astikit.NewBytesIterator(pcrBytes())) assert.Equal(t, pcr, v) assert.NoError(t, err) }