MCPcopy Create free account
hub / github.com/cowprotocol/services / decode

Method decode

crates/database/src/byte_array.rs:50–67  ·  view source on GitHub ↗
(value: PgValueRef<'_>)

Source from the content-addressed store, hash-verified

48
49impl<const N: usize> Decode<'_, Postgres> for ByteArray<N> {
50 fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
51 let mut bytes = [0u8; N];
52 match value.format() {
53 // prepared query
54 PgValueFormat::Binary => {
55 bytes = value.as_bytes()?.try_into()?;
56 }
57 // unprepared raw query
58 PgValueFormat::Text => {
59 let text = value
60 .as_bytes()?
61 .strip_prefix(b"\\x")
62 .ok_or("text does not start with \\x")?;
63 const_hex::decode_to_slice(text, &mut bytes)?
64 }
65 };
66 Ok(Self(bytes))
67 }
68}
69
70impl<const N: usize> Encode<'_, Postgres> for ByteArray<N> {

Callers

nothing calls this directly

Calls 2

as_bytesMethod · 0.80
try_intoMethod · 0.45

Tested by

no test coverage detected