TypedMarshaler
This class handles typed marshaling and unmarshaling operations. It encapsulates a Marshaler and stores information about whether the type is a pointer and its element type for efficient processing.
Methods
Set()
@classmethod
def Set(
ctx: context.Context,
key: any,
object: T,
options: store.Option
) - > error
Stores an object in the underlying store with a given key. This method marshals the object before storing it.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and deadlines. |
| key | any | The key used to identify the object in the store. |
| object | T | The object to be stored, which will be marshaled according to the TypedMarshaler's configuration. |
| options | store.Option | Optional settings for the store operation, such as expiration or conditional writes. |
Returns
| Type | Description |
|---|---|
error | An error if the operation fails, otherwise nil. |
Get()
@classmethod
def Get(
ctx: context.Context,
key: any
) - > (T, error)
Retrieves an object from the underlying store using a given key. This method unmarshals the retrieved data into the specified type T.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and deadlines. |
| key | any | The key used to identify the object in the store. |
Returns
| Type | Description |
|---|---|
(T, error) | The unmarshaled object of type T and an error if the operation fails or the key is not found. |