MCPcopy Create free account
hub / github.com/apache/fory / generate_bytes_impl

Method generate_bytes_impl

compiler/fory_compiler/generators/rust.py:615–632  ·  view source on GitHub ↗
(self, type_name: str)

Source from the content-addressed store, hash-verified

613 return f"crate::{module}::{self.get_type_identifier(type_def)}"
614
615 def generate_bytes_impl(self, type_name: str) -> List[str]:
616 lines = []
617 lines.append(f"impl {type_name} {{")
618 lines.append(
619 " pub fn to_bytes(&self) -> ::std::result::Result<::std::vec::Vec<u8>, ::fory::Error> {"
620 )
621 lines.append(" let fory = detail::get_fory();")
622 lines.append(" fory.serialize(self)")
623 lines.append(" }")
624 lines.append("")
625 lines.append(
626 f" pub fn from_bytes(data: &[u8]) -> ::std::result::Result<{type_name}, ::fory::Error> {{"
627 )
628 lines.append(" let fory = detail::get_fory();")
629 lines.append(" fory.deserialize(data)")
630 lines.append(" }")
631 lines.append("}")
632 return lines
633
634 def generate_module(self) -> GeneratedFile:
635 """Generate a Rust module with all types."""

Callers 2

generate_unionMethod · 0.95
generate_messageMethod · 0.95

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected