Skip to main content

libsqlite3_sys/
wire.rs

1//! Single-byte BLOB storage tags. Codec versions belong to database metadata.
2pub const VERSION: i64 = 1;
3pub const BYTEA_TAG: u8 = b'b';
4
5pub fn blob_payload(bytes: &[u8]) -> &[u8] {
6    bytes.strip_prefix(&[BYTEA_TAG]).unwrap_or(bytes)
7}
8
9pub fn encode_blob(bytes: &[u8]) -> Vec<u8> {
10    let mut encoded = Vec::with_capacity(bytes.len() + 1);
11    encoded.push(BYTEA_TAG);
12    encoded.extend_from_slice(bytes);
13    encoded
14}
15
16pub fn decode_blob(mut bytes: Vec<u8>) -> Vec<u8> {
17    if bytes.first() == Some(&BYTEA_TAG) {
18        bytes.remove(0);
19    }
20    bytes
21}