ufwb

package
v0.0.0-...-e96a773 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2016 License: BSD-2-Clause Imports: 17 Imported by: 1

Documentation

Overview

TODO Change Format API to have a FormatTo(.., io.writer), or similar, so we can avoid all the string concat.

TODO Move this file into a ints package

TODO This file is full of panics, because I don't know the correct way to deal with errors under Lua

TODO Consider moving this into a separate package, so that the parser can't use the unexported fields (and forced to go via Getters, which "do the right thing" wrt extending and defaults.

TODO Change the Validate to collect errors, instead of stopping on first TODO Use validationError as much as possible

Shout out to https://github.com/wicast/xj2s for helping to generate the XML structs TODO I have special ufwb tags, do I need them anymore?

Index

Constants

View Source
const (
	Black = Colour(0x000000)
	White = Colour(0xffffff)
)
View Source
const (
	UnknownEndian Endian = 0
	DynamicEndian        = 1
	BigEndian            = 2
	LittleEndian         = 3
)
View Source
const DEBUG = true
View Source
const MAX_STACK = 10
View Source
const MAX_VALUES = 10000

Variables

This section is empty.

Functions

func LogAtLevel

func LogAtLevel(level logrus.Level, args ...interface{})

func Walk

func Walk(u *Ufwb, walkFunc WalkFunc) []error

Walk walks the tree of Elements in depth-first order

func WalkFrom

func WalkFrom(u *Ufwb, element Element, walkFunc WalkFunc) []error

func WriteXmlGrammar

func WriteXmlGrammar(w io.Writer, ufwb *Ufwb) error

Types

type Base

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

Base is what all Elements implement

func (*Base) Description

func (b *Base) Description() string

func (*Base) GetBase

func (b *Base) GetBase() *Base

func (*Base) Id

func (b *Base) Id() int

func (*Base) IdString

func (b *Base) IdString() string

func (*Base) Name

func (b *Base) Name() string

type Binary

type Binary struct {
	Xml *XmlBinary

	Base
	Repeats
	Colourful
	// contains filtered or unexported fields
}

func (*Binary) Bytes

func (b *Binary) Bytes(file io.ReaderAt, value *Value) ([]byte, error)

Bytes returns the bytes from file, found at Value

func (*Binary) DeriveFrom

func (b *Binary) DeriveFrom(element Element) error

func (*Binary) Description

func (b *Binary) Description() string

func (*Binary) ElemType

func (b *Binary) ElemType() string

func (*Binary) FillColour

func (b *Binary) FillColour() Colour

func (*Binary) Format

func (b *Binary) Format(file io.ReaderAt, value *Value) (string, error)

func (*Binary) Id

func (b *Binary) Id() int

func (*Binary) Length

func (b *Binary) Length() Expression

func (*Binary) LengthUnit

func (b *Binary) LengthUnit() LengthUnit

func (*Binary) MustMatch

func (b *Binary) MustMatch() Bool

func (*Binary) Name

func (b *Binary) Name() string

func (*Binary) Read

func (b *Binary) Read(d *Decoder) (*Value, error)

func (*Binary) RepeatMax

func (b *Binary) RepeatMax() Expression

func (*Binary) RepeatMin

func (b *Binary) RepeatMin() Expression

func (*Binary) SetDescription

func (b *Binary) SetDescription(description string)

func (*Binary) SetFillColour

func (b *Binary) SetFillColour(fillColour Colour)

func (*Binary) SetId

func (b *Binary) SetId(id int)

func (*Binary) SetLength

func (b *Binary) SetLength(length Expression)

func (*Binary) SetLengthUnit

func (b *Binary) SetLengthUnit(lengthUnit LengthUnit)

func (*Binary) SetMustMatch

func (b *Binary) SetMustMatch(mustMatch Bool)

func (*Binary) SetName

func (b *Binary) SetName(name string)

func (*Binary) SetRepeatMax

func (b *Binary) SetRepeatMax(repeatMax Expression)

func (*Binary) SetRepeatMin

func (b *Binary) SetRepeatMin(repeatMin Expression)

func (*Binary) SetStrokeColour

func (b *Binary) SetStrokeColour(strokeColour Colour)

func (*Binary) SetValues

func (b *Binary) SetValues(values []*FixedBinaryValue)

func (*Binary) StrokeColour

func (b *Binary) StrokeColour() Colour

func (*Binary) Values

func (b *Binary) Values() []*FixedBinaryValue

type Bool

type Bool int8 // tri-state bool unset, false, true.
const (
	UnknownBool Bool = iota
	False
	True
)

No other value is allowed

type Colour

type Colour uint32

type Colourful

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

type ConstExpression

type ConstExpression int64

func (ConstExpression) String

func (e ConstExpression) String() string

type Custom

type Custom struct {
	Xml *XmlCustom

	Base
	Colourful
	// contains filtered or unexported fields
}

func (*Custom) DeriveFrom

func (c *Custom) DeriveFrom(element Element) error

func (*Custom) Description

func (c *Custom) Description() string

func (*Custom) ElemType

func (c *Custom) ElemType() string

func (*Custom) FillColour

func (c *Custom) FillColour() Colour

func (*Custom) Format

func (n *Custom) Format(file io.ReaderAt, value *Value) (string, error)

func (*Custom) Id

func (c *Custom) Id() int

func (*Custom) Length

func (c *Custom) Length() Expression

func (*Custom) LengthUnit

func (c *Custom) LengthUnit() LengthUnit

func (*Custom) Name

