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

Function try_decode_hex_literal

datafusion/sql/src/expr/value.rs:310–328  ·  view source on GitHub ↗

Try to decode bytes from hex literal string. None will be returned if the input literal is hex-invalid.

(s: &str)

Source from the content-addressed store, hash-verified

308///
309/// None will be returned if the input literal is hex-invalid.
310fn try_decode_hex_literal(s: &str) -> Option<Vec<u8>> {
311 let hex_bytes = s.as_bytes();
312
313 let mut decoded_bytes = Vec::with_capacity(hex_bytes.len().div_ceil(2));
314
315 let start_idx = hex_bytes.len() % 2;
316 if start_idx > 0 {
317 // The first byte is formed of only one char.
318 decoded_bytes.push(try_decode_hex_char(hex_bytes[0])?);
319 }
320
321 for i in (start_idx..hex_bytes.len()).step_by(2) {
322 let high = try_decode_hex_char(hex_bytes[i])?;
323 let low = try_decode_hex_char(hex_bytes[i + 1])?;
324 decoded_bytes.push((high << 4) | low);
325 }
326
327 Some(decoded_bytes)
328}
329
330/// Try to decode a byte from a hex char.
331///

Callers 2

parse_valueMethod · 0.85
test_decode_hex_literalFunction · 0.85

Calls 3

try_decode_hex_charFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45

Tested by 1

test_decode_hex_literalFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…