Documentation
¶
Overview ¶
Package bebop provides structures, tokenizing, parsing, and code generation for the bebop file type
Index ¶
Constants ¶
const Version = "v0.6.2"
Version is the library version. Should be used by CLI tools when passed a '--version' flag.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Const ¶ added in v0.1.4
type Const struct {
// Consts do not support map or array (or record) types
SimpleType string
Comment string
Name string
Value string
}
A const is a simple type - value pair that is compiled as a constant into generated code.
type Enum ¶
type Enum struct {
Name string
Comment string
Options []EnumOption
// Namespace is only provided for imported types, and only
// used in code generation.
Namespace string
// SimpleType is an integer or unsigned integer type. If not
// otherwise specified, it defaults to uint32
SimpleType string
Unsigned bool
}
An Enum is a definition that will generate typed enumerable options.
func (Enum) Generate ¶
func (en Enum) Generate(w *iohelp.ErrorWriter, settings GenerateSettings)
Generate writes a .go enum definition out to w.
type EnumOption ¶
type EnumOption struct {
Name string
Comment string
// DeprecatedMessage is only provided if Deprecated is true.
DeprecatedMessage string
// Only one of Value or UintValue should e populated, dependant on
// if the enum this option applies to is unsigned.
Value int64
UintValue uint64
Deprecated bool
}
An EnumOption is one possible value for a field typed as a specific Enum.
type Field ¶
type Field struct {
FieldType
Name string
Comment string
// Tags are not written by default, and must be enabled via a compiler flag.
Tags []Tag
// DeprecatedMessage is only provided if Deprecated is true.
DeprecatedMessage string
Deprecated bool
}
A Field is an individual, typed data component making up a Struct or Message.
type FieldType ¶
A FieldType is a union of three choices: Simple types, array types, and map types. Only one of the three should be provided for a given FieldType.
type File ¶
type File struct {
// FileName is an optional argument defining where this
// bebop file came from. This argument is only used to
// determine where relative import files lie. If relative
// imports are not used, this argument is not read. If
// FileName is a relative path, it will be treated as
// relative to os.Getwd().
FileName string
// GoPackage is the value of this file's go_package const,
// should it be defined and string-typed.
GoPackage string
Structs []Struct
Messages []Message
Enums []Enum
Unions []Union
Consts []Const
Imports []string
}
A File is a structured representation of a .bop file.
func ReadFile ¶
ReadFile reads out a bebop file. If r is a FileNamer, like an *os.File, the output's FileName will be populated. In addition to fatal errors, string warnings may also be output.
type GenerateSettings ¶
type GenerateSettings struct {
// PackageName is optional if the target bebop file defines a go_package
// constant. If both are provided, PackageName will take precedence.
PackageName string
ImportGenerationMode
GenerateUnsafeMethods bool
GenerateFieldTags bool
PrivateDefinitions bool
AlwaysUsePointerReceivers bool
// contains filtered or unexported fields
}
GenerateSettings holds customization options for what Generate should do.
func (GenerateSettings) Validate ¶ added in v0.2.0
func (gs GenerateSettings) Validate() error
type ImportGenerationMode ¶ added in v0.2.0
type ImportGenerationMode uint8
const ( // ImportGenerationModeSeparate will generate separate go files for // every bebop file, and will assume that imported files are // already generated. If imported file types are used and their containing // files do not contain a go_package constant, this mode will fail. ImportGenerationModeSeparate ImportGenerationMode = iota // ImportGenerationModeCombined will generate one go file including // all definitions from all imports. This does not require go_package // is defined anywhere, and maintains compatibility with files compilable // by the original bebopc compiler. ImportGenerationModeCombined ImportGenerationMode = iota )
type Message ¶
type Message struct {
Name string
Comment string
Fields map[uint8]Field
OpCode uint32
// Namespace is only provided for imported types, and only
// used in code generation.
Namespace string
}
A Message is a record type where all fields are optional and keyed to indices.
type Record ¶
type Record interface {
// MarshalBebop converts a bebop record to wire format. It is recommended over
// EncodeBebop for performance.
MarshalBebop() []byte
// MarshalBebopTo writes a bebop record to an existing byte slice. It performs no
// checks to ensure the given byte slice is large enough to contain the record.
MarshalBebopTo([]byte) (n int)
// UnmarshalBebop is parallel to Marshal as Decode is to Encode. It has similar
// performance improvements.
UnmarshalBebop([]byte) error
// EncodeBebop writes a bebop record in wire format to a writer. It is slower (~6x)
// than MarshalBebop, and is only recommended for uses where the record size is both
// larger than a network packet and able to be acted upon as writer receives the byte
// stream, not only after the entire message has been received.
EncodeBebop(io.Writer) error
// DecodeBebop is to EncodeBebop as UnmarshalBebop is to MarshalBebop
DecodeBebop(io.Reader) error
// Size reports how many bytes a record takes up. It is only valid for the state of the
// record when Size is called.
Size() int
}
A Record can be serialized to and from a bebop structure.
type Struct ¶
type Struct struct {
Name string
Comment string
Fields []Field
// If OpCode is defined, wire encodings of the struct can be
// preceded by the OpCode.
OpCode uint32
// Namespace is only provided for imported types, and only
// used in code generation.
Namespace string
// If ReadOnly is true, generated code for the struct will
// provide field getters instead of exporting fields.
ReadOnly bool
}
A Struct is a record type where all fields are required.
type Tag ¶ added in v0.2.2
type Tag struct {
Key string
Value string
// Boolean is set if Value is empty, in the form `key`, not `key:""`.
Boolean bool
}
A Tag is a Go struct field tag, e.g. `json:"userId,omitempty"`
type Union ¶ added in v0.0.9
type Union struct {
Name string
Comment string
Fields map[uint8]UnionField
OpCode uint32
// Namespace is only provided for imported types, and only
// used in code generation.
Namespace string
}
A Union is like a message where explicitly one field will be provided.
type UnionField ¶ added in v0.0.9
type UnionField struct {
Message *Message
Struct *Struct
// Tags are not written by default, ard must be enabled via a compiler flag.
Tags []Tag
// DeprecatedMessage is only provided if Deprecated is true.
DeprecatedMessage string
Deprecated bool
}
A UnionField is either a Message, Struct, or Union, defined inline.