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