ebml

package module
v0.0.0-...-adc0947 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 15 Imported by: 1

README

EBML

An EBML parser written in Go.

Introduction

Extensible Binary Meta Language (EBML) is a generalized file format for any kind of data, aiming to be a binary equivalent to XML. It provides a basic framework for storing data in XML-like tags. It was originally developed for the Matroska audio/video container format.

Source: https://en.wikipedia.org/wiki/Extensible_Binary_Meta_Language

This library is based on the July 2020 version of RFC 8794 (with additions from github.com/ietf-wg-cellar/ebml-specification). This document did not reach "Internet Standard" status yet. RFC 8794 is in a "Proposed Standard" status.

The goal of this project is to create an implementation based on the document and during the implementation provide feedback.

Production readiness

This project is still in alpha phase. In this stage the public API can change between days.

Beta version will be considered when the feature set covers the documents the implementation is based on, and the public API is reached a mature state.

Stable version will be considered only if enough positive feedback is gathered to lock the public API and all document the implementation is based on became "Internet Standard".

Documents

Official sites

Huge thanks to the Matroska.org for their work.

IETF Documents

Huge thanks to the IETF CELLAR Working Group for their work.

Inspiration

Inspiration for the implementation comes from the following places:

Similar libraries

Last updated: 2023-05-22

URL Status
https://github.com/at-wat/ebml-go In active development
https://github.com/ebml-go/ebml + https://github.com/ebml-go/webm Last updated on 17 Nov 2022
https://github.com/ehmry/go-ebml Deleted
https://github.com/jacereda/ebml Last updated on 10 Jan 2016
https://github.com/mediocregopher/ebmlstream Last updated on 15 Dec 2014
https://github.com/pankrator/ebml-parser Last updated on 24 Jun 2020
https://github.com/pixelbender/go-matroska Last updated on 29 Oct 2018
https://github.com/pubblic/ebml Last updated on 12 Dec 2018
https://github.com/quadrifoglio/go-mkv Last updated on 20 Jun 2018
https://github.com/rrerolle/ebml-go Last updated on 1 Dec 2012
https://github.com/remko/go-mkvparse Last updated on 19 May 2022
https://github.com/tpjg/ebml-go Last updated on 1 Dec 2012

Documentation

Overview

Package ebml implements a simple EBML parser.

The EBML specification is RFC 8794.

Index

Constants

This section is empty.

Variables

View Source
var (
	IDEBML                    schema.ElementID = 0x1a45dfa3
	IDEBMLVersion             schema.ElementID = 0x4286
	IDEBMLReadVersion         schema.ElementID = 0x42f7
	IDEBMLMaxIDLength         schema.ElementID = 0x42f2
	IDEBMLMaxSizeLength       schema.ElementID = 0x42f3
	IDDocType                 schema.ElementID = 0x4282
	IDDocTypeVersion          schema.ElementID = 0x4287
	IDDocTypeReadVersion      schema.ElementID = 0x4285
	IDDocTypeExtension        schema.ElementID = 0x4281
	IDDocTypeExtensionName    schema.ElementID = 0x4283
	IDDocTypeExtensionVersion schema.ElementID = 0x4284
	IDVoid                    schema.ElementID = 0xec
	IDCRC32                   schema.ElementID = 0xbf
)
View Source
var (
	HeaderDef *Def

	DefaultMaxIDLength   uint = 4
	DefaultMaxSizeLength uint = 8
)
View Source
var (
	TypeInteger  = "integer"
	TypeUinteger = "uinteger"
	TypeFloat    = "float"
	TypeString   = "string"
	TypeDate     = "date"
	TypeUTF8     = "utf-8"
	TypeMaster   = "master"
	TypeBinary   = "binary"
)
View Source
var ErrElementOverflow = errors.New("ebml: element overflow")

ErrElementOverflow signals that an element signals a length greater than the parent DataSize.

View Source
var ErrInvalidVINTLength = fmt.Errorf("ebml: invalid length descriptor")

Functions

func DocTypes

func DocTypes() []string

DocTypes returns a sorted list of the names of the registered document types.

func ReadElementID

func ReadElementID(r io.Reader, maxIDLength uint) (id schema.ElementID, n int, err error)

ReadElementID reads an Element ID based on https://datatracker.ietf.org/doc/html/rfc8794#section-5

func Register

func Register(docType string, s schema.Schema)

Register makes a schema.Schema available by the provided doc type. If Register is called twice with the same name or if driver is nil, it panics.

Types

type DataSize

type DataSize struct {
	// contains filtered or unexported fields
}

func NewKnownDataSize

func NewKnownDataSize(s int64) DataSize

func ReadElementDataSize

func ReadElementDataSize(r io.Reader, maxSizeLength uint) (ds DataSize, n int, err error)

