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