func (c *Custom) Name() string

func (*Custom) Read

func (c *Custom) Read(d *Decoder) (*Value, error)

func (*Custom) RepeatMax

func (*Custom) RepeatMax() Expression

func (*Custom) RepeatMin

func (*Custom) RepeatMin() Expression

func (*Custom) Script

func (c *Custom) Script() *Script

func (*Custom) SetDescription

func (c *Custom) SetDescription(description string)

func (*Custom) SetFillColour

func (c *Custom) SetFillColour(fillColour Colour)

func (*Custom) SetId

func (c *Custom) SetId(id int)

func (*Custom) SetLength

func (c *Custom) SetLength(length Expression)

func (*Custom) SetLengthUnit

func (c *Custom) SetLengthUnit(lengthUnit LengthUnit)

func (*Custom) SetName

func (c *Custom) SetName(name string)

func (*Custom) SetScript

func (c *Custom) SetScript(script *Script)

func (*Custom) SetStrokeColour

func (c *Custom) SetStrokeColour(strokeColour Colour)

func (*Custom) StrokeColour

func (c *Custom) StrokeColour() Colour

type Decoder

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

func NewDecoder

func NewDecoder(u *Ufwb, f input.Input) *Decoder

func NewDecoderWithBounds

func NewDecoderWithBounds(u *Ufwb, f input.Input, start, end int64) *Decoder

func (*Decoder) Bits

func (d *Decoder) Bits(length Expression, unit LengthUnit) (int64, error)

Bits returns the number of bits this length represents.

func (*Decoder) ByteOrder

func (d *Decoder) ByteOrder(e Endian) binary.ByteOrder

ByteOrder returns the current byte order TODO Delete this method

func (*Decoder) Bytes

func (d *Decoder) Bytes(length Expression, unit LengthUnit) (int64, error)

Bytes returns the number of bytes this length represents. If the unit is in bits, it rounds up or down.

func (*Decoder) Decode

func (d *Decoder) Decode() (*Value, error)

Decode decodes the input using the given grammar, returning a Value for as much as could be parsed as well as the first error encountered

func (*Decoder) ParentBounds

func (d *Decoder) ParentBounds() *ElementBounds

func (*Decoder) String

func (d *Decoder) String() string

type Derivable

type Derivable interface {
	DeriveFrom(parent Element) error
}

type Display

type Display int
const (
	UnknownDisplay Display = iota
	BinaryDisplay
	DecDisplay
	HexDisplay
)

func (Display) Base

func (d Display) Base() int

type ElementBounds

type ElementBounds struct {
	Element Element
	Start   int64 // Absolute byte offset of the start of these bounds
	End     int64 // Absolute byte offset of the end of these bounds
}

func (*ElementBounds) Length

func (bounds *ElementBounds) Length() int64

func (*ElementBounds) String

func (bounds *ElementBounds) String() string

type ElementId

type ElementId interface {
	Id() int
	Name() string
	Description() string

	IdString() string
}

ElementId holds the the basic identifer for a Element

type Elements

type Elements []Element

func (Elements) Find

func (e Elements) Find(name string) (int, Element)

func (Elements) Read

func (elements Elements) Read(d *Decoder, value *Value, order Order) (*Value, error)

type Endian

type Endian int

func FromByteOrder

func FromByteOrder(bo binary.ByteOrder) Endian

func (Endian) ByteOrder

func (e Endian) ByteOrder() binary.ByteOrder

TODO Move this somewhere else TODO Do we already have this somewhere?

type Eof

type Eof interface {
	IsEof() bool
}

type Expression

type Expression interface {
	fmt.Stringer
}

func NewExpression

func NewExpression(expr string) Expression

type FixedBinaryValue

type FixedBinaryValue struct {
	Xml *XmlFixedValue
	// contains filtered or unexported fields
}

type FixedStringValue

type FixedStringValue struct {
	Xml *XmlFixedValue
	// contains filtered or unexported fields
}

type FixedValue

type FixedValue struct {
	Xml *XmlFixedValue
	// contains filtered or unexported fields
}

TODO FixedValue is for what? Numbers? Rename to FixedNumberValue

type Formatter

type Formatter interface {
	// Format returns the display string for this Element.
	Format(file io.ReaderAt, value *Value) (string, error)
}

type Grammar

type Grammar struct {
	Xml *XmlGrammar

	Base
	Repeats

	Author   string
	Ext      string
	Email    string
	Complete Bool
	Uti      string

	Start    *Structure
	Scripts  []*Script
	Elements []Element
}

func (*Grammar) DeriveFrom

func (g *Grammar) DeriveFrom(element Element) error

func (*Grammar) Description

func (g *Grammar) Description() string

func (*Grammar) ElemType

func (g *Grammar) ElemType() string

func (*Grammar) Format

func (g *Grammar) Format(file io.ReaderAt, value *Value) (string, error)

func (*Grammar) Id

func (g *Grammar) Id() int

func (*Grammar) Length

func (g *Grammar) Length() Expression

func (*Grammar) LengthUnit

func (g *Grammar) LengthUnit() LengthUnit

func (*Grammar) Name

func (g *Grammar) Name() string

func (*Grammar) Read

func (g *Grammar) Read(d *Decoder) (*Value, error)

func (*Grammar) RepeatMax

func (g *Grammar) RepeatMax() Expression

func (*Grammar) RepeatMin

func (g *Grammar) RepeatMin() Expression

func (*Grammar) SetDescription

func (g *Grammar) SetDescription(description string)

