Documentation ¶
Index ¶
- func IsExported(typeName string) bool
- func Name(ty analysis.Type) string
- func ParseFunctionName(typeName string) string
- type Accu
- type Buffer
- type Context
- func (cc Context) ErrReturn(errVariable Err) string
- func (cc Context) ParsingFunc(origin *types.Named, args, scopes []string) Declaration
- func (cc Context) ParsingFuncComment(origin *types.Named, args, scopes []string, comment string) Declaration
- func (cc Context) Selector(field string) string
- func (cc *Context) SubSlice(subSlice Expression) string
- type Declaration
- type Err
- type ErrFormated
- type ErrVariable
- type Expression
- type Offset
- func (of *Offset) Increment(size analysis.BinarySize)
- func (of *Offset) SetStatement(value Expression) Expression
- func (of *Offset) UpdateStatement(size analysis.BinarySize) Expression
- func (of *Offset) UpdateStatementDynamic(size Expression) Expression
- func (of Offset) Value() Expression
- func (of Offset) With(size analysis.BinarySize) Expression
- func (of Offset) WithAffine(count Expression, size analysis.BinarySize) Expression
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsExported ¶
func Name ¶
Name returns the representation of the given type in generated code, either its local name or its String
func ParseFunctionName ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is used to accumulate and de-deduplicate function declarations
func NewBuffer ¶
NewBuffer returns a ready to use buffer, which will add the new decleration to [accu].
func (*Buffer) Add ¶
func (db *Buffer) Add(decl Declaration)
type Context ¶
type Context struct { // Type is the name of the type being generated Type Expression // ObjectVar if the name of the variable being parsed or dumped ObjectVar Expression // Slice is the name of the []byte being read or written Slice Expression // Offset holds the variable name for the current offset, // and its value when known at compile time Offset Offset // IgnoreUpdateOffset is true if the update offset statement // should not be written IgnoreUpdateOffset bool }
Context holds the names of the objects used in the generated code
func (Context) ParsingFunc ¶
func (cc Context) ParsingFunc(origin *types.Named, args, scopes []string) Declaration
ParsingFunc adds the context to the given [scopes] and [args]
func (Context) ParsingFuncComment ¶
func (cc Context) ParsingFuncComment(origin *types.Named, args, scopes []string, comment string) Declaration
ParsingFunc adds the context to the given [scopes] and [args], also adding the given comment as documentation
func (*Context) SubSlice ¶
func (cc *Context) SubSlice(subSlice Expression) string
SubSlice slices the current input slice at the current offset and assigns it to `subSlice`. It also updates the [Context.Slice] field
type Declaration ¶
Declaration is a chunk of generated go code, with an id used to avoid duplication
type Expression ¶
type Expression = string
Expression is a Go expression, such as a variable name, a static number, or an expression
func ArrayOffset ¶
func ArrayOffset(offset Expression, count Expression, elementSize int) Expression
ArrayOffset returns the expression for <offset> + <count> * <elementSize>, usable for offsets or array length
type Offset ¶
type Offset struct { // Name is the name of the variable containing the offset Name Expression // contains filtered or unexported fields }
Offset represents an offset in a byte of slice. It is designed to produce the optimal output regardless of whether its value is known at compile time or not.
func NewOffset ¶
func NewOffset(name Expression, initialValue int) Offset
func NewOffsetDynamic ¶
func NewOffsetDynamic(name Expression) Offset
func (*Offset) Increment ¶
func (of *Offset) Increment(size analysis.BinarySize)
Increment updates the current value, adding [size]. It is a no-op if the tracked value is unknown.
func (*Offset) SetStatement ¶
func (of *Offset) SetStatement(value Expression) Expression
SetStatement returns the code for <offset> = <value>, and remove the tracked value which is now unknown
func (*Offset) UpdateStatement ¶
func (of *Offset) UpdateStatement(size analysis.BinarySize) Expression
UpdateStatement returns a statement for <offset> += size, without changing the tracked value, since it has already been done with [Increment] calls. It also reset the temporary increment.
func (*Offset) UpdateStatementDynamic ¶
func (of *Offset) UpdateStatementDynamic(size Expression) Expression
UpdateStatementDynamic returns a statement for <offset> += size, and remove the tracked value which is now unknown.
func (Offset) Value ¶
func (of Offset) Value() Expression
Value returns the optimal Go expression for the offset current value.
func (Offset) With ¶
func (of Offset) With(size analysis.BinarySize) Expression
With returns the optimal expression for <offset> + <size>
func (Offset) WithAffine ¶
func (of Offset) WithAffine(count Expression, size analysis.BinarySize) Expression
WithAffine returns the optimal expression for <offset> + <count>*<size>