literal

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2017 License: Apache-2.0 Imports: 7 Imported by: 27

Documentation

Overview

Package literal provides an abstraction to manipulate BadWolf literals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	Build(t Type, v interface{}) (*Literal, error)
	Parse(s string) (*Literal, error)
}

Builder interface provides a standard way to build literals given a type and a given value.

func DefaultBuilder

func DefaultBuilder() Builder

DefaultBuilder returns a builder with no constraints or checks.

func NewBoundedBuilder

func NewBoundedBuilder(max int) Builder

NewBoundedBuilder creates a builder that guarantees that no literal will be created if the size of the string or a blob is bigger than the provided maximum.

type Literal

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

Literal represents the type and value boxed in the literal.

func (*Literal) Blob

func (l *Literal) Blob() ([]byte, error)

Blob returns the value of a literal as a []byte.

func (*Literal) Bool

func (l *Literal) Bool() (bool, error)

Bool returns the value of a literal as a boolean.

func (*Literal) Float64

func (l *Literal) Float64() (float64, error)

Float64 returns the value of a literal as a float64.

func (*Literal) Int64

func (l *Literal) Int64() (int64, error)

Int64 returns the value of a literal as an int64.

func (*Literal) Interface

func (l *Literal) Interface() interface{}

Interface returns the value as a simple interface{}.

func (*Literal) String

func (l *Literal) String() string

String returns a string representation of the literal.

func (*Literal) Text

func (l *Literal) Text() (string, error)

Text returns the value of a literal as a string.

func (*Literal) ToComparableString

func (l *Literal) ToComparableString() string

ToComparableString returns a string that can be directly compared.

func (*Literal) Type

func (l *Literal) Type() Type

Type returns the type of a literal.

func (*Literal) UUID added in v0.5.0

func (l *Literal) UUID() uuid.UUID

UUID returns a global unique identifier for the given literal. It is implemented as the SHA1 UUID of the literal value.

type Type

type Type uint8

Type represents the type contained in a literal.

const (
	// Bool indicates that the type contained in the literal is a bool.
	Bool Type = iota
	// Int64 indicates that the type contained in the literal is an int64.
	Int64
	// Float64 indicates that the type contained in the literal is a float64.
	Float64
	// Text indicates that the type contained in the literal is a string.
	Text
	// Blob indicates that the type contained in the literal is a []byte.
	Blob
)

func (Type) String

func (t Type) String() string

Strings returns the pretty printing version of the type

Jump to

Keyboard shortcuts

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