AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
protobuf.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-protobuf-export.hpp"
23
24#include <concepts>
25#include <istream>
26#include <ostream>
27#include <string>
28#include <string_view>
29#include <type_traits>
30
31#include <google/protobuf/message.h>
32
33#include "codec/codec.hpp"
34#include "codec/mediaType.hpp"
35
36namespace anch::codec {
37
45 template<typename T>
46 concept ProtobufMessage = std::derived_from<T, google::protobuf::Message>;
47
59 struct ANCH_CODEC_PROTOBUF_EXPORT Protobuf {
60
66 static std::string_view mediaType() noexcept;
67
76 template<anch::codec::ProtobufMessage T>
77 static void serialize(const T& value, std::ostream& out);
78
89 template<anch::codec::ProtobufMessage T>
90 static void deserialize(T& value, std::istream& input, anch::codec::Side side);
91
100 static void write(const google::protobuf::Message& message, std::ostream& out);
101
110 static void read(google::protobuf::Message& message, std::istream& input);
111
122 static void read(google::protobuf::Message& message, std::string_view data);
123
124 };
125
136 struct ANCH_CODEC_PROTOBUF_EXPORT ProtobufJson {
137
143 static std::string_view mediaType() noexcept;
144
154 template<anch::codec::ProtobufMessage T>
155 static void serialize(const T& value, std::ostream& out, anch::codec::Side side);
156
167 template<anch::codec::ProtobufMessage T>
168 static void deserialize(T& value, std::istream& input, anch::codec::Side side);
169
179 static std::string toJson(const google::protobuf::Message& message);
180
190 static void fromJson(google::protobuf::Message& message, std::string_view json, bool ignoreUnknownFields);
191
192 };
193
194}
195
196#include "codec/impl/protobuf.hpp"
Definition protobuf.hpp:46
AnCH codec library namespace.
Definition csv.hpp:31
Side
Definition codec.hpp:48
JSON namespace.
Definition constants.hpp:27
AnCH framework base namespace.
Definition app.hpp:30
Definition protobuf.hpp:59
static void serialize(const T &value, std::ostream &out)
static void write(const google::protobuf::Message &message, std::ostream &out)
static void read(google::protobuf::Message &message, std::istream &input)
static void deserialize(T &value, std::istream &input, anch::codec::Side side)
static std::string_view mediaType() noexcept
Definition protobuf.hpp:136
static void serialize(const T &value, std::ostream &out, anch::codec::Side side)
static std::string toJson(const google::protobuf::Message &message)
static void deserialize(T &value, std::istream &input, anch::codec::Side side)
static std::string_view mediaType() noexcept
static void fromJson(google::protobuf::Message &message, std::string_view json, bool ignoreUnknownFields)