ReadElementDataSize reads an Element ID based on https://datatracker.ietf.org/doc/html/rfc8794#section-6

func (*DataSize) Known

func (ds *DataSize) Known() bool

func (*DataSize) Size

func (ds *DataSize) Size() int64

type DecodeTypeError

type DecodeTypeError struct {
	EBMLType string       // description of EBML type - "integer", "binary", "master"
	Type     reflect.Type // type of Go value it could not be assigned to
	Offset   int64        // error occurred after reading Offset bytes
	Path     string       // the full path from root node to the field
}

An DecodeTypeError describes an EBML value that was not appropriate for a value of a specific Go type.

func (*DecodeTypeError) Error

func (e *DecodeTypeError) Error() string

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder represents an EBML parser reading a particular input stream.

func NewDecoder

func NewDecoder(r io.ReadSeeker) *Decoder

NewDecoder reads and parses an EBML Document from r.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

func (*Decoder) DecodeBody

func (d *Decoder) DecodeBody(v interface{}) error

DecodeBody decodes the EBML Body and stores the result in the value pointed to by v. If v is nil or not a pointer, DecodeBody returns an InvalidDecodeError.

func (*Decoder) DecodeHeader

func (d *Decoder) DecodeHeader() (*EBML, error)

DecodeHeader decodes the document header.

func (*Decoder) EndOfKnownDataSize

func (d *Decoder) EndOfKnownDataSize(parent Element, offset int64) (bool, error)

EndOfKnownDataSize tries to guess the end of an element which has a know data size.

A parent with unknown data size won't raise an error but not handled as the end of the parent.

func (*Decoder) EndOfUnknownDataSize

func (d *Decoder) EndOfUnknownDataSize(parent Element, el Element) (bool, error)

EndOfUnknownDataSize tries to guess the end of an element which has an unknown data size.

A parent with known data size won't raise an error but not handled as the end of the parent.

func (*Decoder) Next

func (d *Decoder) Next() (el Element, n int, err error)

Next reads the following element id and data size. It must be called before Decode.

func (*Decoder) NextOf

func (d *Decoder) NextOf(parent Element, offset int64) (el Element, n int, err error)

NextOf reads the following element id and data size related to the given parent Element.

When NextOf encounters an error or end-of-element condition it return EOE error.

func (*Decoder) Seek

func (d *Decoder) Seek(offset int64, whence int) (ret int64, err error)

type Def

type Def struct {
	Root schema.Element
	// contains filtered or unexported fields
}

func Definition

func Definition(docType string) (*Def, error)

func NewDef

func NewDef(s schema.Schema) (*Def, error)

func (*Def) Get

func (d *Def) Get(id schema.ElementID) (schema.Element, bool)

func (*Def) Values

func (d *Def) Values() []schema.Element

type DocTypeExtension

type DocTypeExtension struct {
	DocTypeExtensionName    string
	DocTypeExtensionVersion uint
}

type EBML

type EBML struct {
	EBMLVersion        uint
	EBMLReadVersion    uint
	EBMLMaxIDLength    uint
	EBMLMaxSizeLength  uint
	DocType            string
	DocTypeVersion     uint
	DocTypeReadVersion uint
	DocTypeExtension   []DocTypeExtension
}

type Element

type Element struct {
	ID       schema.ElementID
	DataSize DataSize
}

type InvalidDecodeError

type InvalidDecodeError struct {
	Type reflect.Type
}

An InvalidDecodeError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidDecodeError) Error

func (e *InvalidDecodeError) Error() string

type Reader

type Reader struct {

	// https://tools.ietf.org/html/rfc8794#section-11.2.4
	MaxIDLength uint
	// https://tools.ietf.org/html/rfc8794#section-11.2.5
	MaxSizeLength uint
	// contains filtered or unexported fields
}

Reader provides a low level API to interacts with EBML documents. Use directly with caution.

func NewReader

func NewReader(r io.ReadSeeker) *Reader

func (*Reader) Next

func (r *Reader) Next() (el Element, n int, err error)

Next reads the following element id and data size.

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (ret int64, err error)

type UnknownDefinitionError

type UnknownDefinitionError struct {
	// contains filtered or unexported fields
}

func (UnknownDefinitionError) Error

func (u UnknownDefinitionError) Error() string

func (UnknownDefinitionError) ID

type UnknownDocTypeError

type UnknownDocTypeError struct {
	DocType string
}

func (UnknownDocTypeError) Error

func (e UnknownDocTypeError) Error() string

type UnknownElementError

type UnknownElementError struct {
	// contains filtered or unexported fields
}

func (UnknownElementError) Error

func (e UnknownElementError) Error() string

Directories

Path Synopsis
Package schema contains structs for reading xml definitions for ebml schema.
Package schema contains structs for reading xml definitions for ebml schema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL