psi: re-wrote bytes for desc and essd to make less bug prone, though at a cost for performance - but optimisation can happen later

This commit is contained in:
saxon 2018-12-06 00:04:19 +10:30
parent 2a589be6bf
commit e2a5e6a16a
1 changed files with 24 additions and 29 deletions

View File

@ -10,7 +10,7 @@ type PSI struct {
pf byte // Point field pf byte // Point field
pfb []byte // Pointer filler bytes pfb []byte // Pointer filler bytes
tid byte // Table ID tid byte // Table ID
ssi bool // Sectiopn syntax indicator (1 for PAT, PMT, CAT) ssi bool // Section syntax indicator (1 for PAT, PMT, CAT)
pb bool // Private bit (0 for PAT, PMT, CAT) pb bool // Private bit (0 for PAT, PMT, CAT)
sl uint16 // Section length sl uint16 // Section length
tss *TSS // Table syntax section (length defined by SL) if length 0 then nil tss *TSS // Table syntax section (length defined by SL) if length 0 then nil
@ -69,38 +69,33 @@ func (p *PSI) Bytes() (out []byte) {
return nil return nil
} }
func (t *TSS) Fill(space []byte) error { func (t *TSS) Fill(s []byte) {
}
func (p *PAT) Fill(s []byte) {
}
func (p *PMT) Bytes() (out []byte) {
return nil return nil
} }
func (p *PAT) Fill(space []byte) error { func (d *Desc) Bytes() (out []byte) {
return nil out = make([]byte, DescHeadLen)
out[0] = d.dt
out[1] = d.dl
out = append(out, d.dd...)
return
} }
func (p *PMT) Fill(space []byte) error { func (e *ESSD) Bytes() (out []byte) {
checkSpace(space) out = make([]byte, ESSDHeadLen)
return nil out[0] = e.st
} out[1] = 0xe0 | e.epid>>3
out[2] = e.epid
func (d *Desc) Fill(space []byte) error { out[3] = 0xf0 | byte(e.esil>>6)
checkSpace(space, DescHeadLen+int(d.dl)) out[4] = byte(e.esil)
space[0] = d.dt for _, d := range e.esd {
space[1] = d.dl out = append(out, d.Bytes()...)
copy(space[2:], d.dd)
return out
}
func (e *ESSD) Fill(space []byte) error {
checkSpace(space, ESSDHeadLen+e.esil)
return nil
}
func checkSpace(s []byte, c uint) {
if s == nil {
panic("Slice provided is nil")
} else if len(s) != 0 {
panic("Slice provided already has something in it")
} else if cap(s) != c {
panic("Slice provided has wrong capacity")
} }
return
} }