use crate::errors::Result;
use crate::{read_vint, Writable};
use std::borrow::Cow;
#[derive(Debug)]
pub struct Text {
len: i32,
buf: Vec<u8>,
}
impl Text {
pub fn to_string(&self) -> Cow<str> {
String::from_utf8_lossy(&self.buf)
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
}
impl Writable for Text {
fn read(input: &mut impl std::io::Read) -> Result<Self> {
let len = read_vint(input)?;
let mut buf = vec![0; len as usize];
input.read_exact(&mut buf)?;
Ok(Self { len, buf })
}
}