func (*Grammar) SetId

func (g *Grammar) SetId(id int)

func (*Grammar) SetName

func (g *Grammar) SetName(name string)

func (*Grammar) SetRepeatMax

func (g *Grammar) SetRepeatMax(repeatMax Expression)

func (*Grammar) SetRepeatMin

func (g *Grammar) SetRepeatMin(repeatMin Expression)

type GrammarRef

type GrammarRef struct {
	Xml *XmlGrammarRef

	Base
	Repeats
	// contains filtered or unexported fields
}

func (*GrammarRef) DeriveFrom

func (g *GrammarRef) DeriveFrom(element Element) error

func (*GrammarRef) Description

func (g *GrammarRef) Description() string

func (*GrammarRef) Disabled

func (g *GrammarRef) Disabled() Bool

func (*GrammarRef) ElemType

func (g *GrammarRef) ElemType() string

func (*GrammarRef) Filename

func (g *GrammarRef) Filename() string

func (*GrammarRef) Format

func (n *GrammarRef) Format(file io.ReaderAt, value *Value) (string, error)

func (*GrammarRef) Grammar

func (g *GrammarRef) Grammar() *Grammar

func (*GrammarRef) Id

func (g *GrammarRef) Id() int

func (*GrammarRef) Length

func (g *GrammarRef) Length() Expression

func (*GrammarRef) LengthUnit

func (g *GrammarRef) LengthUnit() LengthUnit

func (*GrammarRef) Name

func (g *GrammarRef) Name() string

func (*GrammarRef) Read

func (g *GrammarRef) Read(d *Decoder) (*Value, error)

func (*GrammarRef) RepeatMax

func (g *GrammarRef) RepeatMax() Expression

func (*GrammarRef) RepeatMin

func (g *GrammarRef) RepeatMin() Expression

func (*GrammarRef) SetDescription

func (g *GrammarRef) SetDescription(description string)

func (*GrammarRef) SetDisabled

func (g *GrammarRef) SetDisabled(disabled Bool)

func (*GrammarRef) SetFilename

func (g *GrammarRef) SetFilename(filename string)

func (*GrammarRef) SetGrammar

func (g *GrammarRef) SetGrammar(grammar *Grammar)

func (*GrammarRef) SetId

func (g *GrammarRef) SetId(id int)

func (*GrammarRef) SetName

func (g *GrammarRef) SetName(name string)

func (*GrammarRef) SetRepeatMax

func (g *GrammarRef) SetRepeatMax(repeatMax Expression)

func (*GrammarRef) SetRepeatMin

func (g *GrammarRef) SetRepeatMin(repeatMin Expression)

func (*GrammarRef) SetUti

func (g *GrammarRef) SetUti(uti string)

func (*GrammarRef) Uti

func (g *GrammarRef) Uti() string

type LengthUnit

type LengthUnit int
const (
	UnknownLengthUnit LengthUnit = iota
	BitLengthUnit
	ByteLengthUnit
)

type Lengthable

type Lengthable interface {
	Length() Expression
	LengthUnit() LengthUnit
}

type Mask

type Mask struct {
	Xml *XmlMask
	// contains filtered or unexported fields
}

type Number

type Number struct {
	Xml *XmlNumber

	Base
	Repeats
	Colourful

	Type string // TODO Convert to Type
	// contains filtered or unexported fields
}

func (*Number) DeriveFrom

func (n *Number) DeriveFrom(element Element) error

func (*Number) Description

func (n *Number) Description() string

func (*Number) Display

func (n *Number) Display() Display

func (*Number) ElemType

func (n *Number) ElemType() string

func (*Number) Endian

func (n *Number) Endian() Endian

func (*Number) FillColour

func (n *Number) FillColour() Colour

func (*Number) Format

func (n *Number) Format(file io.ReaderAt, value *Value) (string, error)

func (*Number) Id

func (n *Number) Id() int

func (*Number) Int

func (n *Number) Int(file io.ReaderAt, value *Value) (int64, error)

Int returns the value this file/value refers to cast to a int64.

func (*Number) Length

func (n *Number) Length() Expression

func (*Number) LengthUnit

func (n *Number) LengthUnit() LengthUnit

func (*Number) Masks

func (n *Number) Masks() []*Mask

func (*Number) MaxVal

func (n *Number) MaxVal() string

func (*Number) MinVal

func (n *Number) MinVal() string

func (*Number) MustMatch

func (n *Number) MustMatch() Bool

func (*Number) Name

func (n *Number) Name() string

func (*Number) Read

func (n *Number) Read(d *Decoder) (*Value, error)

func (*Number) RepeatMax

func (n *Number) RepeatMax() Expression

func (*Number) RepeatMin

func (n *Number) RepeatMin() Expression

func (*Number) SetDescription

func (n *Number) SetDescription(description string)

func (*Number) SetDisplay

func (n *Number) SetDisplay(display Display)

func (*Number) SetEndian

func (n *Number) SetEndian(endian Endian)

func (*Number) SetFillColour

func (n *Number) SetFillColour(fillColour Colour)

func (*Number) SetId

func (n *Number) SetId(id int)

func (*Number) SetLength

func (n *Number) SetLength(length Expression)

func (*Number) SetLengthUnit

func (n *Number) SetLengthUnit(lengthUnit LengthUnit)

func (*Number) SetMasks

func (n *Number) SetMasks(masks []*Mask)

func (*Number) SetMaxVal

func (n *Number) SetMaxVal(maxVal string)

