github.com/puellanivis/breton@v0.2.16/lib/mpeg/ts/psi/raw.go (about)

     1  package psi
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type raw struct {
     9  	ID      byte
    10  	Private bool
    11  
    12  	Syntax *SectionSyntax
    13  
    14  	Data []byte
    15  
    16  	crc uint32
    17  }
    18  
    19  func (psi *raw) TableID() uint8 {
    20  	return psi.ID
    21  }
    22  
    23  func (psi *raw) SectionSyntax() *SectionSyntax {
    24  	return psi.Syntax
    25  }
    26  
    27  func (psi *raw) String() string {
    28  	var out []string
    29  
    30  	out = append(out, fmt.Sprintf("TID:x%02X", psi.ID))
    31  	if psi.Private {
    32  		out = append(out, "PRIV")
    33  	}
    34  
    35  	if psi.Syntax != nil {
    36  		out = append(out, fmt.Sprint(psi.Syntax))
    37  	}
    38  
    39  	out = append(out, fmt.Sprintf("Data[%d]", len(psi.Data)))
    40  
    41  	out = append(out, fmt.Sprintf("crc:x%08X", psi.crc))
    42  
    43  	return fmt.Sprintf("{%s}", strings.Join(out, " "))
    44  }
    45  
    46  const (
    47  	flagSectionSyntax = 0x80
    48  	flagPrivate       = 0x40
    49  )
    50  
    51  func (psi *raw) Unmarshal(b []byte) error {
    52  	psi.ID = b[0]
    53  	psi.Private = b[1]&flagPrivate != 0
    54  
    55  	syn, data, crc, err := CommonUnmarshal(b)
    56  	if err != nil {
    57  		return err
    58  	}
    59  
    60  	psi.Syntax = syn
    61  	psi.crc = crc
    62  
    63  	psi.Data = append([]byte{}, data...)
    64  
    65  	return nil
    66  }
    67  
    68  func (psi *raw) Marshal() ([]byte, error) {
    69  	return CommonMarshal(psi.ID, psi.Private, psi.Syntax, psi.Data)
    70  }