def encode_null(value: object) -> Optional[Payload]: if value is None: p: Payload = Payload() p.metadata = {METADATA_ENCODING_KEY: METADATA_ENCODING_NULL} p.data = bytes() return p else: return None
def encode_binary(value: object) -> Optional[Payload]: if isinstance(value, bytes): p: Payload = Payload() p.metadata = {METADATA_ENCODING_KEY: METADATA_ENCODING_RAW} p.data = value return p else: return None
def encode_json_string(value: object) -> Payload: # TODO: # mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); # mapper.registerModule(new JavaTimeModule()); # mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); p: Payload = Payload() p.metadata = {METADATA_ENCODING_KEY: METADATA_ENCODING_JSON} p.data = json.dumps(value).encode("utf-8") return p
def get_header(self) -> Header: header_bytes = self.header.to_json().encode("utf-8") # type: ignore header = Header() header.fields[MUTABLE_MARKER_HEADER_KEY] = Payload(data=header_bytes) return header
def to_payload(self, arg: object) -> Payload: payload = Payload() payload.metadata = {METADATA_ENCODING_KEY: b"PYTHON_PICKLE"} payload.data = pickle.dumps(arg) return payload