• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-S2 / open-vector-tile / #27

06 Dec 2024 02:32PM UTC coverage: 98.708% (+1.3%) from 97.451%
#27

push

Mr Martian
fix coveralls

8783 of 8898 relevant lines covered (98.71%)

58.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/rust/mapbox/vector_tile.rs
1
use pbf::{ProtoRead, Protobuf};
2

3
use alloc::collections::BTreeMap;
4
use alloc::rc::Rc;
5
use alloc::string::String;
6
use alloc::vec::Vec;
7

8
use core::cell::RefCell;
9

10
use crate::{
11
    base::BaseVectorTile,
12
    mapbox::{write_layer, MapboxVectorLayer},
13
};
14

15
/// The vector tile struct that covers both "open" and "mapbox" specifications
16
#[derive(Debug)]
17
pub struct MapboxVectorTile {
18
    /// the layers in the vector tile
19
    pub layers: BTreeMap<String, MapboxVectorLayer>,
20
    /// the protobuf for the vector tile
21
    pbf: Rc<RefCell<Protobuf>>,
22
}
23
impl MapboxVectorTile {
24
    /// Create a new vector tile
25
    pub fn new(data: Vec<u8>, end: Option<usize>) -> Self {
12✔
26
        let pbf = Rc::new(RefCell::new(data.into()));
12✔
27
        let mut vt = MapboxVectorTile { pbf: pbf.clone(), layers: BTreeMap::new() };
12✔
28

12✔
29
        let mut tmp_pbf = pbf.borrow_mut();
12✔
30
        tmp_pbf.read_fields(&mut vt, end);
12✔
31

12✔
32
        vt
12✔
33
    }
12✔
34

35
    /// Get a layer given the name
36
    pub fn layer(&mut self, name: &str) -> Option<&mut MapboxVectorLayer> {
18✔
37
        self.layers.get_mut(name)
18✔
38
    }
18✔
39
}
40
impl ProtoRead for MapboxVectorTile {
41
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
18✔
42
        match tag {
18✔
43
            1 | 3 => {
18✔
44
                let mut layer = MapboxVectorLayer::new(self.pbf.clone(), tag == 1);
18✔
45
                pb.read_message(&mut layer);
18✔
46
                self.layers.insert(layer.name.clone(), layer);
18✔
47
            }
18✔
48
            #[tarpaulin::skip]
49
            _ => panic!("unknown tag: {}", tag),
×
50
        }
51
    }
18✔
52
}
53

54
/// writer for converting a BaseVectorTile to encoded bytes of the Open Vector Tile format
55
pub fn write_tile(tile: &mut BaseVectorTile) -> Vec<u8> {
3✔
56
    let mut pbf = Protobuf::new();
3✔
57

58
    // first write layers
59
    for layer in tile.layers.values() {
9✔
60
        pbf.write_bytes_field(1, &write_layer(layer));
9✔
61
    }
9✔
62

63
    pbf.take()
3✔
64
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc