GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
protobuf.h
Go to the documentation of this file.
1// Copyright (c) 2024 Clarisma / GeoDesk contributors
2// SPDX-License-Identifier: LGPL-3.0-only
3
4#pragma once
5
8
9namespace clarisma {
10
11namespace protobuf
12{
13 enum Type
14 {
15 VARINT = 0,
16 FIXED64 = 1,
17 STRING = 2,
18 FIXED32 = 5
19 };
20
21 /*
22 struct Message
23 {
24 Message() : start(nullptr), end(nullptr) {}
25 Message(const uint8_t* start_, const uint8_t* end_) :
26 start(start_), end(end_) {}
27
28 bool isEmpty() const { return start == end; }
29 size_t length() const { return end - start; }
30
31 const uint8_t* start;
32 const uint8_t* end;
33 };
34 */
35
36 using Field = uint32_t;
37
38 inline ByteSpan readMessage(const uint8_t*& p)
39 {
40 uint32_t size = readVarint32(p);
41 const uint8_t* start = p;
42 p += size;
43 return ByteSpan(start, size);
44 }
45
46 inline Field readField(const uint8_t*& p)
47 {
48 return readVarint32(p);
49 }
50
51 inline void skipEntity(const uint8_t*& p, Field field)
52 {
53 switch (field & 7)
54 {
55 case Type::VARINT:
56 readVarint64(p);
57 break;
58 case Type::FIXED64:
59 p += 8;
60 break;
61 case Type::STRING:
62 readMessage(p);
63 break;
64 case Type::FIXED32:
65 p += 4;
66 break;
67 default:
68 // TODO: throw new PbfException("Unknown type: " + (marker & 7));
69 break;
70 }
71 }
72
73} // end namespace
74
75
76} // namespace clarisma
Definition Arena.h:17
uint64_t readVarint64(const uint8_t *&p)
Definition varint.h:40
Span< const uint8_t > ByteSpan
Definition Span.h:60
uint32_t readVarint32(const uint8_t *&p)
Definition varint.h:35