Serialize the message by lazy decoder.
Returns a cache after first usage. To prevent such behavior, please call message.clear_cache() after message.body changes.
Source code in faststream/message/message.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115 | async def decode(self) -> Optional["Any"]:
"""Serialize the message by lazy decoder.
Returns a cache after first usage. To prevent such behavior, please call
`message.clear_cache()` after `message.body` changes.
"""
assert self.__decoder, "You should call `set_decoder()` method first."
if (
result := self.__decoded_caches.get(self.__decoder, _NOT_CACHED)
) is _NOT_CACHED:
result = self.__decoded_caches[self.__decoder] = await self.__decoder(self)
return result
|