MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / validate

Function validate

crates/table/src/table_index/bytes_key.rs:185–199  ·  view source on GitHub ↗

Validates BSATN `byte` to conform to `seed`. The BSATN can originate from untrusted sources, e.g., from module code. This also means that e.g., a `BytesKey` can be trusted to hold valid BSATN for the key type, which we can rely on in e.g., `decode_algebraic_value`, which isn't used in a context where it would be appropriate to fail. Another reason to validate is that we wish for `BytesKey` to be

(seed: &'a S, mut bytes: &'de [u8])

Source from the content-addressed store, hash-verified

183/// since if all parts that are encoded into it are valid according to a key type,
184/// then `bytes` cannot be longer than `N`.
185fn validate<'a, 'de, S: 'a + ?Sized>(seed: &'a S, mut bytes: &'de [u8]) -> DecodeResult<()>
186where
187 WithTypespace<'a, S>: DeserializeSeed<'de>,
188{
189 WithTypespace::empty(seed).validate(Deserializer::new(&mut bytes))?;
190
191 if !bytes.is_empty() {
192 return Err(DecodeError::custom(format_args!(
193 "after decoding, there are {} extra bytes",
194 bytes.len()
195 )));
196 }
197
198 Ok(())
199}
200
201impl<const N: usize> BytesKey<N> {
202 fn new(length: usize, bytes: [u8; N]) -> Self {

Callers 5

from_bsatnMethod · 0.70
from_bsatn_prefixMethod · 0.70

Calls 7

customFunction · 0.85
emptyFunction · 0.50
newFunction · 0.50
ErrFunction · 0.50
OkFunction · 0.50
validateMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…