1use crate::clangd::ClangdUtility;
2use crate::symbols::SymbolId;
3
4use griff::ChunkStream;
5
6#[derive(Debug, Clone, Default)]
7#[repr(u8)]
8pub enum RelationKind {
9 #[default]
10 BaseOf,
11 OverriddenBy,
12}
13impl From<u8> for RelationKind {
14 fn from(b: u8) -> Self {
15 use RelationKind::*;
16 match b {
17 1 => OverriddenBy,
18 _ => BaseOf
19 }
20 }
21}
22
23#[derive(Debug, Clone, Default)]
24pub struct Rela {
25 pub subject: SymbolId,
26 pub predicate: RelationKind,
27 pub object: SymbolId,
28}
29impl ClangdUtility for Rela{}
30
31impl Rela {
32 #[allow(dead_code)]
33 pub fn parse(buf: &ChunkStream) -> Vec<Rela> {
34 let mut rela: Vec<Rela> = vec![];
35 let mut cursor: usize = 0;
36 let data = buf.data.as_slice();
37 if data.len() == 0 {
38 return rela;
39 }
40
41 loop {
42 let mut r: Rela = Default::default();
43 r.subject = data.get(cursor..cursor+8).unwrap().try_into().unwrap();
44 cursor += 8;
45 r.predicate = RelationKind::from(data[cursor]);
46 cursor += 1;
47 r.object = data.get(cursor..cursor+8).unwrap().try_into().unwrap();
48 cursor += 8;
49
50 rela.push(r);
51 if cursor >= data.len() {
52 break;
53 }
54 }
55
56 rela
57 }
58}