diff options
| author | LLLL Colonq <llll@colonq> | 2025-11-06 22:20:12 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-11-06 22:20:12 -0500 |
| commit | 9e95cb43f1dbc9e63c9e3df2472c36e38e19fc88 (patch) | |
| tree | 3fc471a4cc1b2d2bc14629504883304a915740f9 /crates | |
| parent | 6a397916e0177c9e7c6b93fb9cc7510c14a659ff (diff) | |
Add read_length_prefixed_utf8
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/teleia/src/fig.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/crates/teleia/src/fig.rs b/crates/teleia/src/fig.rs index 0dd2f68..c584b97 100644 --- a/crates/teleia/src/fig.rs +++ b/crates/teleia/src/fig.rs @@ -1,8 +1,15 @@ use std::io::{Read, Write}; -use byteorder::{ReadBytesExt, WriteBytesExt}; +use byteorder::{LE, ReadBytesExt, WriteBytesExt}; use crate::{Erm, WrapErr}; +pub fn read_length_prefixed_utf8<R>(r: &mut R) -> Erm<String> where R: std::io::Read { + let len = r.read_u32::<LE>()?; + let mut bs = vec![0; len as usize]; + r.read_exact(&mut bs)?; + Ok(String::from_utf8(bs)?) +} + #[derive(Debug, Clone)] pub struct BinaryMessage { pub event: Vec<u8>, |
