Skip to main content

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 using the provided key and options. This method allows callers to persist typed data.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used for cancellation and deadlines.
keyanyThe key used to identify the object in the store. This can be any type that the underlying store can handle as a key.
objectTThe object to be stored. Its type is determined by the TypedMarshaler's generic type parameter.
optionsstore.OptionOptions to configure the storage operation, such as expiration or other store-specific settings.

Returns

TypeDescription
errorAn 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 the provided key. This method allows callers to retrieve typed data previously stored.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used for cancellation and deadlines.
keyanyThe key used to identify the object in the store. This can be any type that the underlying store can handle as a key.

Returns

TypeDescription
(T, error)The retrieved object of type T and an error if the operation fails or the object is not found.