etfapi

package
v21.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadElementData = errors.New("bad element data")

ErrBadElementData is the error returned when attempting to create a new element but the data provided does not match the Code

View Source
var ErrBadFieldType = errors.New("bad field type")

ErrBadFieldType is the error returned when attempting to unmarshal an etf payload and a field is an incorrect type (like non-string-like map keys)

View Source
var ErrBadMarshalData = errors.New("bad marshal data")

ErrBadMarshalData is the error returned when attempting to marshal an etf payload to []byte and the data in an Element doesn't match the Code

View Source
var ErrBadParity = errors.New("non-even list parity")

ErrBadParity is the error returned when a list that should be even parity is not (usually when trying to deal with Map Elements)

View Source
var ErrBadPayload = errors.New("bad payload format")

ErrBadPayload is the error returned when attempting to unmarshal an etf payload fails due to bad formatting

View Source
var ErrBadTarget = errors.New("bad element unmarshal target")

ErrBadTarget is the error returned when trying to convert an Element to an incorrect type

View Source
var ErrOutOfBounds = errors.New("int value out of bounds")

ErrOutOfBounds is the error returned when integer values are out of the bounds of the type code

Functions

func MapAndIDFromElement

func MapAndIDFromElement(e Element) (map[string]Element, snowflake.Snowflake, error)

MapAndIDFromElement converts a Map element into a string->Element map and attempts to extract an id Snowflake from the "id" field

func SnowflakeFromElement

func SnowflakeFromElement(e Element) (snowflake.Snowflake, error)

SnowflakeFromElement converts a number-like Element into a Snowflake

Types

type Code

type Code int
const (
	Map       Code = 116
	Atom      Code = 100
	List      Code = 108
	Binary    Code = 109
	Int8      Code = 97
	Int32     Code = 98
	Float     Code = 70
	String    Code = 107
	EmptyList Code = 106
	SmallBig  Code = 110
	LargeBig  Code = 111
)

These are the ETF type codes that this library knows about

func (Code) IsCollection

func (c Code) IsCollection() bool

IsCollection determines if an ETF Code is a collection of other elements

func (Code) IsList

func (c Code) IsList() bool

IsList determines if an ETF Code is a list

func (Code) IsNumeric

func (c Code) IsNumeric() bool

IsNumeric determines if an ETF Code is number-like

func (Code) IsStringish

func (c Code) IsStringish() bool

IsStringish determines if an ETF Code is string-like

func (Code) String

func (c Code) String() string

type Element

type Element struct {
	Code Code
	Val  []byte
	Vals []Element
}

Element is a container for arbitrary etf-formatted data

func ElementMapToElementSlice

func ElementMapToElementSlice(m map[string]Element) ([]Element, error)

ElementMapToElementSlice converts an string->Element map into a slice of Elements (kv pairs)

func NewAtomElement

func NewAtomElement(val []byte) (Element, error)

NewAtomElement generates a new Element representing an Atom value

func NewBasicElement

func NewBasicElement(code Code, val []byte) (Element, error)

NewBasicElement generates a new Element to hold data for non-collection types.

func NewBinaryElement

func NewBinaryElement(val []byte) (Element, error)

NewBinaryElement generates a new Element representing Binary data

func NewBoolElement

func NewBoolElement(val bool) (Element, error)

NewBoolElement generates a new Element representing a boolean value

func NewCollectionElement

func NewCollectionElement(code Code, val []Element) (Element, error)

NewCollectionElement generates a new Element to hold data for collection types.

func NewInt32Element

func NewInt32Element(val int) (Element, error)

NewInt32Element generates a new Element representing a 32-bit unsigned integer value; Bounds checking will happen inside the function

func NewInt8Element

func NewInt8Element(val int) (Element, error)

NewInt8Element generates a new Element representing an 8-bit unsigned integer value; Bounds checking will happen inside the function.

func NewListElement

func NewListElement(val []Element) (Element, error)

NewListElement generates a new Element representing a List

NOTE: empty lists are likely not handled well

func NewMapElement

func NewMapElement(val map[string]Element) (Element, error)

NewMapElement generates a new Element representing a Map

Keys are encoded as Binary type elements

func NewNilElement

func NewNilElement() (Element, error)

NewNilElement generates a new Element representing "nil"

func NewSmallBigElement

func NewSmallBigElement(val int64) (Element, error)

NewSmallBigElement generates a new Element representing a 64-bit unsigned integer value

func NewStringElement

func NewStringElement(val string) (Element, error)

NewStringElement generates a new Element representing a String value

func (*Element) IsCollection

