Documentation ¶
Overview ¶
Package botstate implements handling of Swarming bot state dictionary.
Index ¶
- Constants
- type Dict
- func (d Dict) Equal(another Dict) bool
- func (d *Dict) Err() error
- func (d *Dict) FromProperty(prop datastore.Property) error
- func (d *Dict) MarshalJSON() ([]byte, error)
- func (d *Dict) MustReadBool(key string) bool
- func (d *Dict) MustReadString(key string) string
- func (d *Dict) Read(key string, val any) error
- func (d *Dict) ReadRaw(key string) (json.RawMessage, error)
- func (d *Dict) String() string
- func (d *Dict) ToProperty() (datastore.Property, error)
- func (d *Dict) UnmarshalJSON(blob []byte) error
- func (d *Dict) Unseal() error
- type EditableDict
Constants ¶
const ( // HandshakingKey is set to true when the bot is connecting. HandshakingKey = "handshaking" // InitialDimensionsKey carries dimensions reported when the bot is connecting. InitialDimensionsKey = "initial_dimensions" // QuarantinedKey carries a self-quarantine message or a boolean. QuarantinedKey = "quarantined" // MaintenanceKey carries a bot maintenance message. MaintenanceKey = "maintenance" )
Some known bot state keys.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dict ¶
type Dict struct { // JSON is serialized JSON representation of the dict. JSON []byte // contains filtered or unexported fields }
Dict is a lazily deserialized read-only bot state JSON dict.
It can be in three state internally:
- Sealed. In this state it is represented exclusively by a JSON byte blob (which may or may not be valid).
- Unsealed. In this state the dict is also accessible as a string-keyed map, allowing to read values of individual keys.
- Broken. This happens when there's an error deserializing the JSON byte blob when unsealing it. Attempts to read keys of a broken dict will end in errors.
Reading values unseals the dict. It can also be unsealed explicitly via Unseal method.
func Edit ¶
func Edit(d Dict, cb func(d *EditableDict) error) (Dict, error)
Edit allows to mutate the state dict inside the given callback.
Returns the final mutated dict or an error if the dict could not be serialized/deserialized or the callback returned an error.
func (Dict) Equal ¶
Equal returns true if both dicts serialize to the same JSON (ignoring formatting).
This method is used by github.com/google/go-cmp/cmp in assertions. For that reason it has to have a non-pointer receiver.
func (*Dict) FromProperty ¶
FromProperty is a part of datastore.PropertyConverter interface.
func (*Dict) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface.
func (*Dict) MustReadBool ¶
MustReadBool reads a boolean, returning false if the key is missing or on errors.
func (*Dict) MustReadString ¶
MustReadString reads a string, returning an empty string if the key is missing or on errors.
func (*Dict) Read ¶
Read reads a value of the given key if it is present.
Doesn't change `val` and returns nil if the key is missing. Returns an error if the dict or the key value can't be deserialized.
func (*Dict) ReadRaw ¶
func (d *Dict) ReadRaw(key string) (json.RawMessage, error)
ReadRaw returns a raw serialized value of a key or nil if the key is missing.
Returns an error if the dict can't be deserialized.
func (*Dict) ToProperty ¶
ToProperty is a part of datastore.PropertyConverter interface.
func (*Dict) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface.
type EditableDict ¶
type EditableDict struct {
// contains filtered or unexported fields
}
EditableDict is an editable representation of a state dict.