From b1771483ce18960cda648d45602b9a905c2e4869 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 11 Dec 2017 17:08:09 +1030 Subject: [PATCH] Working out how to convert to byte slice --- packet/MpegTs.go | 55 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/packet/MpegTs.go b/packet/MpegTs.go index f22a9746..71024e0a 100644 --- a/packet/MpegTs.go +++ b/packet/MpegTs.go @@ -28,19 +28,50 @@ LICENSE package packet +import ( + "strconv" +) + +// Length of some fields in bits +const ( + SyncByteLength = 8 + TEILength = 1 + PUSILength = 1 + PriorityLength = 1 + PIDLength = 13 + TSCLength = 2 + AFCLength = 2 + CCLength = 4 +) + +// Index of the fields +const ( + SyncByteIndex = 0 + TEIIndex = SyncByteIndex + SyncByteLength + PUSIIndex = TEIIndex + TEILength + PriorityIndex = PUSIIndex + PUSILength + PIDIndex = PriorityIndex + PriorityLength + TSCIndex = PIDIndex + PIDLength + AFCIndex = TSCIndex + TSCLength + CCIndex = AFCIndex + AFCLength + AFIndex = CCIndex + CCLength +) + type MpegTsPacket struct { - SyncByte byte - TEI bool - PUSI bool - Priority bool - PID uint - TSC byte - AFC byte - CC byte - AdaptionField []byte - Payload []byte + SyncByte byte + TEI bool // Transport Error Indicator + PUSI bool // Payload Unit Start Indicator + Priority bool + PID int + TSC byte // Transport Scrambling Control + AFC byte // Adaption Field Control + CC int // Continuity Counter + AF []byte // Adaption Field + Payload []byte } -type (p *MpegTsPacket) toByteSlice() []byte { - +func getHex() +func (p *MpegTsPacket) toByteSlice() (output []byte) { + output[0] = p.SyncByte + output[1] = }