github.com/puellanivis/breton@v0.2.16/lib/mpeg/ts/psi/psi.go (about) 1 package psi 2 3 var tableRegistry = make(map[uint8]func() PSI) 4 5 // Register sets a mapping from the id to a function which returns a PSI of the appropriate type for that id. 6 func Register(id uint8, fn func() PSI) { 7 tableRegistry[id] = fn 8 } 9 10 // PSI defines an MPEG-TS Program Specific Information table. 11 type PSI interface { 12 TableID() uint8 13 SectionSyntax() *SectionSyntax 14 15 Marshal() ([]byte, error) 16 Unmarshal([]byte) error 17 } 18 19 func defaultTable() PSI { 20 return new(raw) 21 } 22 23 // Unmarshal decodes an abitrary Program Specific information table from a byte slice. 24 func Unmarshal(b []byte) (psi PSI, err error) { 25 ptrVal := int(b[0]) 26 b = b[1+ptrVal:] 27 28 fn := tableRegistry[uint8(b[0])] 29 if fn == nil { 30 fn = defaultTable 31 } 32 33 psi = fn() 34 35 return psi, psi.Unmarshal(b) 36 }