MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_bytes

Function parse_bytes

src/repr/src/strconv.rs:631–644  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

629}
630
631pub fn parse_bytes(s: &str) -> Result<Vec<u8>, ParseError> {
632 // If the input starts with "\x", then the remaining bytes are hex encoded
633 // [0]. Otherwise the bytes use the traditional "escape" format. [1]
634 //
635 // [0]: https://www.postgresql.org/docs/current/datatype-binary.html#id-1.5.7.12.9
636 // [1]: https://www.postgresql.org/docs/current/datatype-binary.html#id-1.5.7.12.10
637 if let Some(remainder) = s.strip_prefix(r"\x") {
638 parse_bytes_hex(remainder).map_err(|e| {
639 ParseError::invalid_input_syntax("bytea", s).with_details(e.to_string_with_causes())
640 })
641 } else {
642 parse_bytes_traditional(s)
643 }
644}
645
646pub fn parse_bytes_hex(s: &str) -> Result<Vec<u8>, ParseHexError> {
647 // Can't use `hex::decode` here, as it doesn't tolerate whitespace

Callers 6

cast_string_to_bytesFunction · 0.50
decode_textMethod · 0.50
decode_text_into_rowMethod · 0.50
get_encoding_innerFunction · 0.50
evalMethod · 0.50
parse_complexMethod · 0.50

Calls 4

parse_bytes_hexFunction · 0.85
parse_bytes_traditionalFunction · 0.85
with_detailsMethod · 0.80
to_string_with_causesMethod · 0.80

Tested by

no test coverage detected