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 tokenizer module. 16 #pragma once 17 18 /// For a tokenized string with arguments, the types of the arguments are 19 /// encoded in either 4 bytes (`uint32_t`) or 8 bytes (`uint64_t`). 4 bytes 20 /// supports up to 14 tokenized string arguments; 8 bytes supports up to 29 21 /// arguments. Using 8 bytes increases code size for 32-bit machines. 22 /// 23 /// Argument types are encoded two bits per argument, in little-endian order. 24 /// The 4 or 6 least-significant bits, respectively, store the number of 25 /// arguments, while the remaining bits encode the argument types. 26 #ifndef PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES 27 #define PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES 4 28 #endif // PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES 29 30 /// Maximum number of characters to hash in C. In C code, strings shorter than 31 /// this length are treated as if they were zero-padded up to the length. 32 /// Strings that are the same length and share a common prefix longer than this 33 /// value hash to the same value. Increasing `PW_TOKENIZER_CFG_C_HASH_LENGTH` 34 /// increases the compilation time for C due to the complexity of the hashing 35 /// macros. 36 /// 37 /// `PW_TOKENIZER_CFG_C_HASH_LENGTH` has no effect on C++ code. In C++, hashing 38 /// is done with a `constexpr` function instead of a macro. There are no string 39 /// length limitations and compilation times are unaffected by this macro. 40 /// 41 /// Only hash lengths for which there is a corresponding macro header 42 /// (`pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_#_hash_macro.`) are 43 /// supported. Additional macros may be generated with the 44 /// `generate_hash_macro.py` function. New macro headers must then be added to 45 /// `pw_tokenizer/internal/tokenize_string.h`. 46 /// 47 /// This MUST match the value of `DEFAULT_C_HASH_LENGTH` in 48 /// `pw_tokenizer/py/pw_tokenizer/tokens.py`. 49 #ifndef PW_TOKENIZER_CFG_C_HASH_LENGTH 50 #define PW_TOKENIZER_CFG_C_HASH_LENGTH 128 51 #endif // PW_TOKENIZER_CFG_C_HASH_LENGTH 52 53 /// `PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES` is deprecated. It is used as 54 /// the default value for pw_log_tokenized's 55 /// @c_macro{PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES}. This value should not 56 /// be configured; set @c_macro{PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES} 57 /// instead. 58 #ifndef PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES 59 #define PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES 52 60 #endif // PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES 61 62 // This character is used to mark the start of all tokenized messages. For 63 // consistency, it is recommended to always use $ if possible. 64 // If required, a different non-Base64 character may be used as a prefix. 65 // 66 // A string version of the character is required for format-string-literal 67 // concatenation. 68 #ifndef PW_TOKENIZER_NESTED_PREFIX_STR 69 #define PW_TOKENIZER_NESTED_PREFIX_STR "$" 70 #endif // PW_TOKENIZER_NESTED_PREFIX_STR 71