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

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

15 Aug 2024 12:44AM UTC coverage: 43.923% (+9.0%) from 34.908%
#19

push

Mr Martian
fix coveralls

2349 of 5348 relevant lines covered (43.92%)

46.88 hits per line

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

0.0
/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::base::BaseVectorTile;
11
use crate::mapbox::{write_layer, MapboxVectorLayer};
12

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

×
30
        let mut tmp_pbf = pbf.borrow_mut();
×
31
        tmp_pbf.read_fields(&mut vt, end);
×
32

×
33
        vt
×
34
    }
×
35

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

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

63
    pbf.take()
×
64
}
×
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