Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_rpc / public / pw_rpc / internal / config.h
1 // Copyright 2020 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 pw_rpc module.
16 #pragma once
17
18 #include <cstddef>
19
20 // The Nanopb-based pw_rpc implementation allocates memory to use for Nanopb
21 // structs for the request and response protobufs. The template function that
22 // allocates these structs rounds struct sizes up to this value so that
23 // different structs can be allocated with the same function. Structs with sizes
24 // larger than this value cause an extra function to be created, which slightly
25 // increases code size.
26 //
27 // Ideally, this value will be set to the size of the largest Nanopb struct used
28 // as an RPC request or response. The buffer can be stack or globally allocated
29 // (see PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE).
30 #ifndef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
31 #define PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE 64
32 #endif  // PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
33
34 namespace pw::rpc::cfg {
35
36 inline constexpr size_t kNanopbStructMinBufferSize =
37     PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE;
38
39 }  // namespace pw::rpc::cfg
40
41 #undef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
42
43 // This option determines whether to allocate the Nanopb structs on the stack or
44 // in a global variable. Globally allocated structs are NOT thread safe, but
45 // work fine when the RPC server's ProcessPacket function is only called from
46 // one thread.
47 #ifndef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
48 #define PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE 1
49 #endif  // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
50
51 #if PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
52 #define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
53 #else
54 #define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS static
55 #endif  // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
56
57 #undef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE