Encode/decode strings to/from bytes using the encoding provided to the constructor.
| 50 | |
| 51 | |
| 52 | class BytesCodec(Codec[str, bytes]): |
| 53 | """ |
| 54 | Encode/decode strings to/from bytes using the encoding provided to the |
| 55 | constructor. |
| 56 | """ |
| 57 | |
| 58 | def __init__(self, encoding: str = "utf8"): |
| 59 | self.encoding = encoding |
| 60 | |
| 61 | def encode(self, value: str) -> bytes: |
| 62 | return value.encode(self.encoding) |
| 63 | |
| 64 | def decode(self, value: bytes) -> str: |
| 65 | return value.decode(self.encoding) |
| 66 | |
| 67 | |
| 68 | class JSONCodec(Codec[Any, str]): |
no outgoing calls