ring.coder
— Auto encode/decode layer¶
Coder is a configurable layer that provides ways to encode raw data and decode stored cache data.
-
class
ring.coder.
Coder
¶ Abstract coder interface.
See
coderize()
to create a Coder-compatible object in an easy way. SeeCoderTuple
to create a Coder-compatible object with functions.-
decode
()¶ Abstract decode function. Children must implement this function.
-
encode
()¶ Abstract encode function. Children must implement this function.
-
-
ring.coder.
CoderTuple
¶ Coder-compatible tuple with encode and decode functions
alias of
ring.coder.Coder
-
class
ring.coder.
DataclassCoder
¶ -
static
decode
(binary)¶ Deserialize json encoded dictionary to dataclass object
-
static
encode
(data)¶ Serialize dataclass object to json encoded dictionary
-
static
-
class
ring.coder.
JsonCoder
¶ JSON Coder.
When
ujson
package is installed, ujson is automatically selected; Otherwise,json
will be used.-
static
decode
(binary)¶ Decode UTF-8 bytes to JSON string and load it to object
-
static
encode
(data)¶ Dump data to JSON string and encode it to UTF-8 bytes
-
static
-
class
ring.coder.
Registry
¶ Coder registry.
See: ring.coder.registry()
for default registry instance.-
get
(coder_name)¶ Get the registered coder for corresponding coder_name.
This method is internally called when coder parameter is passed to ring object factory.
-
register
(coder_name, raw_coder)¶ Register raw_coder as a new coder with alias coder_name.
Coder can be one of next types:
- A
Coder
subclass. - A
CoderTuple
object. - A tuple of encode and decode functions.
- An object which has encode and decode methods.
Parameters: - A
-
-
ring.coder.
bypass_coder
= (<function bypass>, <function bypass>)¶ Default coder.
encode and decode functions bypass the given parameter.
-
ring.coder.
pickle_coder
= (<built-in function dumps>, <built-in function loads>)¶ Pickle coder.
encode is
pickle.dumps()
and decode ispickle.loads()
.cpickle
will be automatically loaded for CPython2.
-
ring.coder.
registry
= <ring.coder.Registry object>¶ The default coder registry with pre-registered coders. Built-in coders are registered by default.
See: ring.coder.Registry
for the class definition.