func (*Number) SetMinVal

func (n *Number) SetMinVal(minVal string)

func (*Number) SetMustMatch

func (n *Number) SetMustMatch(mustMatch Bool)

func (*Number) SetName

func (n *Number) SetName(name string)

func (*Number) SetRepeatMax

func (n *Number) SetRepeatMax(repeatMax Expression)

func (*Number) SetRepeatMin

func (n *Number) SetRepeatMin(repeatMin Expression)

func (*Number) SetSigned

func (n *Number) SetSigned(signed bool)

func (*Number) SetStrokeColour

func (n *Number) SetStrokeColour(strokeColour Colour)

func (*Number) SetValueExpression

func (n *Number) SetValueExpression(valueExpression string)

func (*Number) SetValues

func (n *Number) SetValues(values []*FixedValue)

func (*Number) Signed

func (n *Number) Signed() bool

func (*Number) StrokeColour

func (n *Number) StrokeColour() Colour

func (*Number) Uint

func (n *Number) Uint(file io.ReaderAt, value *Value) (uint64, error)

Uint returns the value this file/value refers to cast to a uint64.

func (*Number) ValueExpression

func (n *Number) ValueExpression() string

func (*Number) Values

func (n *Number) Values() []*FixedValue

type Offset

type Offset struct {
	Xml *XmlOffset

	Base
	Repeats
	Colourful
	// contains filtered or unexported fields
}

TODO Support parsing the Offsets

func (*Offset) Additional

func (o *Offset) Additional() string

func (*Offset) DeriveFrom

func (o *Offset) DeriveFrom(element Element) error

func (*Offset) Description

func (o *Offset) Description() string

func (*Offset) Display

func (o *Offset) Display() Display

func (*Offset) ElemType

func (o *Offset) ElemType() string

func (*Offset) Endian

func (o *Offset) Endian() Endian

func (*Offset) FillColour

func (o *Offset) FillColour() Colour

func (*Offset) FollowNullReference

func (o *Offset) FollowNullReference() Bool

func (*Offset) Format

func (n *Offset) Format(file io.ReaderAt, value *Value) (string, error)

func (*Offset) Id

func (o *Offset) Id() int

func (*Offset) Length

func (o *Offset) Length() Expression

func (*Offset) LengthUnit

func (o *Offset) LengthUnit() LengthUnit

func (*Offset) Name

func (o *Offset) Name() string

func (*Offset) Read

func (o *Offset) Read(d *Decoder) (*Value, error)

func (*Offset) ReferencedSize

func (o *Offset) ReferencedSize() ElementId

func (*Offset) References

func (o *Offset) References() ElementId

func (*Offset) RelativeTo

func (o *Offset) RelativeTo() ElementId

func (*Offset) RepeatMax

func (o *Offset) RepeatMax() Expression

func (*Offset) RepeatMin

func (o *Offset) RepeatMin() Expression

func (*Offset) SetAdditional

func (o *Offset) SetAdditional(additional string)

func (*Offset) SetDescription

func (o *Offset) SetDescription(description string)

func (*Offset) SetDisplay

func (o *Offset) SetDisplay(display Display)

func (*Offset) SetEndian

func (o *Offset) SetEndian(endian Endian)

func (*Offset) SetFillColour

func (o *Offset) SetFillColour(fillColour Colour)

func (*Offset) SetFollowNullReference

func (o *Offset) SetFollowNullReference(followNullReference Bool)

func (*Offset) SetId

func (o *Offset) SetId(id int)

func (*Offset) SetLength

func (o *Offset) SetLength(length Expression)

func (*Offset) SetLengthUnit

func (o *Offset) SetLengthUnit(lengthUnit LengthUnit)

func (*Offset) SetName

func (o *Offset) SetName(name string)

func (*Offset) SetReferencedSize

func (o *Offset) SetReferencedSize(referencedSize ElementId)

func (*Offset) SetReferences

func (o *Offset) SetReferences(references ElementId)

func (*Offset) SetRelativeTo

func (o *Offset) SetRelativeTo(relativeTo ElementId)

func (*Offset) SetRepeatMax

func (o *Offset) SetRepeatMax(repeatMax Expression)

func (*Offset) SetRepeatMin

func (o *Offset) SetRepeatMin(repeatMin Expression)

func (*Offset) SetStrokeColour

func (o *Offset) SetStrokeColour(strokeColour Colour)

func (*Offset) StrokeColour

func (o *Offset) StrokeColour() Colour

type Order

type Order int
const (
	UnknownOrder Order = iota
	FixedOrder         // TODO Check this is the right name
	VariableOrder
)

type Padding

type Padding struct {
	Base
}

Padding is a pseudo Element created to represent unspecified regions in a file.

func (*Padding) DeriveFrom

func (*Padding) DeriveFrom(e Element) error

func (*Padding) Format

func (p *Padding) Format(file io.ReaderAt, value *Value) (string, error)

func (*Padding) Length

func (*Padding) Length() Expression

func (*Padding) LengthUnit

func (*Padding) LengthUnit() LengthUnit

func (*Padding) Read

func (p *Padding) Read(d *Decoder) (*Value, error)

func (*Padding) RepeatMax

func (*Padding) RepeatMax() Expression

func (*Padding) RepeatMin

func (*Padding) RepeatMin() Expression

type Reader

type Reader interface {
	// Read from file and return a Value.
	// The Read method must leave the file offset at Value.Offset + Value.Len // TODO Enforce this!
	// Read should return what has been parsed, and any error encountered.
	// If no bytes could be read, then <nil, io.EOF> is returned.
	Read(decoder *Decoder) (*Value, error)
}

