C/C++ API Reference
Loading...
Searching...
No Matches
config.h
1// Copyright 2021 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15// Configuration macros for the protobuf module.
16#pragma once
17
18#include <cstddef>
19
21
22// When encoding nested messages, the number of bytes to reserve for the varint
23// submessage length. Nested messages are limited in size to the maximum value
24// that can be varint-encoded into this reserved space.
25//
26// The values that can be set, and their corresponding maximum submessage
27// lengths, are outlined below.
28//
29// 1 byte => 127
30// 2 bytes => 16,383 or < 16KiB
31// 3 bytes => 2,097,151 or < 2048KiB
32// 4 bytes => 268,435,455 or < 256MiB
33// 5 bytes => 4,294,967,295 or < 4GiB (max uint32_t)
34//
35#ifndef PW_PROTOBUF_CFG_MAX_VARINT_SIZE
36#define PW_PROTOBUF_CFG_MAX_VARINT_SIZE 4
37#endif // PW_PROTOBUF_MAX_VARINT_SIZE
38
40
41static_assert(PW_PROTOBUF_CFG_MAX_VARINT_SIZE > 0 &&
42 PW_PROTOBUF_CFG_MAX_VARINT_SIZE <= 5);
43
44namespace pw::protobuf::config {
45
46inline constexpr size_t kMaxVarintSize = PW_PROTOBUF_CFG_MAX_VARINT_SIZE;
47
48} // namespace pw::protobuf::config