Documentation ¶
Overview ¶
Package binary implements encoding and decoding documents in WhatsApp's binary XML format.
Index ¶
- Variables
- func Marshal(n Node) ([]byte, error)
- func Unpack(data []byte) ([]byte, error)
- type AttrUtility
- func (au *AttrUtility) Bool(key string) bool
- func (au *AttrUtility) Error() error
- func (au *AttrUtility) GetBool(key string, require bool) (bool, bool)
- func (au *AttrUtility) GetInt64(key string, require bool) (int64, bool)
- func (au *AttrUtility) GetJID(key string, require bool) (jidVal types.JID, ok bool)
- func (au *AttrUtility) GetString(key string, require bool) (strVal string, ok bool)
- func (au *AttrUtility) GetUint64(key string, require bool) (uint64, bool)
- func (au *AttrUtility) Int(key string) int
- func (au *AttrUtility) Int64(key string) int64
- func (au *AttrUtility) JID(key string) types.JID
- func (au *AttrUtility) OK() bool
- func (au *AttrUtility) OptionalBool(key string) bool
- func (au *AttrUtility) OptionalInt(key string) int
- func (au *AttrUtility) OptionalJID(key string) *types.JID
- func (au *AttrUtility) OptionalJIDOrEmpty(key string) types.JID
- func (au *AttrUtility) OptionalString(key string) string
- func (au *AttrUtility) String(key string) string
- func (au *AttrUtility) Uint64(key string) uint64
- type Attrs
- type ErrorList
- type Node
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidType = errors.New("unsupported payload type") ErrInvalidJIDType = errors.New("invalid JID type") ErrInvalidNode = errors.New("invalid node") ErrInvalidToken = errors.New("invalid token with tag") ErrNonStringKey = errors.New("non-string key") )
Errors returned by the binary XML decoder.
var ( IndentXML = false MaxBytesToPrintAsHex = 128 )
Options to control how Node.XMLString behaves.
Functions ¶
func Unpack ¶
Unpack unpacks the given decrypted data from the WhatsApp web API.
It checks the first byte to decide whether to uncompress the data with zlib or just return as-is (without the first byte). There's currently no corresponding Pack function because Marshal already returns the data with a leading zero (i.e. not compressed).
Types ¶
type AttrUtility ¶
AttrUtility is a helper struct for reading multiple XML attributes and checking for errors afterwards.
The functions return values directly and append any decoding errors to the Errors slice. The slice can then be checked after all necessary attributes are read, instead of having to check each attribute for errors separately.
func (*AttrUtility) Bool ¶
func (au *AttrUtility) Bool(key string) bool
func (*AttrUtility) Error ¶
func (au *AttrUtility) Error() error
Error returns the list of errors as a single error interface, or nil if there are no errors.
func (*AttrUtility) GetInt64 ¶
func (au *AttrUtility) GetInt64(key string, require bool) (int64, bool)
func (*AttrUtility) GetString ¶
func (au *AttrUtility) GetString(key string, require bool) (strVal string, ok bool)
func (*AttrUtility) GetUint64 ¶
func (au *AttrUtility) GetUint64(key string, require bool) (uint64, bool)
func (*AttrUtility) Int ¶
func (au *AttrUtility) Int(key string) int
func (*AttrUtility) Int64 ¶
func (au *AttrUtility) Int64(key string) int64
func (*AttrUtility) JID ¶
func (au *AttrUtility) JID(key string) types.JID
JID returns the JID under the given key. If there's no valid JID under the given key, an error will be stored and a blank JID struct will be returned.
func (*AttrUtility) OptionalBool ¶
func (au *AttrUtility) OptionalBool(key string) bool
func (*AttrUtility) OptionalInt ¶
func (au *AttrUtility) OptionalInt(key string) int
func (*AttrUtility) OptionalJID ¶
func (au *AttrUtility) OptionalJID(key string) *types.JID
OptionalJID returns the JID under the given key. If there's no valid JID under the given key, this will return nil. However, if the attribute is completely missing, this will not store an error.
func (*AttrUtility) OptionalJIDOrEmpty ¶
func (au *AttrUtility) OptionalJIDOrEmpty(key string) types.JID
OptionalJIDOrEmpty returns the JID under the given key. If there's no valid JID under the given key, this will return an empty JID. However, if the attribute is completely missing, this will not store an error.
func (*AttrUtility) OptionalString ¶
func (au *AttrUtility) OptionalString(key string) string
OptionalString returns the string under the given key.
func (*AttrUtility) String ¶
func (au *AttrUtility) String(key string) string
String returns the string under the given key. If there's no valid string under the given key, an error will be stored and an empty string will be returned.
func (*AttrUtility) Uint64 ¶
func (au *AttrUtility) Uint64(key string) uint64
type Attrs ¶
type Attrs = map[string]interface{}
Attrs is a type alias for the attributes of an XML element (Node).
type ErrorList ¶
type ErrorList []error
ErrorList is a list of errors that implements the error interface itself.
type Node ¶
type Node struct { Tag string // The tag of the element. Attrs Attrs // The attributes of the element. Content interface{} // The content inside the element. Can be nil, a list of Nodes, or a byte array. }
Node represents an XML element.
func (*Node) AttrGetter ¶
func (n *Node) AttrGetter() *AttrUtility
AttrGetter returns the AttrUtility for this Node.
func (*Node) GetChildByTag ¶
GetChildByTag does the same thing as GetOptionalChildByTag, but returns the Node directly without the ok boolean.
func (*Node) GetChildren ¶
GetChildren returns the Content of the node as a list of nodes. If the content is not a list of nodes, this returns nil.
func (*Node) GetChildrenByTag ¶
GetChildrenByTag returns the same list as GetChildren, but filters it by tag first.
func (*Node) GetOptionalChildByTag ¶
GetOptionalChildByTag finds the first child with the given tag and returns it. Each provided tag will recurse in, so this is useful for getting a specific nested element.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package proto contains the compiled protobuf structs from WhatsApp's protobuf schema.
|
Package proto contains the compiled protobuf structs from WhatsApp's protobuf schema. |
Package token contains maps of predefined tokens that WhatsApp's binary XML encoding uses to save bytes when sending commonly used strings.
|
Package token contains maps of predefined tokens that WhatsApp's binary XML encoding uses to save bytes when sending commonly used strings. |