type Repeatable

type Repeatable interface {
	RepeatMin() Expression
	RepeatMax() Expression
}

type Repeats

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

type Script

type Script struct {
	Xml *XmlScriptElement

	Base
	Repeats

	XmlScript *XmlScript
	// contains filtered or unexported fields
}

func (*Script) DeriveFrom

func (o *Script) DeriveFrom(element Element) error

func (*Script) Description

func (s *Script) Description() string

func (*Script) ElemType

func (s *Script) ElemType() string

func (*Script) Format

func (n *Script) Format(file io.ReaderAt, value *Value) (string, error)

func (*Script) Id

func (s *Script) Id() int

func (*Script) Language

func (s *Script) Language() string

func (*Script) Length

func (s *Script) Length() Expression

func (*Script) LengthUnit

func (s *Script) LengthUnit() LengthUnit

func (*Script) Name

func (s *Script) Name() string

func (*Script) Read

func (s *Script) Read(d *Decoder) (*Value, error)

func (*Script) RepeatMax

func (s *Script) RepeatMax() Expression

func (*Script) RepeatMin

func (s *Script) RepeatMin() Expression

func (*Script) RunLua

func (s *Script) RunLua(d *Decoder) error

func (*Script) SetDescription

func (s *Script) SetDescription(description string)

func (*Script) SetId

func (s *Script) SetId(id int)

func (*Script) SetLanguage

func (s *Script) SetLanguage(language string)

func (*Script) SetName

func (s *Script) SetName(name string)

func (*Script) SetRepeatMax

func (s *Script) SetRepeatMax(repeatMax Expression)

func (*Script) SetRepeatMin

func (s *Script) SetRepeatMin(repeatMin Expression)

func (*Script) SetText

func (s *Script) SetText(text string)

func (*Script) SetTyp

func (s *Script) SetTyp(typ string)

func (*Script) Text

func (s *Script) Text() string

func (*Script) Typ

func (s *Script) Typ() string

type StackPrinter

type StackPrinter []ElementBounds

func (StackPrinter) String

func (stack StackPrinter) String() string

type String

type String struct {
	Xml *XmlString

	Base
	Repeats
	Colourful
	// contains filtered or unexported fields
}

func (*String) Delimiter

func (s *String) Delimiter() byte

func (*String) DeriveFrom

func (s *String) DeriveFrom(element Element) error

func (*String) Description

func (s *String) Description() string

func (*String) ElemType

func (s *String) ElemType() string

func (*String) Encoding

func (s *String) Encoding() string

func (*String) FillColour

func (s *String) FillColour() Colour

func (*String) Format

func (s *String) Format(file io.ReaderAt, value *Value) (string, error)

func (*String) Id

func (s *String) Id() int

func (*String) Length

func (s *String) Length() Expression

func (*String) LengthUnit

func (s *String) LengthUnit() LengthUnit

func (*String) MustMatch

func (s *String) MustMatch() Bool

func (*String) Name

func (s *String) Name() string

func (*String) Read

func (s *String) Read(d *Decoder) (*Value, error)

func (*String) RepeatMax

func (s *String) RepeatMax() Expression

func (*String) RepeatMin

func (s *String) RepeatMin() Expression

func (*String) SetDelimiter

func (s *String) SetDelimiter(delimiter byte)

func (*String) SetDescription

func (s *String) SetDescription(description string)

func (*String) SetEncoding

func (s *String) SetEncoding(encoding string)

func (*String) SetFillColour

func (s *String) SetFillColour(fillColour Colour)

func (*String) SetId

func (s *String) SetId(id int)

func (*String) SetLength

func (s *String) SetLength(length Expression)

func (*String) SetLengthUnit

func (s *String) SetLengthUnit(lengthUnit LengthUnit)

func (*String) SetMustMatch

func (s *String) SetMustMatch(mustMatch Bool)

func (*String) SetName

func (s *String) SetName(name string)

func (*String) SetRepeatMax

func (s *String) SetRepeatMax(repeatMax Expression)

func (*String) SetRepeatMin

func (s *String) SetRepeatMin(repeatMin Expression)

func (*String) SetStrokeColour

func (s *String) SetStrokeColour(strokeColour Colour)

func (*String) SetTyp

func (s *String) SetTyp(typ string)

func (*String) SetValues

func (s *String) SetValues(values []*FixedStringValue)

func (*String) StrokeColour

func (s *String) StrokeColour() Colour

func (*String) Typ

func (s *String) Typ() string

func (*String) Values

func (s *String) Values() []*FixedStringValue

type StringExpression

type StringExpression string

StringExpression needs to be evaluated

func (StringExpression) String

func (e StringExpression) String() string

type StructRef

type StructRef struct {
	Xml *XmlStructRef

	Base
	Repeats
	Colourful
	// contains filtered or unexported fields
}

func (*StructRef) DeriveFrom

func (s *StructRef) DeriveFrom(element Element) error

func (*StructRef) Description

func (s *StructRef) Description() string

func (*StructRef) Disabled

func (s *StructRef) Disabled() Bool

func (*StructRef) ElemType

func (s *StructRef) ElemType() string

func (*StructRef) FillColour

func (s *StructRef) FillColour() Colour

func (*StructRef) Format

func (n *StructRef) Format(file io.ReaderAt, value *Value) (string, error)

func (*StructRef) Id

func (s *StructRef) Id() int

