diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-24 17:59:45 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-24 17:59:45 +0100 |
| commit | 2bc23bdc7fe01fc5921be8e09f405a8a1fd7bd65 (patch) | |
| tree | 9df07f8aeba21f4fb91e23fcc8d1c7a4a57a42eb /examples/11-transient-0/output/rust/src/gen/transient_0.rs | |
| parent | c8baf035c5a1705b957931f56f9162125803e554 (diff) | |
Add Shared type
Diffstat (limited to 'examples/11-transient-0/output/rust/src/gen/transient_0.rs')
| -rw-r--r-- | examples/11-transient-0/output/rust/src/gen/transient_0.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/11-transient-0/output/rust/src/gen/transient_0.rs b/examples/11-transient-0/output/rust/src/gen/transient_0.rs new file mode 100644 index 0000000..560fe51 --- /dev/null +++ b/examples/11-transient-0/output/rust/src/gen/transient_0.rs @@ -0,0 +1,70 @@ +// Generated by hobgoblin. + +pub fn encode_bool(value: &::core::primitive::bool, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + if *value { + writer.write_all(&1u8.to_le_bytes())?; + } else { + writer.write_all(&0u8.to_le_bytes())?; + }; + ::std::io::Result::Ok(()) +} + +pub fn decode_bool(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::bool> { + let int_value = { + let bytes = { + let mut bytes = [0; 1]; + reader.read_exact(&mut bytes)?; + bytes + }; + u8::from_le_bytes(bytes) + }; + std::io::Result::Ok(if int_value == 0 { + false + } else { + true + }) +} + +pub fn encode_int_32(value: &::core::primitive::i32, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + writer.write_all(&value.to_le_bytes())?; + ::std::io::Result::Ok(()) +} + +pub fn decode_int_32(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::i32> { + let bytes = { + let mut bytes = [0; 4]; + reader.read_exact(&mut bytes)?; + bytes + }; + std::io::Result::Ok(::core::primitive::i32::from_le_bytes(bytes)) +} + +pub fn encode_int_64(value: &::core::primitive::i64, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + writer.write_all(&value.to_le_bytes())?; + ::std::io::Result::Ok(()) +} + +pub fn decode_int_64(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::i64> { + let bytes = { + let mut bytes = [0; 8]; + reader.read_exact(&mut bytes)?; + bytes + }; + std::io::Result::Ok(::core::primitive::i64::from_le_bytes(bytes)) +} + +pub fn encode_string(value: &::std::string::String, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + crate::transient_0::encode_int_64(&((value.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer)?; + writer.write_all(value.as_bytes())?; + ::std::io::Result::Ok(()) +} + +pub fn decode_string(reader: &mut impl std::io::Read) -> ::std::io::Result::<::std::string::String> { + let len = crate::transient_0::decode_int_64(reader)?; + let bytes = { + let mut bytes = vec![0u8; (len.try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?]; + reader.read_exact(&mut bytes)?; + bytes + }; + std::io::Result::Ok((::std::string::String::from_utf8(bytes)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?) +} |
