AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
thrift.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-codec-thrift-export.hpp"
23
24#include <concepts>
25#include <functional>
26#include <cstdint>
27#include <istream>
28#include <memory>
29#include <optional>
30#include <ostream>
31#include <string>
32#include <string_view>
33#include <type_traits>
34
35#include <thrift/protocol/TProtocol.h>
36#include <thrift/transport/TTransport.h>
37
38#include "codec/codec.hpp"
39#include "codec/mediaType.hpp"
40
41namespace anch::codec {
42
50 template<typename T>
51 concept ThriftStruct = requires(T& value, const T& constant, apache::thrift::protocol::TProtocol* protocol) {
52 { value.read(protocol) } -> std::convertible_to<uint32_t>;
53 { constant.write(protocol) } -> std::convertible_to<uint32_t>;
54 };
55
69
79 ANCH_CODEC_THRIFT_EXPORT std::string_view thriftMediaType(anch::codec::ThriftProtocol protocol) noexcept;
80
91 ANCH_CODEC_THRIFT_EXPORT std::optional<anch::codec::ThriftProtocol> thriftProtocolOf(const anch::codec::MediaType& mediaType);
92
103 ANCH_CODEC_THRIFT_EXPORT std::shared_ptr<apache::thrift::protocol::TProtocol> thriftProtocol(anch::codec::ThriftProtocol protocol,
104 std::shared_ptr<apache::thrift::transport::TTransport> transport);
105
116 ANCH_CODEC_THRIFT_EXPORT std::string thriftWrite(anch::codec::ThriftProtocol protocol, const std::function<void(apache::thrift::protocol::TProtocol*)>& write);
117
129 ANCH_CODEC_THRIFT_EXPORT void thriftRead(anch::codec::ThriftProtocol protocol, std::string_view content,
130 const std::function<void(apache::thrift::protocol::TProtocol*)>& read);
131
144 template<anch::codec::ThriftProtocol P>
145 struct ThriftCodec {
146
152 static std::string_view mediaType() noexcept;
153
160 template<anch::codec::ThriftStruct T>
161 static void serialize(const T& value, std::ostream& out);
162
173 template<anch::codec::ThriftStruct T>
174 static void deserialize(T& value, std::istream& input, anch::codec::Side side);
175
176 };
177
180
183
186
187}
188
189#include "codec/impl/thrift.hpp"
Definition mediaType.hpp:41
Definition thrift.hpp:51
AnCH codec library namespace.
Definition csv.hpp:31
Side
Definition codec.hpp:48
std::string thriftWrite(anch::codec::ThriftProtocol protocol, const std::function< void(apache::thrift::protocol::TProtocol *)> &write)
ThriftProtocol
Definition thrift.hpp:61
@ JSON
Definition thrift.hpp:67
@ BINARY
Definition thrift.hpp:63
@ COMPACT
Definition thrift.hpp:65
void thriftRead(anch::codec::ThriftProtocol protocol, std::string_view content, const std::function< void(apache::thrift::protocol::TProtocol *)> &read)
anch::codec::ThriftCodec< anch::codec::ThriftProtocol::BINARY > ThriftBinary
Definition thrift.hpp:179
anch::codec::ThriftCodec< anch::codec::ThriftProtocol::JSON > ThriftJson
Definition thrift.hpp:185
std::string_view thriftMediaType(anch::codec::ThriftProtocol protocol) noexcept
std::optional< anch::codec::ThriftProtocol > thriftProtocolOf(const anch::codec::MediaType &mediaType)
std::shared_ptr< apache::thrift::protocol::TProtocol > thriftProtocol(anch::codec::ThriftProtocol protocol, std::shared_ptr< apache::thrift::transport::TTransport > transport)
anch::codec::ThriftCodec< anch::codec::ThriftProtocol::COMPACT > ThriftCompact
Definition thrift.hpp:182
AnCH framework base namespace.
Definition app.hpp:30
Definition thrift.hpp:145
static std::string_view mediaType() noexcept
static void deserialize(T &value, std::istream &input, anch::codec::Side side)
static void serialize(const T &value, std::ostream &out)