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

Method from_canonical

atomic-core/src/change/attribute.rs:104–121  ·  view source on GitHub ↗

Decode and validate a canonical value.

(name: InodeAttrName, bytes: &[u8])

Source from the content-addressed store, hash-verified

102
103 /// Decode and validate a canonical value.
104 pub fn from_canonical(name: InodeAttrName, bytes: &[u8]) -> Result<Self, AttrValueError> {
105 let value = match name {
106 InodeAttrName::Mode if bytes.len() == 2 => {
107 Self::Mode(u16::from_le_bytes([bytes[0], bytes[1]]))
108 }
109 InodeAttrName::Kind if bytes.len() == 1 => Self::Kind(
110 InodeKind::from_byte(bytes[0]).ok_or(AttrValueError::UnsupportedKind(bytes[0]))?,
111 ),
112 _ => {
113 return Err(AttrValueError::InvalidLength {
114 name,
115 actual: bytes.len(),
116 });
117 }
118 };
119 value.validate()?;
120 Ok(value)
121 }
122}
123
124/// Rejection reason for a malformed or unsupported attribute value.

Callers

nothing calls this directly

Calls 4

ModeEnum · 0.85
KindEnum · 0.85
lenMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected