Skip to content

Commit

Permalink
fix protobuf bytes coder
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Liu <[email protected]>
  • Loading branch information
austin362667 committed Aug 10, 2024
1 parent 12bc0af commit ea63c72
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions flyteidl/pyo3_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ pub fn with_new(input: TokenStream) -> TokenStream {
}
}
// For the needs like `load_proto_from_file()`, `write_proto_to_file()` in `flytekit/core/utils.py`
pub fn ParseFromString(&mut self, bytes_string: &str) -> Result<#name, crate::_flyteidl_rust::MessageDecodeError>
pub fn ParseFromString(&mut self, bytes_string: &pyo3::types::PyBytes) -> Result<#name, crate::_flyteidl_rust::MessageDecodeError>
{
let bt = bytes_string.as_bytes();
let de = prost::Message::decode(&bt.to_vec()[..]);
use prost::Message;
let bytes = bytes_string.as_bytes();
let de = Message::decode(&bytes.to_vec()[..]);
Ok(de?)
}
pub fn SerializeToString(&self) -> Result<String, crate::_flyteidl_rust::MessageEncodeError>
pub fn SerializeToString(&self, py: Python) -> Result<PyObject, crate::_flyteidl_rust::MessageEncodeError>
{
// Bring `prost::Message` trait to scope here. Put it in outer impl block will leads to duplicated imports.
use prost::Message;
let mut buf = vec![];
buf.reserve(self.encoded_len());
// Unwrap is safe, since we have reserved sufficient capacity in the vector.
self.encode(&mut buf).unwrap();
let result = base64::encode(&buf);
Ok(result)
Ok(pyo3::types::PyBytes::new_bound(py, &buf).into())
}
}
}
Expand Down

0 comments on commit ea63c72

Please sign in to comment.