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

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

12 Aug 2024 09:02PM UTC coverage: 27.612% (+4.4%) from 23.175%
#17

push

Mr Martian
tests moving along

1915 of 2437 new or added lines in 17 files covered. (78.58%)

14 existing lines in 5 files now uncovered.

11082 of 40134 relevant lines covered (27.61%)

105.18 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::base::BaseVectorLayer;
4
use crate::open::{
5
    decode_shape, encode_shape, read_feature, write_feature, ColumnCacheReader, ColumnCacheWriter,
6
    Extent, OpenVectorFeature, Shape,
7
};
8
use crate::VectorLayerMethods;
9

10
use core::cell::RefCell;
11

12
use alloc::rc::Rc;
13
use alloc::string::String;
14
use alloc::vec::Vec;
15

16
/// The Open Vector Layer class represents a layer in an Open Vector Tile.
17
/// Contains an extent, name, version, and features.
18
/// The features will utilize the layer extent to decode geometry.
19
pub struct OpenVectorLayer {
20
    /// the version of the vector tile
21
    pub version: u16,
22
    /// the name of the layer
23
    pub name: String,
24
    /// the extent of the vector layer
25
    pub extent: Extent,
26
    /// the features in the layer
27
    pub features: Vec<OpenVectorFeature>,
28
    shape: Option<Shape>,
29
    m_shape: Option<Shape>,
30
    cache: Rc<RefCell<ColumnCacheReader>>,
31
}
32
impl OpenVectorLayer {
33
    /// Create a new OpenVectorLayer
34
    pub fn new(
×
35
        pbf: Rc<RefCell<Protobuf>>,
×
36
        cache: Rc<RefCell<ColumnCacheReader>>,
×
37
    ) -> OpenVectorLayer {
×
38
        let mut ol = OpenVectorLayer {
×
39
            version: 1,
×
40
            name: String::new(),
×
41
            extent: Extent::default(),
×
42
            shape: None,
×
43
            m_shape: None,
×
44
            features: Vec::new(),
×
45
            cache,
×
46
        };
×
47

×
48
        let mut tmp_pbf = pbf.borrow_mut();
×
49
        tmp_pbf.read_message::<OpenVectorLayer>(&mut ol);
×
50

×
51
        ol
×
52
    }
×
53
}
54
impl VectorLayerMethods for OpenVectorLayer {
55
    fn version(&self) -> u16 {
×
56
        self.version
×
57
    }
×
58
    fn name(&self) -> String {
×
59
        self.name.clone()
×
60
    }
×
61
    fn extent(&self) -> usize {
×
62
        self.extent.into()
×
63
    }
×
64
}
65
impl ProtoRead for OpenVectorLayer {
66
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
×
67
        match tag {
×
68
            1 => self.version = pb.read_varint::<u16>(),
×
69
            2 => {
NEW
70
                self.name = {
×
NEW
71
                    let mut cache = self.cache.borrow_mut();
×
NEW
72
                    cache.get_string(pb.read_varint())
×
NEW
73
                }
×
74
            }
75
            3 => self.extent = pb.read_varint::<Extent>(),
×
76
            4 => {
×
77
                read_feature(
×
78
                    pb.read_bytes(),
×
79
                    self.extent,
×
80
                    self.cache.clone(),
×
81
                    &self.shape.clone().unwrap_or_default(),
×
82
                    self.m_shape.clone().unwrap_or_default(),
×
83
                );
×
NEW
84
            }
×
85
            5 => {
NEW
86
                self.shape = {
×
NEW
87
                    let mut cache = self.cache.borrow_mut();
×
NEW
88
                    Some(decode_shape(pb.read_varint(), &mut cache))
×
NEW
89
                }
×
90
            }
91
            6 => {
NEW
92
                self.m_shape = {
×
NEW
93
                    let mut cache: core::cell::RefMut<ColumnCacheReader> = self.cache.borrow_mut();
×
NEW
94
                    Some(decode_shape(pb.read_varint(), &mut cache))
×
NEW
95
                }
×
96
            }
UNCOV
97
            _ => panic!("unknown tag: {}", tag),
×
98
        }
99
    }
×
100
}
101

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

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

114
    // sort by feature type
115
    layer.features.sort_by_key(|a| a.get_type());
×
116

117
    for feature in &layer.features {
×
NEW
118
        pbf.write_bytes_field(
×
NEW
119
            4,
×
NEW
120
            &write_feature(feature, &layer.shape, layer.m_shape.as_ref(), cache),
×
NEW
121
        );
×
UNCOV
122
    }
×
123

124
    pbf.take()
×
125
}
×
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