MCPcopy Create free account
hub / github.com/apache/datafusion / unhex_common

Function unhex_common

datafusion/spark/src/function/math/unhex.rs:84–110  ·  view source on GitHub ↗

Decodes a hex-encoded byte slice into binary data. Returns `true` if decoding succeeded, `false` if the input contains invalid hex characters.

(bytes: &[u8], out: &mut Vec<u8>)

Source from the content-addressed store, hash-verified

82/// Decodes a hex-encoded byte slice into binary data.
83/// Returns `true` if decoding succeeded, `false` if the input contains invalid hex characters.
84fn unhex_common(bytes: &[u8], out: &mut Vec<u8>) -> bool {
85 if bytes.is_empty() {
86 return true;
87 }
88
89 let mut i = 0usize;
90
91 // If the hex string length is odd, implicitly left-pad with '0'.
92 if (bytes.len() & 1) == 1 {
93 match hex_nibble(bytes[0]) {
94 // Equivalent to (0 << 4) | lo
95 Some(lo) => out.push(lo),
96 None => return false,
97 }
98 i = 1;
99 }
100
101 while i + 1 < bytes.len() {
102 match (hex_nibble(bytes[i]), hex_nibble(bytes[i + 1])) {
103 (Some(hi), Some(lo)) => out.push((hi << 4) | lo),
104 _ => return false,
105 }
106 i += 2;
107 }
108
109 true
110}
111
112/// Converts an iterator of hex strings to a binary array.
113fn unhex_array<I, T>(

Callers 2

unhex_arrayFunction · 0.85
unhex_scalarFunction · 0.85

Calls 4

hex_nibbleFunction · 0.85
is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…