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

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

17 Feb 2025 08:39PM UTC coverage: 40.419% (-58.3%) from 98.718%
#49

push

Mr Martian
setup a wasm build for experimentation; main rust didnt have no_std (bug)

18 of 18 new or added lines in 3 files covered. (100.0%)

2956 existing lines in 15 files now uncovered.

2082 of 5151 relevant lines covered (40.42%)

107.98 hits per line

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

0.0
/rust/open/vector_layer.rs
1
use pbf::{ProtoRead, Protobuf};
2

3
use crate::{
4
    base::BaseVectorLayer,
5
    open::{
6
        decode_shape, encode_shape, read_feature, write_feature, ColumnCacheReader,
7
        ColumnCacheWriter, Extent, OpenVectorFeature, Shape,
8
    },
9
    VectorLayerMethods,
10
};
11

12
use core::cell::RefCell;
13

14
use alloc::rc::Rc;
15
use alloc::string::String;
16
use alloc::vec::Vec;
17

18
/// The Open Vector Layer class represents a layer in an Open Vector Tile.
19
/// Contains an extent, name, version, and features.
20
/// The features will utilize the layer extent to decode geometry.
21
#[derive(Debug)]
22
pub struct OpenVectorLayer {
23
    /// the version of the vector tile
24
    pub version: u16,
25
    /// the name of the layer
26
    pub name: String,
27
    /// the extent of the vector layer
28
    pub extent: Extent,
29
    /// the features in the layer
30
    pub features: Vec<OpenVectorFeature>,
31
    shape: Option<Shape>,
32
    m_shape: Option<Shape>,
33
    cache: Rc<RefCell<ColumnCacheReader>>,
34
}
35
impl OpenVectorLayer {
36
    /// Create a new OpenVectorLayer
UNCOV
37
    pub fn new(cache: Rc<RefCell<ColumnCacheReader>>) -> OpenVectorLayer {
×
UNCOV
38
        OpenVectorLayer {
×
UNCOV
39
            version: 1,
×
UNCOV
40
            name: String::new(),
×
UNCOV
41
            extent: Extent::default(),
×
UNCOV
42
            shape: None,
×
UNCOV
43
            m_shape: None,
×
UNCOV
44
            features: Vec::new(),
×
UNCOV
45
            cache,
×
UNCOV
46
        }
×
UNCOV
47
    }
×
48
}
49
impl VectorLayerMethods for OpenVectorLayer {
UNCOV
50
    fn version(&self) -> u16 {
×
UNCOV
51
        self.version
×
UNCOV
52
    }
×
UNCOV
53
    fn name(&self) -> String {
×
UNCOV
54
        self.name.clone()
×
UNCOV
55
    }
×
UNCOV
56
    fn extent(&self) -> usize {
×
UNCOV
57
        self.extent.into()
×
UNCOV
58
    }
×
UNCOV
59
    fn len(&self) -> usize {
×
UNCOV
60
        self.features.len()
×
UNCOV
61
    }
×
UNCOV
62
    fn is_empty(&self) -> bool {
×
UNCOV
63
        self.features.is_empty()
×
UNCOV
64
    }
×
UNCOV
65
    fn feature(&mut self, i: usize) -> Option<&mut dyn crate::VectorFeatureMethods> {
×
UNCOV
66
        self.features.get_mut(i).map(|f| f as &mut dyn crate::VectorFeatureMethods)
×
UNCOV
67
    }
×
68
}
69
impl ProtoRead for OpenVectorLayer {
UNCOV
70
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
×
UNCOV
71
        match tag {
×
UNCOV
72
            1 => self.version = pb.read_varint::<u16>(),
×
73
            2 => {
UNCOV
74
                self.name = {
×
UNCOV
75
                    let mut cache = self.cache.borrow_mut();
×
UNCOV
76
                    cache.get_string(pb.read_varint())
×
UNCOV
77
                }
×
78
            }
UNCOV
79
            3 => self.extent = pb.read_varint::<Extent>(),
×
UNCOV
80
            4 => self.features.push(read_feature(
×
UNCOV
81
                pb.read_bytes(),
×
UNCOV
82
                self.extent,
×
UNCOV
83
                self.cache.clone(),
×
UNCOV
84
                &self.shape.clone().unwrap_or_default(),
×
UNCOV
85
                self.m_shape.clone().unwrap_or_default(),
×
UNCOV
86
            )),
×
87
            5 => {
UNCOV
88
                self.shape = {
×
UNCOV
89
                    let mut cache = self.cache.borrow_mut();
×
UNCOV
90
                    Some(decode_shape(pb.read_varint(), &mut cache))
×
UNCOV
91
                }
×
92
            }
93
            6 => {
UNCOV
94
                self.m_shape = {
×
UNCOV
95
                    let mut cache: core::cell::RefMut<ColumnCacheReader> = self.cache.borrow_mut();
×
UNCOV
96
                    Some(decode_shape(pb.read_varint(), &mut cache))
×
UNCOV
97
                }
×
98
            }
99
            #[tarpaulin::skip]
100
            _ => panic!("unknown tag: {}", tag),
×
101
        }
UNCOV
102
    }
×
103
}
104

105
/// Write the layer to a protobuf
UNCOV
106
pub fn write_layer(layer: &mut BaseVectorLayer, cache: &mut ColumnCacheWriter) -> Vec<u8> {
×
UNCOV
107
    let mut pbf = Protobuf::new();
×
UNCOV
108

×
UNCOV
109
    pbf.write_varint_field(1, layer.version);
×
UNCOV
110
    pbf.write_varint_field(2, cache.add_string(layer.name.clone()));
×
UNCOV
111
    pbf.write_varint_field(3, layer.extent);
×
UNCOV
112
    pbf.write_varint_field(5, encode_shape(&layer.shape, cache));
×
UNCOV
113
    if let Some(ref m_shape) = layer.m_shape {
×
UNCOV
114
        pbf.write_varint_field(6, encode_shape(m_shape, cache));
×
UNCOV
115
    }
×
116

117
    // sort by feature type
UNCOV
118
    layer.features.sort_by_key(|a| a.get_type());
×
119

UNCOV
120
    for feature in &layer.features {
×
UNCOV
121
        pbf.write_bytes_field(
×
UNCOV
122
            4,
×
UNCOV
123
            &write_feature(feature, &layer.shape, layer.m_shape.as_ref(), cache),
×
UNCOV
124
        );
×
UNCOV
125
    }
×
126

UNCOV
127
    pbf.take()
×
UNCOV
128
}
×
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