Skip to content

Commit 9ca4dcc

Browse files
committed
Allow specify schema in capnproto's stream interface
1 parent afc0255 commit 9ca4dcc

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ if (REFLECTCPP_CAPNPROTO)
241241
if (NOT TARGET CapnProto)
242242
find_package(CapnProto CONFIG REQUIRED)
243243
endif ()
244-
target_link_libraries(reflectcpp PUBLIC CapnProto::kj CapnProto::capnp CapnProto::capnpc CapnProto::kj-gzip)
244+
set(CAPNPC_LIB CapnProto::capnpc)
245+
if (NOT TARGET CapnProto::capnpc)
246+
# in some old versions, there is no alias target CapnProto::capnpc, fallback to capnc
247+
set(CAPNPC_LIB capnpc)
248+
endif()
249+
target_link_libraries(reflectcpp PUBLIC CapnProto::kj CapnProto::capnp ${CAPNPC_LIB} CapnProto::kj-gzip)
245250
endif ()
246251

247252
if (REFLECTCPP_CBOR)

include/rfl/capnproto/read.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ auto read(std::istream& _stream) {
7878
return read<T, Ps...>(bytes.data(), bytes.size());
7979
}
8080

81+
template <class T, class... Ps>
82+
auto read(std::istream& _stream, const Schema<T>& _schema) {
83+
return read<T, Ps...>(_stream, _schema);
84+
}
85+
8186
} // namespace rfl::capnproto
8287

8388
#endif

include/rfl/capnproto/write.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ std::ostream& write(const auto& _obj, std::ostream& _stream) {
6767
return _stream;
6868
}
6969

70+
template <class... Ps>
71+
std::ostream& write(const auto& _obj, const auto& _schema, std::ostream& _stream) {
72+
auto buffer = write<Ps...>(_obj, _schema);
73+
_stream.write(buffer.data(), buffer.size());
74+
return _stream;
75+
}
76+
7077
} // namespace rfl::capnproto
7178

7279
#endif

0 commit comments

Comments
 (0)