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

Function decode_path_claim_event

atomic-core/src/pristine/path_claim.rs:168–209  ·  view source on GitHub ↗

Decode and validate one fixed-width path-claim event.

(
    bytes: &[u8; PATH_CLAIM_EVENT_SIZE],
)

Source from the content-addressed store, hash-verified

166
167/// Decode and validate one fixed-width path-claim event.
168pub fn decode_path_claim_event(
169 bytes: &[u8; PATH_CLAIM_EVENT_SIZE],
170) -> PristineResult<PathClaimEvent> {
171 if bytes[0] != PATH_CLAIM_EVENT_VERSION {
172 return Err(invalid_path_claim_data(format!(
173 "unsupported path-claim event version {} (expected {})",
174 bytes[0], PATH_CLAIM_EVENT_VERSION
175 )));
176 }
177
178 let operation_index =
179 u32::from_be_bytes(bytes[9..13].try_into().map_err(|_| {
180 invalid_path_claim_data("invalid path-claim operation index".to_string())
181 })?);
182 let claimant = Position::new(
183 NodeId::new(get_u64(bytes, 13)),
184 ChangePosition::new(get_u64(bytes, 21)),
185 );
186 let parent = GraphNode::new(
187 NodeId::new(get_u64(bytes, 31)),
188 ChangePosition::new(get_u64(bytes, 39)),
189 ChangePosition::new(get_u64(bytes, 47)),
190 );
191 let name = GraphNode::new(
192 NodeId::new(get_u64(bytes, 55)),
193 ChangePosition::new(get_u64(bytes, 63)),
194 ChangePosition::new(get_u64(bytes, 71)),
195 );
196
197 Ok(PathClaimEvent {
198 event_change: NodeId::new(get_u64(bytes, 1)),
199 operation_index,
200 kind: PathClaimKind::try_from(bytes[29])?,
201 state: PathClaimState::try_from(bytes[30])?,
202 claim: PathClaimId {
203 claimant,
204 parent,
205 name,
206 introduced_by: NodeId::new(get_u64(bytes, 79)),
207 },
208 })
209}
210
211pub(crate) fn invalid_path_claim_data(message: String) -> PristineError {
212 PristineError::Io(Error::new(ErrorKind::InvalidData, message))

Callers 7

get_path_claimsMethod · 0.85
iter_path_claimsMethod · 0.85
get_path_claimsMethod · 0.85
iter_path_claimsMethod · 0.85

Calls 2

invalid_path_claim_dataFunction · 0.85
get_u64Function · 0.85

Tested by

no test coverage detected