func (*StructRef) Length

func (s *StructRef) Length() Expression

func (*StructRef) LengthUnit

func (s *StructRef) LengthUnit() LengthUnit

func (*StructRef) Name

func (s *StructRef) Name() string

func (*StructRef) Read

func (s *StructRef) Read(d *Decoder) (*Value, error)

func (*StructRef) RepeatMax

func (s *StructRef) RepeatMax() Expression

func (*StructRef) RepeatMin

func (s *StructRef) RepeatMin() Expression

func (*StructRef) SetDescription

func (s *StructRef) SetDescription(description string)

func (*StructRef) SetDisabled

func (s *StructRef) SetDisabled(disabled Bool)

func (*StructRef) SetFillColour

func (s *StructRef) SetFillColour(fillColour Colour)

func (*StructRef) SetId

func (s *StructRef) SetId(id int)

func (*StructRef) SetName

func (s *StructRef) SetName(name string)

func (*StructRef) SetRepeatMax

func (s *StructRef) SetRepeatMax(repeatMax Expression)

func (*StructRef) SetRepeatMin

func (s *StructRef) SetRepeatMin(repeatMin Expression)

func (*StructRef) SetStrokeColour

func (s *StructRef) SetStrokeColour(strokeColour Colour)

func (*StructRef) SetStructure

func (s *StructRef) SetStructure(structure *Structure)

func (*StructRef) StrokeColour

func (s *StructRef) StrokeColour() Colour

func (*StructRef) Structure

func (s *StructRef) Structure() *Structure

type Structure

type Structure struct {
	Xml *XmlStructure

	Base
	Repeats
	Colourful
	// contains filtered or unexported fields
}

func (*Structure) DeriveFrom

func (s *Structure) DeriveFrom(element Element) error

func (*Structure) Description

func (s *Structure) Description() string

func (*Structure) Display

func (s *Structure) Display() Display

func (*Structure) ElemType

func (s *Structure) ElemType() string

func (*Structure) ElementByName

func (s *Structure) ElementByName(name string) Element

ElementByName returns a child element with this name, or nil

func (*Structure) Elements

func (s *Structure) Elements() []Element

TODO Precompute this

func (*Structure) Encoding

func (s *Structure) Encoding() string

func (*Structure) Endian

func (s *Structure) Endian() Endian

func (*Structure) FillColour

func (s *Structure) FillColour() Colour

func (*Structure) Format

func (n *Structure) Format(file io.ReaderAt, value *Value) (string, error)

func (*Structure) Id

func (s *Structure) Id() int

func (*Structure) Length

func (s *Structure) Length() Expression

func (*Structure) LengthOffset

func (s *Structure) LengthOffset() Expression

func (*Structure) LengthUnit

func (s *Structure) LengthUnit() LengthUnit

func (*Structure) Name

func (s *Structure) Name() string

func (*Structure) Order

func (s *Structure) Order() Order

func (*Structure) Read

func (s *Structure) Read(d *Decoder) (*Value, error)

func (*Structure) RepeatMax

func (s *Structure) RepeatMax() Expression

func (*Structure) RepeatMin

func (s *Structure) RepeatMin() Expression

func (*Structure) SetDescription

func (s *Structure) SetDescription(description string)

func (*Structure) SetDisplay

func (s *Structure) SetDisplay(display Display)

func (*Structure) SetElements

func (s *Structure) SetElements(elements []Element)

func (*Structure) SetEncoding

func (s *Structure) SetEncoding(encoding string)

func (*Structure) SetEndian

func (s *Structure) SetEndian(endian Endian)

func (*Structure) SetFillColour

func (s *Structure) SetFillColour(fillColour Colour)

func (*Structure) SetId

func (s *Structure) SetId(id int)

func (*Structure) SetLength

func (s *Structure) SetLength(length Expression)

func (*Structure) SetLengthOffset

func (s *Structure) SetLengthOffset(lengthOffset Expression)

func (*Structure) SetLengthUnit

func (s *Structure) SetLengthUnit(lengthUnit LengthUnit)

func (*Structure) SetName

func (s *Structure) SetName(name string)

func (*Structure) SetOrder

func (s *Structure) SetOrder(order Order)

func (*Structure) SetRepeatMax

func (s *Structure) SetRepeatMax(repeatMax Expression)

func (*Structure) SetRepeatMin

func (s *Structure) SetRepeatMin(repeatMin Expression)

func (*Structure) SetSigned

func (s *Structure) SetSigned(signed bool)

func (*Structure) SetStrokeColour

func (s *Structure) SetStrokeColour(strokeColour Colour)

func (*Structure) Signed

func (s *Structure) Signed() bool

func (*Structure) StrokeColour

func (s *Structure) StrokeColour() Colour

type Transformable

type Transformable interface {
	// contains filtered or unexported methods
}

TODO Rename to TransformToElement or similar

type Ufwb

type Ufwb struct {
	Xml *XmlUfwb

	Version string
	Grammar *Grammar

	Elements map[string]Element
	Scripts  map[string]*Script
}

func ParseXmlGrammar

func ParseXmlGrammar(r io.Reader) (*Ufwb, []error)

func (*Ufwb) Format

func (u *Ufwb) Format(file io.ReaderAt, value *Value) (string, error)

func (*Ufwb) Get

func (u *Ufwb) Get(id string) (Element, bool)

func (*Ufwb) GetScript

func (u *Ufwb) GetScript(id string) (*Script, bool)

func (*Ufwb) Read

