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