Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_tokenizer / pw_tokenizer_private / encode_args.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 #pragma once
15
16 #include <array>
17 #include <cstdarg>
18 #include <cstddef>
19 #include <span>
20
21 #include "pw_tokenizer/config.h"
22 #include "pw_tokenizer/internal/argument_types.h"
23 #include "pw_tokenizer/tokenize.h"
24
25 namespace pw {
26 namespace tokenizer {
27
28 // Buffer for encoding a tokenized string and arguments.
29 struct EncodedMessage {
30   pw_tokenizer_Token token;
31   std::array<uint8_t,
32              PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES - sizeof(token)>
33       args;
34 };
35
36 static_assert(PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES >=
37                   sizeof(pw_tokenizer_Token),
38               "PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES must be at least "
39               "large enough for a token (4 bytes)");
40
41 static_assert(offsetof(EncodedMessage, args) == sizeof(EncodedMessage::token) &&
42                   PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES ==
43                       sizeof(EncodedMessage),
44               "EncodedMessage should not have padding bytes between members");
45
46 // Encodes a tokenized string's arguments to a buffer. The
47 // _pw_tokenizer_ArgTypes parameter specifies the argument types, in place of a
48 // format string.
49 size_t EncodeArgs(_pw_tokenizer_ArgTypes types,
50                   va_list args,
51                   std::span<uint8_t> output);
52
53 }  // namespace tokenizer
54 }  // namespace pw