Documentation ¶
Index ¶
- Variables
- func MapAndIDFromElement(e Element) (map[string]Element, snowflake.Snowflake, error)
- func SnowflakeFromElement(e Element) (snowflake.Snowflake, error)
- type Code
- type Element
- func ElementMapToElementSlice(m map[string]Element) ([]Element, error)
- func NewAtomElement(val []byte) (Element, error)
- func NewBasicElement(code Code, val []byte) (Element, error)
- func NewBinaryElement(val []byte) (Element, error)
- func NewBoolElement(val bool) (Element, error)
- func NewCollectionElement(code Code, val []Element) (Element, error)
- func NewInt32Element(val int) (Element, error)
- func NewInt8Element(val int) (Element, error)
- func NewListElement(val []Element) (Element, error)
- func NewMapElement(val map[string]Element) (Element, error)
- func NewNilElement() (Element, error)
- func NewSmallBigElement(val int64) (Element, error)
- func NewStringElement(val string) (Element, error)
- func (e *Element) IsCollection() bool
- func (e *Element) IsFalse() bool
- func (e *Element) IsList() bool
- func (e *Element) IsNil() bool
- func (e *Element) IsNumeric() bool
- func (e *Element) IsStringish() bool
- func (e *Element) IsTrue() bool
- func (e *Element) Marshal() ([]byte, error)
- func (e *Element) MarshalTo(b io.Writer) error
- func (e Element) String() string
- func (e *Element) ToBytes() ([]byte, error)
- func (e *Element) ToInt() (int, error)
- func (e *Element) ToInt64() (int64, error)
- func (e *Element) ToList() ([]Element, error)
- func (e *Element) ToMap() (map[string]Element, error)
- func (e *Element) ToString() (string, error)
- type HeartbeatPayload
- type IdentifyPayload
- type IdentifyPayloadGame
- type IdentifyPayloadPresence
- type IdentifyPayloadProperties
- type IdentifyPayloadShard
- type Payload
- type ResumePayload
Constants ¶
This section is empty.
Variables ¶
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
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)
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
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)
var ErrBadPayload = errors.New("bad payload format")
ErrBadPayload is the error returned when attempting to unmarshal an etf payload fails due to bad formatting
var ErrBadTarget = errors.New("bad element unmarshal target")
ErrBadTarget is the error returned when trying to convert an Element to an incorrect type
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 ¶
MapAndIDFromElement converts a Map element into a string->Element map and attempts to extract an id Snowflake from the "id" field
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 ¶
IsCollection determines if an ETF Code is a collection of other elements
func (Code) IsStringish ¶
IsStringish determines if an ETF Code is string-like
type Element ¶
Element is a container for arbitrary etf-formatted data
func ElementMapToElementSlice ¶
ElementMapToElementSlice converts an string->Element map into a slice of Elements (kv pairs)
func NewAtomElement ¶
NewAtomElement generates a new Element representing an Atom value
func NewBasicElement ¶
NewBasicElement generates a new Element to hold data for non-collection types.
func NewBinaryElement ¶
NewBinaryElement generates a new Element representing Binary data
func NewBoolElement ¶
NewBoolElement generates a new Element representing a boolean value
func NewCollectionElement ¶
NewCollectionElement generates a new Element to hold data for collection types.
func NewInt32Element ¶
NewInt32Element generates a new Element representing a 32-bit unsigned integer value; Bounds checking will happen inside the function
func NewInt8Element ¶
NewInt8Element generates a new Element representing an 8-bit unsigned integer value; Bounds checking will happen inside the function.
func NewListElement ¶
NewListElement generates a new Element representing a List
NOTE: empty lists are likely not handled well
func NewMapElement ¶
NewMapElement generates a new Element representing a Map
Keys are encoded as Binary type elements
func NewNilElement ¶
NewNilElement generates a new Element representing "nil"
func NewSmallBigElement ¶
NewSmallBigElement generates a new Element representing a 64-bit unsigned integer value
func NewStringElement ¶
NewStringElement generates a new Element representing a String value
func (*Element) IsCollection ¶
IsCollection determines if an element is a collection (map or list)
func (*Element) IsStringish ¶
IsStringish determines if an element is string-like
func (*Element) MarshalTo ¶
MarshalTo formats the data in the given element in etf binary format and writes it to the provided writer
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 ¶
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 ¶
IdentifyPayloadProperties holds the data about the os, etc. of the bot when identifying
type IdentifyPayloadShard ¶
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)
type ResumePayload ¶
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