1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use bytes::{Bytes, BytesMut};

use crate::{errors::Result, Version};

pub(crate) trait BoltWireFormat: Sized {
    // TODO: remove
    fn can_parse(version: Version, input: &[u8]) -> bool;

    fn parse(version: Version, input: &mut Bytes) -> Result<Self>;

    fn write_into(&self, version: Version, bytes: &mut BytesMut) -> Result<()>;

    fn into_bytes(self, version: Version) -> Result<Bytes> {
        let mut bytes = BytesMut::new();
        self.write_into(version, &mut bytes)?;
        Ok(bytes.freeze())
    }
}