MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / bytes

Method bytes

atomic-core/src/change/format_v3/semantic/predictive/encode.rs:60–99  ·  view source on GitHub ↗
(&mut self, has_kind: bool)

Source from the content-addressed store, hash-verified

58 Ok(n)
59 }
60 fn bytes(&mut self, has_kind: bool) -> FormatResult<()> {
61 let tag = self.n(REFERENCE)?;
62 if tag > 2 {
63 return Err(invalid("predictive reference tag"));
64 }
65 let len = usize::try_from(get(&mut self.input)?)
66 .map_err(|_| invalid("predictive length overflow"))?;
67 let at = if tag == 0 {
68 self.cursor
69 } else {
70 usize::try_from(self.previous.read(&mut self.refs)?)
71 .map_err(|_| invalid("predictive offset overflow"))?
72 };
73 let pool = if tag == 2 {
74 self.literals
75 } else {
76 self.content
77 };
78 let tail = pool
79 .get(at..)
80 .ok_or_else(|| invalid("predictive offset outside pool"))?;
81 self.length.add(len as u64, p::length(tail) as u64)?;
82 let end = at
83 .checked_add(len)
84 .ok_or_else(|| invalid("predictive range overflow"))?;
85 let bytes = pool
86 .get(at..end)
87 .ok_or_else(|| invalid("predictive range outside pool"))?;
88 if tag != 2 {
89 self.cursor = end;
90 }
91 if has_kind {
92 let actual = get(&mut self.kinds)?;
93 if p::from_code(actual).is_none() {
94 return Err(invalid("unknown predictive kind"));
95 }
96 self.kind.add(actual, p::code(p::kind(bytes)))?;
97 }
98 Ok(())
99 }
100 fn leaves(&mut self) -> FormatResult<()> {
101 for _ in 0..self.count(TOKENS)? {
102 match self.n(LEAF)? {

Callers 1

leavesMethod · 0.45

Calls 11

lengthFunction · 0.85
from_codeFunction · 0.85
is_noneMethod · 0.80
codeFunction · 0.70
kindFunction · 0.70
getMethod · 0.65
invalidFunction · 0.50
getFunction · 0.50
nMethod · 0.45
readMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected