gistools/readers/osm/
blob.rs

1use crate::util::{CompressionFormat::DeflateRaw, decompress_data};
2use alloc::{string::String, vec::Vec};
3use pbf::{ProtoRead, Protobuf};
4
5/// headers have a max size of 64KB
6pub const OSM_MAX_HEADER_SIZE: usize = 64 * 1024;
7/// blobs have a max size of 32MB
8pub const OSM_MAX_BLOB_SIZE: usize = 32 * 1024 * 1024;
9
10/// A file contains an sequence of fileblock headers, each prefixed by
11/// their length in network byte order, followed by a data block
12/// containing the actual data. Types starting with a "_" are reserved.
13/// example: { type: 'OSMHeader', indexdata: null, datasize: 173 }
14#[derive(Debug, Default)]
15pub struct BlobHeader {
16    /// The type of the blob
17    pub _type: String,
18    /// The index data
19    pub indexdata: Vec<u8>,
20    /// The size of the data
21    pub datasize: u64,
22}
23/// Read in the contents of the blob header
24impl ProtoRead for BlobHeader {
25    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
26        match tag {
27            1 => self._type = pb.read_string(),
28            2 => self.indexdata = pb.read_bytes(),
29            3 => self.datasize = pb.read_varint(),
30            _ => panic!("unknown tag {}", tag),
31        }
32    }
33}
34
35///  STORAGE LAYER: Storing primitives.
36/// A Blob is a data block containing the actual data.
37#[derive(Debug, Default)]
38pub struct Blob {
39    /// The raw size (uncompressed length)
40    pub raw_size: i32,
41    /// The data
42    pub data: Vec<u8>,
43}
44/// Read in the contents of the blob
45impl ProtoRead for Blob {
46    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
47        match tag {
48            1 => self.data = pb.read_bytes(),
49            2 => self.raw_size = pb.read_varint(),
50            // 3 => self.data = decompress_fflate(&pb.read_bytes(), None).unwrap(),
51            3 => self.data = decompress_data(&pb.read_bytes(), DeflateRaw).unwrap(),
52            4..=6 => panic!("LZMA, bzip2 and LZ4 not supported"),
53            _ => panic!("unknown tag {}", tag),
54        }
55    }
56}