func (e *Element) IsCollection() bool

IsCollection determines if an element is a collection (map or list)

func (*Element) IsFalse

func (e *Element) IsFalse() bool

IsFalse determines if an element represents a "false" value

func (*Element) IsList

func (e *Element) IsList() bool

IsList determines if an element is a list (with or without members)

func (*Element) IsNil

func (e *Element) IsNil() bool

IsNil determines if an element represents a "nil" value

func (*Element) IsNumeric

func (e *Element) IsNumeric() bool

IsNumeric determines if an element is number-like

func (*Element) IsStringish

func (e *Element) IsStringish() bool

IsStringish determines if an element is string-like

func (*Element) IsTrue

func (e *Element) IsTrue() bool

IsTrue determines if an element represents a "true" value

func (*Element) Marshal

func (e *Element) Marshal() ([]byte, error)

Marshal formats the data in the given element in etf binary format

func (*Element) MarshalTo

func (e *Element) MarshalTo(b io.Writer) error

MarshalTo formats the data in the given element in etf binary format and writes it to the provided writer

func (Element) String

func (e Element) String() string

func (*Element) ToBytes

func (e *Element) ToBytes() ([]byte, error)

ToBytes converts a string-like Element to a []byte, if possible

func (*Element) ToInt

func (e *Element) ToInt() (int, error)

ToInt converts an int-like Element to an int, if possible

func (*Element) ToInt64

func (e *Element) ToInt64() (int64, error)

ToInt64 converts an int-like Element to an int64, if possible

func (*Element) ToList

func (e *Element) ToList() ([]Element, error)

ToList converts a list Element to a list

func (*Element) ToMap

func (e *Element) ToMap() (map[string]Element, error)

ToMap converts a map Element to a map

func (*Element) ToString

func (e *Element) ToString() (string, error)

ToString converts a string-like element to a real string, if possible

type HeartbeatPayload

type HeartbeatPayload struct {
	Sequence int
}

HeartbeatPayload is the specialized payload for sending "heartbeat" events to the discord gateway websocket

func (*HeartbeatPayload) Payload

func (hp *HeartbeatPayload) Payload() (Payload, error)

Payload converts the specialized payload to a generic etfapi.Payload

type IdentifyPayload

type IdentifyPayload struct {
	Token          string
	Intents        int
	Properties     IdentifyPayloadProperties
	LargeThreshold int
	Shard          IdentifyPayloadShard
	Presence       IdentifyPayloadPresence
}

IdentifyPayload is the specialized payload for sending "Identify" events to the discord gateway websocket

func (*IdentifyPayload) Payload

func (ip *IdentifyPayload) Payload() (Payload, error)

Payload converts the specialized payload to a generic Payload

type IdentifyPayloadGame

type IdentifyPayloadGame struct {
	Name string
	Type int
}

IdentifyPayloadGame holds the data about the "game" portion of the presence

type IdentifyPayloadPresence

type IdentifyPayloadPresence struct {
	Game   IdentifyPayloadGame
	Status string
	Since  int
	AFK    bool
}

IdentifyPayloadPresence holds the data about the "presence" portion of the identify payload

type IdentifyPayloadProperties

type IdentifyPayloadProperties struct {
	OS      string
	Browser string
	Device  string
}

IdentifyPayloadProperties holds the data about the os, etc. of the bot when identifying

type IdentifyPayloadShard

type IdentifyPayloadShard struct {
	ID    int
	MaxID int
}

IdentifyPayloadShard holds the data about the shards being identified for

type Payload

type Payload struct {
	OpCode discordapi.OpCode
	SeqNum *int
	EName  string

	Data     map[string]Element
	DataList []Element
}

Payload represents the data in a etf api payload (both for sending and receiving)

func Unmarshal

func Unmarshal(raw []byte) (*Payload, error)

Unmarshal creates a new Payload from the raw etf data in the []byte

func (*Payload) Contents

func (p *Payload) Contents() map[string]Element

func (*Payload) EventName

func (p *Payload) EventName() string

func (*Payload) Marshal

func (p *Payload) Marshal() ([]byte, error)

Marshal converts a payload into a properly formatted []byte that can be sent over a websocket connection

func (Payload) String

func (p Payload) String() string

type ResumePayload

type ResumePayload struct {
	Token     string
	SessionID string
	SeqNum    int
}

ResumePayload is the specialized payload for sending "Resume" events to the discord gateway websocket

func (*ResumePayload) Payload

func (rp *ResumePayload) Payload() (Payload, error)

Payload converts the specialized payload to a generic Payload

Jump to

Keyboard shortcuts

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