FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
padded_json.hpp
Go to the documentation of this file.
1#pragma once
2// PaddedJson: owns a copy of a JSON text with kJsonPadding zero bytes behind it so the
3// decoders (which assume RecvBuffer-style padding) can be driven from fixtures, tests and
4// benchmarks. Never used on the hot path.
6
7#include <cstddef>
8#include <cstring>
9#include <memory>
10#include <string_view>
11
12namespace fastmm::venues {
13
14class PaddedJson {
15 public:
16 PaddedJson() = default;
17 explicit PaddedJson(std::string_view text) { assign(text); }
19 void assign(std::string_view text) {
20 len_ = text.size();
21 buf_.reset(new char[len_ + kJsonPadding]);
22 if (len_ > 0) std::memcpy(buf_.get(), text.data(), len_);
23 std::memset(buf_.get() + len_, 0, kJsonPadding);
24 }
25 [[nodiscard]] std::string_view view() const noexcept { return {buf_.get(), len_}; }
26 [[nodiscard]] const char* data() const noexcept { return buf_.get(); }
27 [[nodiscard]] std::size_t size() const noexcept { return len_; }
29 private:
30 std::unique_ptr<char[]> buf_;
31 std::size_t len_ = 0;
32};
33
34} // namespace fastmm::venues
void assign(std::string_view text)
Definition padded_json.hpp:21
const char * data() const noexcept
Definition padded_json.hpp:28
std::string_view view() const noexcept
Definition padded_json.hpp:27
std::size_t size() const noexcept
Definition padded_json.hpp:29
Hot-path connector concepts (6.2).
Definition venue.hpp:38
constexpr std::size_t kJsonPadding
Parsers that hand raw text frames to simdjson need SIMDJSON_PADDING (64) readable bytes after the pay...
Definition feed.hpp:87