(s: &str)
| 629 | } |
| 630 | |
| 631 | pub 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 | |
| 646 | pub fn parse_bytes_hex(s: &str) -> Result<Vec<u8>, ParseHexError> { |
| 647 | // Can't use `hex::decode` here, as it doesn't tolerate whitespace |
no test coverage detected