C/C++ API Reference
Loading...
Searching...
No Matches
base64.h
1// Copyright 2023 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 <cstddef>
17#include <type_traits>
18
19#include "pw_log_tokenized/config.h"
20#include "pw_tokenizer/base64.h"
21
22namespace pw::log_tokenized {
23
25
26// Minimum capacity for a string that to hold the Base64-encoded version of a
27// PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES tokenized message. This is the
28// capacity needed to encode to a `pw::InlineString` and does not include a null
29// terminator.
30inline constexpr size_t kBase64EncodedBufferSizeBytes =
31 tokenizer::Base64EncodedBufferSize(kEncodingBufferSizeBytes);
32
37 span<const std::byte> binary_message) {
38 return tokenizer::PrefixedBase64Encode<kEncodingBufferSizeBytes>(
39 binary_message);
40}
41
42#ifndef PW_EXCLUDE_FROM_DOXYGEN // Doxygen fails to parse this, so skip it.
43
44template <typename T,
45 typename = std::enable_if_t<sizeof(T) == sizeof(std::byte)>>
47 const T* log_buffer, size_t size_bytes) {
48 return PrefixedBase64Encode(as_bytes(span(log_buffer, size_bytes)));
49}
50
51#endif // PW_EXCLUDE_FROM_DOXYGEN
52
53} // namespace pw::log_tokenized
pw::InlineBasicString is a fixed-capacity version of std::basic_string. In brief:
Definition: string.h:68
Definition: span_impl.h:235
InlineString< kBase64EncodedBufferSizeBytes > PrefixedBase64Encode(span< const std::byte > binary_message)
Definition: base64.h:36
constexpr size_t Base64EncodedBufferSize(size_t message_size)
Definition: base64.h:89