bytes_field#
Bases:
Field
Source Code in griptape/schemas/bytes_field.py
class Bytes(fields.Field):
def _serialize(self, value: Any, attr: Any, obj: Any, **kwargs) -> str:
return base64.b64encode(value).decode()
def _deserialize(self, value: Any, attr: Any, data: Any, **kwargs) -> bytes:
return base64.b64decode(value)
def _validate(self, value: Any) -> None:
if not isinstance(value, bytes):
raise ValidationError("Invalid input type.")
_deserialize(value, attr, data, **kwargs)#
Source Code in griptape/schemas/bytes_field.py
def _deserialize(self, value: Any, attr: Any, data: Any, **kwargs) -> bytes:
return base64.b64decode(value)
_serialize(value, attr, obj, **kwargs)#
Source Code in griptape/schemas/bytes_field.py
def _serialize(self, value: Any, attr: Any, obj: Any, **kwargs) -> str:
return base64.b64encode(value).decode()
_validate(value)#
Source Code in griptape/schemas/bytes_field.py
def _validate(self, value: Any) -> None:
if not isinstance(value, bytes):
raise ValidationError("Invalid input type.")