Documentation
¶
Overview ¶
Package ebml implements encoding and decoding of Extensible Binary Meta Language (EBML).
Index ¶
- func Marshal(val interface{}, w io.Writer, opts ...MarshalOption) error
- func MarshalBlock(b *Block, w io.Writer) error
- func Unmarshal(r io.Reader, val interface{}, opts ...UnmarshalOption) error
- type Block
- type Element
- type ElementType
- type Lace
- type LacingMode
- type MarshalOption
- type MarshalOptions
- type Type
- type UnmarshalOption
- type UnmarshalOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
func Marshal(val interface{}, w io.Writer, opts ...MarshalOption) error
Marshal struct to EBML bytes
Examples of struct field tags:
// Field appears as element "EBMLVersion".
Field uint64 `ebml:EBMLVersion`
// Field appears as element "EBMLVersion" and
// the field is omitted from the output if the value is empty.
Field uint64 `ebml:TheElement,omitempty`
// Field appears as element "EBMLVersion" and
// the field is omitted from the output if the value is empty.
EBMLVersion uint64 `ebml:,omitempty`
// Field appears as master element "Segment" and
// the size of the element contents is left unknown for streaming data.
Field struct{} `ebml:Segment,size=unknown`
// Field appears as master element "Segment" and
// the size of the element contents is left unknown for streaming data.
// This style may be deprecated in the future.
Field struct{} `ebml:Segment,inf`
// Field appears as element "EBMLVersion" and
// the size of the element data is reserved by 4 bytes.
Field uint64 `ebml:EBMLVersion,size=4`
Example ¶
type EBMLHeader struct {
DocType string `ebml:"EBMLDocType"`
DocTypeVersion uint64 `ebml:"EBMLDocTypeVersion"`
DocTypeReadVersion uint64 `ebml:"EBMLDocTypeReadVersion"`
}
type TestEBML struct {
Header EBMLHeader `ebml:"EBML"`
}
s := TestEBML{
Header: EBMLHeader{
DocType: "webm",
DocTypeVersion: 2,
DocTypeReadVersion: 2,
},
}
var b bytes.Buffer
if err := Marshal(&s, &b); err != nil {
panic(err)
}
for _, b := range b.Bytes() {
fmt.Printf("0x%02x, ", int(b))
}
Output: 0x1a, 0x45, 0xdf, 0xa3, 0x90, 0x42, 0x82, 0x85, 0x77, 0x65, 0x62, 0x6d, 0x00, 0x42, 0x87, 0x81, 0x02, 0x42, 0x85, 0x81, 0x02,
func MarshalBlock ¶
MarshalBlock marshals EBML Block structure
func Unmarshal ¶
func Unmarshal(r io.Reader, val interface{}, opts ...UnmarshalOption) error
Unmarshal EBML stream
Example ¶
TestBinary := []byte{
0x1a, 0x45, 0xdf, 0xa3, // EBML
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, // 0x10
0x42, 0x82, 0x85, 0x77, 0x65, 0x62, 0x6d, 0x00,
0x42, 0x87, 0x81, 0x02, 0x42, 0x85, 0x81, 0x02,
}
type TestEBML struct {
Header struct {
DocType string `ebml:"EBMLDocType"`
DocTypeVersion uint64 `ebml:"EBMLDocTypeVersion"`
DocTypeReadVersion uint64 `ebml:"EBMLDocTypeReadVersion"`
} `ebml:"EBML"`
}
r := bytes.NewReader(TestBinary)
var ret TestEBML
if err := Unmarshal(r, &ret); err != nil {
fmt.Printf("error: %+v\n", err)
}
fmt.Println(ret)
Output: {{webm 2 2}}
Types ¶
type Block ¶
type Block struct {
TrackNumber uint64
Timecode int16
Keyframe bool
Invisible bool
Lacing LacingMode
Discardable bool
Lace *Lace
Data [][]byte
}
Block represents EBML Block/SimpleBlock element
type ElementType ¶
type ElementType int
ElementType represents EBML Element type
const ( ElementInvalid ElementType = iota ElementEBML ElementEBMLVersion ElementEBMLReadVersion ElementEBMLMaxIDLength ElementEBMLMaxSizeLength ElementEBMLDocType ElementEBMLDocTypeVersion ElementEBMLDocTypeReadVersion ElementVoid ElementSegment ElementSeekHead ElementSeek ElementSeekID ElementSeekPosition ElementInfo ElementTimecodeScale ElementDuration ElementDateUTC ElementTitle ElementMuxingApp ElementWritingApp ElementCluster ElementTimecode ElementPrevSize ElementSimpleBlock ElementBlockGroup ElementBlock ElementBlockAdditions ElementBlockMore ElementBlockAddID ElementBlockAdditional ElementBlockDuration ElementReferenceBlock ElementDiscardPadding ElementTracks ElementTrackEntry ElementTrackNumber ElementTrackUID ElementTrackType ElementFlagEnabled ElementFlagForced ElementFlagLacing ElementDefaultDuration ElementName ElementLanguage ElementCodecID ElementCodecPrivate ElementCodecName ElementCodecDelay ElementSeekPreRoll ElementVideo ElementFlagInterlaced ElementStereoMode ElementAlphaMode ElementPixelWidth ElementPixelHeight ElementPixelCropBottom ElementPixelCropTop ElementPixelCropLeft ElementPixelCropRight ElementDisplayWidth ElementDisplayHeight ElementDisplayUnit ElementAspectRatioType ElementAudio ElementSamplingFrequency ElementOutputSamplingFrequency ElementChannels ElementBitDepth ElementContentEncodings ElementContentEncoding ElementContentEncodingOrder ElementContentEncodingScope ElementContentEncodingType ElementContentEncryption ElementContentEncAlgo ElementContentEncKeyID ElementContentEncAESSettings ElementAESSettingsCipherMode ElementCues ElementCuePoint ElementCueTime ElementCueTrackPositions ElementCueTrack ElementCueClusterPosition ElementCueBlockNumber )
EBML Element types
func ElementTypeFromString ¶
func ElementTypeFromString(s string) (ElementType, error)
ElementTypeFromString converts string to ElementType
func (ElementType) String ¶
func (i ElementType) String() string
type LacingMode ¶
type LacingMode uint8
LacingMode is type of laced data
const ( LacingNo LacingMode = 0 LacingFixed LacingMode = 1 LacingXiph LacingMode = 2 LacingEBML LacingMode = 3 )
Type of laced data
type MarshalOption ¶ added in v0.4.0
type MarshalOption func(*MarshalOptions)
MarshalOption configures a MarshalOptions struct
func WithDataSizeLen ¶ added in v0.4.0
func WithDataSizeLen(l int) MarshalOption
WithDataSizeLen returns an MarshalOption which sets number of reserved bytes of element data size
Example ¶
type EBMLHeader struct {
DocType string `ebml:"EBMLDocType"`
DocTypeVersion uint64 `ebml:"EBMLDocTypeVersion"`
DocTypeReadVersion uint64 `ebml:"EBMLDocTypeReadVersion"`
}
type TestEBML struct {
Header EBMLHeader `ebml:"EBML"`
}
s := TestEBML{
Header: EBMLHeader{
DocType: "webm",
DocTypeVersion: 2,
DocTypeReadVersion: 2,
},
}
var b bytes.Buffer
if err := Marshal(&s, &b, WithDataSizeLen(2)); err != nil {
panic(err)
}
for _, b := range b.Bytes() {
fmt.Printf("0x%02x, ", int(b))
}
Output: 0x1a, 0x45, 0xdf, 0xa3, 0x40, 0x13, 0x42, 0x82, 0x40, 0x05, 0x77, 0x65, 0x62, 0x6d, 0x00, 0x42, 0x87, 0x40, 0x01, 0x02, 0x42, 0x85, 0x40, 0x01, 0x02,
type MarshalOptions ¶ added in v0.4.0
type MarshalOptions struct {
// contains filtered or unexported fields
}
MarshalOptions stores options for marshalling
type Type ¶
type Type int
Type represents EBML Element data type
type UnmarshalOption ¶ added in v0.2.0
type UnmarshalOption func(*UnmarshalOptions)
UnmarshalOption configures a UnmarshalOptions struct
func WithElementReadHooks ¶ added in v0.2.0
func WithElementReadHooks(hooks ...func(*Element)) UnmarshalOption
WithElementReadHooks returns an UnmarshalOption which registers element hooks
type UnmarshalOptions ¶ added in v0.2.0
type UnmarshalOptions struct {
// contains filtered or unexported fields
}
UnmarshalOptions stores options for unmarshalling