func (u *Ufwb) Read(d *Decoder) (*Value, error)

type Updatable

type Updatable interface {
	// contains filtered or unexported methods
}

type Value

type Value struct {
	Offset  int64 // In bytes from the beginning of the file
	Len     int64 // In bytes
	Element Element
	Extra   interface{} // Extra info defined by the Element

	Children []*Value

	ByteOrder binary.ByteOrder // Only used for Number, TODO, and TODO. Why have this?
}

Value represents one of the parsed elements in the file. It doesn't contain the element, just the offset where it starts, and which element it is.

func (*Value) Description

func (v *Value) Description() string

func (*Value) Format

func (v *Value) Format(file io.ReaderAt) (string, error)

String returns this value's string representation (based on display, etc)

func (*Value) Name

func (v *Value) Name() string

func (*Value) String

func (v *Value) String() string

func (*Value) Write

func (v *Value) Write(f input.Input)

type WalkFunc

type WalkFunc func(root *Ufwb, element Element, parent *Structure, errs *toerr.Errors)

TODO Move Errors out of this API, we shouldn't expose that, instead return a single error

type XmlBinary

type XmlBinary struct {
	XMLName xml.Name `xml:"binary"`

	XmlIdName
	XmlRepeats

	Length     string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"` // "bit"

	MustMatch string `xml:"mustmatch,attr,omitempty"  ufwb:"bool"`
	Unused    string `xml:"unused,attr,omitempty" ufwb:"bool"`
	Disabled  string `xml:"disabled,attr,omitempty" ufwb:"bool"`

	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`

	Values []*XmlFixedValue `xml:"fixedvalue,omitempty"`
}

func (*XmlBinary) UnmarshalXML

func (b *XmlBinary) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type XmlCustom

type XmlCustom struct {
	XMLName xml.Name `xml:"custom"`

	XmlIdName

	Length     string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"`

	Script string `xml:"script,attr,omitempty" ufwb:"id"`

	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`
}

type XmlElement

type XmlElement interface {
	Transformable
}

TODO Ensure all elements can be disabled, and perhaps move IdName into XmlElement

type XmlFixedValue

type XmlFixedValue struct {
	XMLName xml.Name `xml:"fixedvalue"`

	Name  string `xml:"name,attr,omitempty"`
	Value string `xml:"value,attr,omitempty"`

	Description string `xml:"description,omitempty"`
}

type XmlFixedValues

type XmlFixedValues struct {
	XMLName xml.Name `xml:"fixedvalues"`

	Values []*XmlFixedValue `xml:"fixedvalue,omitempty"`
}

type XmlGrammar

type XmlGrammar struct {
	XMLName xml.Name `xml:"grammar"`

	XmlIdName

	Author   string `xml:"author,attr,omitempty"`
	Ext      string `xml:"fileextension,attr,omitempty"`
	Email    string `xml:"email,attr,omitempty"`
	Complete string `xml:"complete,attr,omitempty" ufwb:"bool"`
	Uti      string `xml:"uti,attr,omitempty"`

	Start      string          `xml:"start,attr,omitempty" ufwb:"id"`
	Scripts    XmlScripts      `xml:"scripts"`
	Structures []*XmlStructure `xml:"structure,omitempty"`
}

type XmlGrammarRef

type XmlGrammarRef struct {
	XMLName xml.Name `xml:"grammarref"`

	XmlIdName

	Uti      string `xml:"uti,attr,omitempty"`
	Filename string `xml:"filename,attr,omitempty"`
	Disabled string `xml:"disabled,attr,omitempty" ufwb:"bool"`
}

type XmlIdName

type XmlIdName struct {
	Id          int    `xml:"id,attr,omitempty"`
	Name        string `xml:"name,attr,omitempty"`
	Description string `xml:"description,omitempty"`
}

type XmlMask

type XmlMask struct {
	XMLName xml.Name `xml:"mask"`

	Name        string `xml:"name,attr,omitempty"`
	Value       string `xml:"value,attr,omitempty"`
	Description string `xml:"description,omitempty"`

	Values []*XmlFixedValue `xml:"fixedvalue,omitempty"`
}

type XmlNumber

type XmlNumber struct {
	XMLName xml.Name `xml:"number"`

	XmlIdName
	XmlRepeats

	Type       string `xml:"type,attr,omitempty" ufwb:"number-type"`
	Length     string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"` // "", "bit" (default "byte")

	Endian          string `xml:"endian,attr,omitempty" ufwb:"endian"` // "", "big", "little", "dynamic"
	Signed          string `xml:"signed,attr,omitempty" ufwb:"bool"`   // "", "yes", "no"
	MustMatch       string `xml:"mustmatch,attr,omitempty" ufwb:"bool"`
	ValueExpression string `xml:"valueexpression,attr,omitempty"`

	MinVal string `xml:"minval,attr,omitempty" ufwb:"ref"`
	MaxVal string `xml:"maxval,attr,omitempty" ufwb:"ref"`

	Display      string `xml:"display,attr,omitempty" ufwb:"display"`
	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`

	Disabled string `xml:"disabled,attr,omitempty" ufwb:"bool"`

	Values []*XmlFixedValue `xml:"fixedvalue,omitempty"`
	Masks  []*XmlMask       `xml:"mask,omitempty"`
}

func (*XmlNumber) UnmarshalXML

func (n *XmlNumber) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type XmlOffset

type XmlOffset struct {
	XMLName xml.Name `xml:"offset"`

	XmlIdName
	XmlRepeats

	Length              string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit          string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"` // "", "bit" (default "byte")
	Endian              string `xml:"endian,attr,omitempty" ufwb:"endian"`
	RelativeTo          string `xml:"relative-to,attr,omitempty" ufwb:"id"`
	FollowNullReference string `xml:"follownullreference,attr,omitempty"`
	References          string `xml:"references,attr,omitempty" ufwb:"id"`
	ReferencedSize      string `xml:"referenced-size,attr,omitempty" ufwb:"id"`
	Additional          string `xml:"additional,attr,omitempty"` // "stringOffset"

	Display      string `xml:"display,attr,omitempty" ufwb:"display"` // "", "hex", "offset"
	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`
}

type XmlRepeats

type XmlRepeats struct {
	RepeatMin string `xml:"repeatmin,attr,omitempty" ufwb:"ref"`
	RepeatMax string `xml:"repeatmax,attr,omitempty" ufwb:"ref"`
}

type XmlScript

type XmlScript struct {
	XMLName xml.Name `xml:"script"`

	XmlIdName

	Type     string     `xml:"type,attr,omitempty"` // DataType, Grammar, Generic
	Language string     `xml:"language,attr,omitempty" ufwb:"lang"`
	Source   *XmlSource `xml:"source,omitempty"`

	// Sometimes the text is defined here, or in the child Source element (example esf.grammar)
	Text string `xml:",chardata"` // TODO Should this be cdata?
}

func (*XmlScript) UnmarshalXML

func (s *XmlScript) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type XmlScriptElement

type XmlScriptElement struct {
	XMLName xml.Name `xml:"scriptelement"`

	XmlIdName
	XmlRepeats

	Disabled string `xml:"disabled,attr,omitempty" ufwb:"bool"`

	Script *XmlScript `xml:"script"`
}

type XmlScripts

type XmlScripts []*XmlScript

func (XmlScripts) MarshalXML

func (s XmlScripts) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*XmlScripts) UnmarshalXML

func (s *XmlScripts) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type XmlSource

type XmlSource struct {
	XMLName xml.Name `xml:"source"`

	Language string `xml:"language,attr,omitempty" ufwb:"lang"`
	Text     string `xml:",chardata"` // TODO Should this be cdata?
	// contains filtered or unexported fields
}

type XmlString

type XmlString struct {
	XMLName xml.Name `xml:"string"`

	XmlIdName
	XmlRepeats

	Type string `xml:"type,attr,omitempty" ufwb:"string-type"` // "zero-terminated", "fixed-length"

	Length     string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"`

	Encoding  string `xml:"encoding,attr,omitempty" ufwb:"encoding"` // Should be valid encoding
	MustMatch string `xml:"mustmatch,attr,omitempty" ufwb:"bool"`    // "yes", "no"

	Delimiter string `xml:"delimiter,attr,omitempty"`

	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`

	Values []*XmlFixedValue `xml:"fixedvalue,omitempty"`
}

func (*XmlString) UnmarshalXML

func (s *XmlString) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type XmlStructRef

type XmlStructRef struct {
	XMLName xml.Name `xml:"structref"`

	XmlIdName
	XmlRepeats

	Structure string `xml:"structure,attr,omitempty" ufwb:"id"`

	Disabled string `xml:"disabled,attr,omitempty" ufwb:"bool"`

	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`
}

