annotate win32-mingw/include/capnp/serialize-packed.h @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents eccd51b72864
children
rev   line source
Chris@64 1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
Chris@64 2 // Licensed under the MIT License:
Chris@64 3 //
Chris@64 4 // Permission is hereby granted, free of charge, to any person obtaining a copy
Chris@64 5 // of this software and associated documentation files (the "Software"), to deal
Chris@64 6 // in the Software without restriction, including without limitation the rights
Chris@64 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Chris@64 8 // copies of the Software, and to permit persons to whom the Software is
Chris@64 9 // furnished to do so, subject to the following conditions:
Chris@64 10 //
Chris@64 11 // The above copyright notice and this permission notice shall be included in
Chris@64 12 // all copies or substantial portions of the Software.
Chris@64 13 //
Chris@64 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chris@64 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Chris@64 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Chris@64 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Chris@64 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Chris@64 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Chris@64 20 // THE SOFTWARE.
Chris@64 21
Chris@64 22 #ifndef CAPNP_SERIALIZE_PACKED_H_
Chris@64 23 #define CAPNP_SERIALIZE_PACKED_H_
Chris@64 24
Chris@64 25 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS)
Chris@64 26 #pragma GCC system_header
Chris@64 27 #endif
Chris@64 28
Chris@64 29 #include "serialize.h"
Chris@64 30
Chris@64 31 namespace capnp {
Chris@64 32
Chris@64 33 namespace _ { // private
Chris@64 34
Chris@64 35 class PackedInputStream: public kj::InputStream {
Chris@64 36 // An input stream that unpacks packed data with a picky constraint: The caller must read data
Chris@64 37 // in the exact same size and sequence as the data was written to PackedOutputStream.
Chris@64 38
Chris@64 39 public:
Chris@64 40 explicit PackedInputStream(kj::BufferedInputStream& inner);
Chris@64 41 KJ_DISALLOW_COPY(PackedInputStream);
Chris@64 42 ~PackedInputStream() noexcept(false);
Chris@64 43
Chris@64 44 // implements InputStream ------------------------------------------
Chris@64 45 size_t tryRead(void* buffer, size_t minBytes, size_t maxBytes) override;
Chris@64 46 void skip(size_t bytes) override;
Chris@64 47
Chris@64 48 private:
Chris@64 49 kj::BufferedInputStream& inner;
Chris@64 50 };
Chris@64 51
Chris@64 52 class PackedOutputStream: public kj::OutputStream {
Chris@64 53 public:
Chris@64 54 explicit PackedOutputStream(kj::BufferedOutputStream& inner);
Chris@64 55 KJ_DISALLOW_COPY(PackedOutputStream);
Chris@64 56 ~PackedOutputStream() noexcept(false);
Chris@64 57
Chris@64 58 // implements OutputStream -----------------------------------------
Chris@64 59 void write(const void* buffer, size_t bytes) override;
Chris@64 60
Chris@64 61 private:
Chris@64 62 kj::BufferedOutputStream& inner;
Chris@64 63 };
Chris@64 64
Chris@64 65 } // namespace _ (private)
Chris@64 66
Chris@64 67 class PackedMessageReader: private _::PackedInputStream, public InputStreamMessageReader {
Chris@64 68 public:
Chris@64 69 PackedMessageReader(kj::BufferedInputStream& inputStream, ReaderOptions options = ReaderOptions(),
Chris@64 70 kj::ArrayPtr<word> scratchSpace = nullptr);
Chris@64 71 KJ_DISALLOW_COPY(PackedMessageReader);
Chris@64 72 ~PackedMessageReader() noexcept(false);
Chris@64 73 };
Chris@64 74
Chris@64 75 class PackedFdMessageReader: private kj::FdInputStream, private kj::BufferedInputStreamWrapper,
Chris@64 76 public PackedMessageReader {
Chris@64 77 public:
Chris@64 78 PackedFdMessageReader(int fd, ReaderOptions options = ReaderOptions(),
Chris@64 79 kj::ArrayPtr<word> scratchSpace = nullptr);
Chris@64 80 // Read message from a file descriptor, without taking ownership of the descriptor.
Chris@64 81 // Note that if you want to reuse the descriptor after the reader is destroyed, you'll need to
Chris@64 82 // seek it, since otherwise the position is unspecified.
Chris@64 83
Chris@64 84 PackedFdMessageReader(kj::AutoCloseFd fd, ReaderOptions options = ReaderOptions(),
Chris@64 85 kj::ArrayPtr<word> scratchSpace = nullptr);
Chris@64 86 // Read a message from a file descriptor, taking ownership of the descriptor.
Chris@64 87
Chris@64 88 KJ_DISALLOW_COPY(PackedFdMessageReader);
Chris@64 89
Chris@64 90 ~PackedFdMessageReader() noexcept(false);
Chris@64 91 };
Chris@64 92
Chris@64 93 void writePackedMessage(kj::BufferedOutputStream& output, MessageBuilder& builder);
Chris@64 94 void writePackedMessage(kj::BufferedOutputStream& output,
Chris@64 95 kj::ArrayPtr<const kj::ArrayPtr<const word>> segments);
Chris@64 96 // Write a packed message to a buffered output stream.
Chris@64 97
Chris@64 98 void writePackedMessage(kj::OutputStream& output, MessageBuilder& builder);
Chris@64 99 void writePackedMessage(kj::OutputStream& output,
Chris@64 100 kj::ArrayPtr<const kj::ArrayPtr<const word>> segments);
Chris@64 101 // Write a packed message to an unbuffered output stream. If you intend to write multiple messages
Chris@64 102 // in succession, consider wrapping your output in a buffered stream in order to reduce system
Chris@64 103 // call overhead.
Chris@64 104
Chris@64 105 void writePackedMessageToFd(int fd, MessageBuilder& builder);
Chris@64 106 void writePackedMessageToFd(int fd, kj::ArrayPtr<const kj::ArrayPtr<const word>> segments);
Chris@64 107 // Write a single packed message to the file descriptor.
Chris@64 108
Chris@64 109 size_t computeUnpackedSizeInWords(kj::ArrayPtr<const byte> packedBytes);
Chris@64 110 // Computes the number of words to which the given packed bytes will unpack. Not intended for use
Chris@64 111 // in performance-sensitive situations.
Chris@64 112
Chris@64 113 // =======================================================================================
Chris@64 114 // inline stuff
Chris@64 115
Chris@64 116 inline void writePackedMessage(kj::BufferedOutputStream& output, MessageBuilder& builder) {
Chris@64 117 writePackedMessage(output, builder.getSegmentsForOutput());
Chris@64 118 }
Chris@64 119
Chris@64 120 inline void writePackedMessage(kj::OutputStream& output, MessageBuilder& builder) {
Chris@64 121 writePackedMessage(output, builder.getSegmentsForOutput());
Chris@64 122 }
Chris@64 123
Chris@64 124 inline void writePackedMessageToFd(int fd, MessageBuilder& builder) {
Chris@64 125 writePackedMessageToFd(fd, builder.getSegmentsForOutput());
Chris@64 126 }
Chris@64 127
Chris@64 128 } // namespace capnp
Chris@64 129
Chris@64 130 #endif // CAPNP_SERIALIZE_PACKED_H_