Chris@64: // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors Chris@64: // Licensed under the MIT License: Chris@64: // Chris@64: // Permission is hereby granted, free of charge, to any person obtaining a copy Chris@64: // of this software and associated documentation files (the "Software"), to deal Chris@64: // in the Software without restriction, including without limitation the rights Chris@64: // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell Chris@64: // copies of the Software, and to permit persons to whom the Software is Chris@64: // furnished to do so, subject to the following conditions: Chris@64: // Chris@64: // The above copyright notice and this permission notice shall be included in Chris@64: // all copies or substantial portions of the Software. Chris@64: // Chris@64: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR Chris@64: // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, Chris@64: // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE Chris@64: // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER Chris@64: // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, Chris@64: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN Chris@64: // THE SOFTWARE. Chris@64: Chris@64: #ifndef CAPNP_SERIALIZE_ASYNC_H_ Chris@64: #define CAPNP_SERIALIZE_ASYNC_H_ Chris@64: Chris@64: #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS) Chris@64: #pragma GCC system_header Chris@64: #endif Chris@64: Chris@64: #include Chris@64: #include "message.h" Chris@64: Chris@64: namespace capnp { Chris@64: Chris@64: kj::Promise> readMessage( Chris@64: kj::AsyncInputStream& input, ReaderOptions options = ReaderOptions(), Chris@64: kj::ArrayPtr scratchSpace = nullptr); Chris@64: // Read a message asynchronously. Chris@64: // Chris@64: // `input` must remain valid until the returned promise resolves (or is canceled). Chris@64: // Chris@64: // `scratchSpace`, if provided, must remain valid until the returned MessageReader is destroyed. Chris@64: Chris@64: kj::Promise>> tryReadMessage( Chris@64: kj::AsyncInputStream& input, ReaderOptions options = ReaderOptions(), Chris@64: kj::ArrayPtr scratchSpace = nullptr); Chris@64: // Like `readMessage` but returns null on EOF. Chris@64: Chris@64: kj::Promise writeMessage(kj::AsyncOutputStream& output, Chris@64: kj::ArrayPtr> segments) Chris@64: KJ_WARN_UNUSED_RESULT; Chris@64: kj::Promise writeMessage(kj::AsyncOutputStream& output, MessageBuilder& builder) Chris@64: KJ_WARN_UNUSED_RESULT; Chris@64: // Write asynchronously. The parameters must remain valid until the returned promise resolves. Chris@64: Chris@64: // ======================================================================================= Chris@64: // inline implementation details Chris@64: Chris@64: inline kj::Promise writeMessage(kj::AsyncOutputStream& output, MessageBuilder& builder) { Chris@64: return writeMessage(output, builder.getSegmentsForOutput()); Chris@64: } Chris@64: Chris@64: } // namespace capnp Chris@64: Chris@64: #endif // CAPNP_SERIALIZE_ASYNC_H_