#![allow(dead_code)] use link_cli::{
protocol::{export_store, LinksPacket, Reference},
Link, NamedTypeLinks,
};
pub const ARCHIVE: &str = "12 02 20 01 24 01 02 01 01 03 03 01 03 \
13 02 21 02 30 01 ff ff 9f ff fd ff 17 ff fc 9f 9e";
pub fn fill(store: &mut impl NamedTypeLinks) {
for _ in 0..3 {
let id = store.create(0, 0);
store.update(id, id, id).unwrap();
}
assert_eq!(store.create(1, 3), 4);
store.delete(2).unwrap();
store.set_name(1, "a").unwrap();
store.set_name(3, "é").unwrap();
store.set_name(4, "ab").unwrap();
}
pub fn export(store: &mut impl NamedTypeLinks) -> Vec<u8> {
let mut bytes = Vec::new();
export_store(store, &mut bytes).unwrap();
bytes
}
pub fn hex(bytes: &[u8]) -> String {
bytes
.iter()
.map(|byte| format!("{byte:02x}"))
.collect::<Vec<_>>()
.join(" ")
}
pub fn bytes(hex: &str) -> Vec<u8> {
hex.split_whitespace()
.map(|byte| u8::from_str_radix(byte, 16).unwrap())
.collect()
}
pub fn names(store: &mut impl NamedTypeLinks) -> Vec<(u32, Option<String>)> {
(1..=4)
.map(|id| (id, store.get_name(id).unwrap()))
.collect()
}
pub fn links(store: &mut impl NamedTypeLinks) -> Vec<Link> {
let mut links = store.all_links();
links.sort_by_key(|link| link.index);
links
}
pub fn packet(external_references: bool, links: &[(u64, Vec<Reference>)]) -> Vec<u8> {
LinksPacket::pack(external_references, links, true)
.unwrap()
.to_bytes()
.unwrap()
}
pub fn doublet(address: u64, source: u64, target: u64) -> (u64, Vec<Reference>) {
(
address,
vec![Reference::Internal(source), Reference::Internal(target)],
)
}
pub fn no_names() -> Vec<u8> {
packet(true, &[])
}