type XmlStructure

type XmlStructure struct {
	XMLName xml.Name `xml:"structure"`

	XmlIdName
	XmlRepeats

	Length     string `xml:"length,attr,omitempty" ufwb:"ref"`
	LengthUnit string `xml:"lengthunit,attr,omitempty" ufwb:"lengthunit"`

	LengthOffset string `xml:"lengthoffset,attr,omitempty"`

	Endian    string `xml:"endian,attr,omitempty" ufwb:"endian"`
	Signed    string `xml:"signed,attr,omitempty" ufwb:"bool"`
	Extends   string `xml:"extends,attr,omitempty" ufwb:"id"`
	Order     string `xml:"order,attr,omitempty"`
	Encoding  string `xml:"encoding,attr,omitempty" ufwb:"encoding"`
	Alignment string `xml:"alignment,attr,omitempty"` // ??

	Floating   string `xml:"floating,attr,omitempty"` // ??
	ConsistsOf string `xml:"consists-of,attr,omitempty" ufwb:"id"`

	Repeat string `xml:"repeat,attr,omitempty" ufwb:"id"` // TODO What is this field?

	ValueExpression string `xml:"valueexpression,attr,omitempty"`
	Debug           string `xml:"debug,attr,omitempty" ufwb:"bool"`
	Disabled        string `xml:"disabled,attr,omitempty" ufwb:"bool"`

	Display      string `xml:"display,attr,omitempty" ufwb:"display"`
	FillColour   string `xml:"fillcolor,attr,omitempty" ufwb:"colour"`
	StrokeColour string `xml:"strokecolor,attr,omitempty" ufwb:"colour"`

	Elements []XmlElement `xml:",any"`
}

func (*XmlStructure) UnmarshalXML

func (s *XmlStructure) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML correctly unmarshals a Structure and its children. This is needed because Go's xml parser doesn't handle the multiple unknown element, that need to be kept in order.

type XmlUfwb

type XmlUfwb struct {
	XMLName xml.Name `xml:"ufwb"`

	Version string      `xml:"version,attr,omitempty"`
	Grammar *XmlGrammar `xml:"grammar"`
}

Jump to

Keyboard shortcuts

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