Skip to content

Commit 265b693

Browse files
authored
Allow specify schema in capnproto's stream interface (#521)
1 parent 732e9fe commit 265b693

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
@@ -261,7 +261,12 @@ if (REFLECTCPP_CAPNPROTO)
261261
if (NOT TARGET CapnProto)
262262
find_package(CapnProto CONFIG REQUIRED)
263263
endif ()
264-
target_link_libraries(reflectcpp PUBLIC CapnProto::kj CapnProto::capnp CapnProto::capnpc CapnProto::kj-gzip)
264+
set(CAPNPC_LIB CapnProto::capnpc)
265+
if (NOT TARGET CapnProto::capnpc)
266+
# in some old versions, there is no alias target CapnProto::capnpc, fallback to capnc
267+
set(CAPNPC_LIB capnpc)
268+
endif()
269+
target_link_libraries(reflectcpp PUBLIC CapnProto::kj CapnProto::capnp ${CAPNPC_LIB} CapnProto::kj-gzip)
265270
endif ()
266271

267272
if (REFLECTCPP_CBOR)

include/rfl/capnproto/read.hpp

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

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

8186
#endif

include/rfl/capnproto/write.hpp

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

65+
template <class... Ps>
66+
std::ostream& write(const auto& _obj, const auto& _schema, std::ostream& _stream) {
67+
auto buffer = write<Ps...>(_obj, _schema);
68+
_stream.write(buffer.data(), buffer.size());
69+
return _stream;
70+
}
71+
6572
} // namespace rfl::capnproto
6673

6774
#endif

0 commit comments

Comments
 (0)