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
pfb []byte // Pointer filler bytes
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)
sl uint16 // Section length
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
}
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
}
func (p *PAT) Fill(space []byte) error {
return nil
func (d *Desc) Bytes() (out []byte) {
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 {
checkSpace(space)
return nil
}
func (d *Desc) Fill(space []byte) error {
checkSpace(space, DescHeadLen+int(d.dl))
space[0] = d.dt
space[1] = d.dl
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")
func (e *ESSD) Bytes() (out []byte) {
out = make([]byte, ESSDHeadLen)
out[0] = e.st
out[1] = 0xe0 | e.epid>>3
out[2] = e.epid
out[3] = 0xf0 | byte(e.esil>>6)
out[4] = byte(e.esil)
for _, d := range e.esd {
out = append(out, d.Bytes()...)
}
return
}