annotate win32-mingw/include/capnp/orphan.h @ 64:eccd51b72864

Update Win32 capnp builds to v0.6
author Chris Cannam
date Tue, 23 May 2017 09:16:54 +0100
parents 37d53a7e8262
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_ORPHAN_H_
Chris@64 23 #define CAPNP_ORPHAN_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 "layout.h"
Chris@64 30
Chris@64 31 namespace capnp {
Chris@64 32
Chris@64 33 class StructSchema;
Chris@64 34 class ListSchema;
Chris@64 35 struct DynamicStruct;
Chris@64 36 struct DynamicList;
Chris@64 37 namespace _ { struct OrphanageInternal; }
Chris@64 38
Chris@64 39 template <typename T>
Chris@64 40 class Orphan {
Chris@64 41 // Represents an object which is allocated within some message builder but has no pointers
Chris@64 42 // pointing at it. An Orphan can later be "adopted" by some other object as one of that object's
Chris@64 43 // fields, without having to copy the orphan. For a field `foo` of pointer type, the generated
Chris@64 44 // code will define builder methods `void adoptFoo(Orphan<T>)` and `Orphan<T> disownFoo()`.
Chris@64 45 // Orphans can also be created independently of any parent using an Orphanage.
Chris@64 46 //
Chris@64 47 // `Orphan<T>` can be moved but not copied, like `Own<T>`, so that it is impossible for one
Chris@64 48 // orphan to be adopted multiple times. If an orphan is destroyed without being adopted, its
Chris@64 49 // contents are zero'd out (and possibly reused, if we ever implement the ability to reuse space
Chris@64 50 // in a message arena).
Chris@64 51
Chris@64 52 public:
Chris@64 53 Orphan() = default;
Chris@64 54 KJ_DISALLOW_COPY(Orphan);
Chris@64 55 Orphan(Orphan&&) = default;
Chris@64 56 Orphan& operator=(Orphan&&) = default;
Chris@64 57 inline Orphan(_::OrphanBuilder&& builder): builder(kj::mv(builder)) {}
Chris@64 58
Chris@64 59 inline BuilderFor<T> get();
Chris@64 60 // Get the underlying builder. If the orphan is null, this will allocate and return a default
Chris@64 61 // object rather than crash. This is done for security -- otherwise, you might enable a DoS
Chris@64 62 // attack any time you disown a field and fail to check if it is null. In the case of structs,
Chris@64 63 // this means that the orphan is no longer null after get() returns. In the case of lists,
Chris@64 64 // no actual object is allocated since a simple empty ListBuilder can be returned.
Chris@64 65
Chris@64 66 inline ReaderFor<T> getReader() const;
Chris@64 67
Chris@64 68 inline bool operator==(decltype(nullptr)) const { return builder == nullptr; }
Chris@64 69 inline bool operator!=(decltype(nullptr)) const { return builder != nullptr; }
Chris@64 70
Chris@64 71 inline void truncate(uint size);
Chris@64 72 // Resize an object (which must be a list or a blob) to the given size.
Chris@64 73 //
Chris@64 74 // If the new size is less than the original, the remaining elements will be discarded. The
Chris@64 75 // list is never moved in this case. If the list happens to be located at the end of its segment
Chris@64 76 // (which is always true if the list was the last thing allocated), the removed memory will be
Chris@64 77 // reclaimed (reducing the messag size), otherwise it is simply zeroed. The reclaiming behavior
Chris@64 78 // is particularly useful for allocating buffer space when you aren't sure how much space you
Chris@64 79 // actually need: you can pre-allocate, say, a 4k byte array, read() from a file into it, and
Chris@64 80 // then truncate it back to the amount of space actually used.
Chris@64 81 //
Chris@64 82 // If the new size is greater than the original, the list is extended with default values. If
Chris@64 83 // the list is the last object in its segment *and* there is enough space left in the segment to
Chris@64 84 // extend it to cover the new values, then the list is extended in-place. Otherwise, it must be
Chris@64 85 // moved to a new location, leaving a zero'd hole in the previous space that won't be filled.
Chris@64 86 // This copy is shallow; sub-objects will simply be reparented, not copied.
Chris@64 87 //
Chris@64 88 // Any existing readers or builders pointing at the object are invalidated by this call (even if
Chris@64 89 // it doesn't move). You must call `get()` or `getReader()` again to get the new, valid pointer.
Chris@64 90
Chris@64 91 private:
Chris@64 92 _::OrphanBuilder builder;
Chris@64 93
Chris@64 94 template <typename, Kind>
Chris@64 95 friend struct _::PointerHelpers;
Chris@64 96 template <typename, Kind>
Chris@64 97 friend struct List;
Chris@64 98 template <typename U>
Chris@64 99 friend class Orphan;
Chris@64 100 friend class Orphanage;
Chris@64 101 friend class MessageBuilder;
Chris@64 102 };
Chris@64 103
Chris@64 104 class Orphanage: private kj::DisallowConstCopy {
Chris@64 105 // Use to directly allocate Orphan objects, without having a parent object allocate and then
Chris@64 106 // disown the object.
Chris@64 107
Chris@64 108 public:
Chris@64 109 inline Orphanage(): arena(nullptr) {}
Chris@64 110
Chris@64 111 template <typename BuilderType>
Chris@64 112 static Orphanage getForMessageContaining(BuilderType builder);
Chris@64 113 // Construct an Orphanage that allocates within the message containing the given Builder. This
Chris@64 114 // allows the constructed Orphans to be adopted by objects within said message.
Chris@64 115 //
Chris@64 116 // This constructor takes the builder rather than having the builder have a getOrphanage() method
Chris@64 117 // because this is an advanced feature and we don't want to pollute the builder APIs with it.
Chris@64 118 //
Chris@64 119 // Note that if you have a direct pointer to the `MessageBuilder`, you can simply call its
Chris@64 120 // `getOrphanage()` method.
Chris@64 121
Chris@64 122 template <typename RootType>
Chris@64 123 Orphan<RootType> newOrphan() const;
Chris@64 124 // Allocate a new orphaned struct.
Chris@64 125
Chris@64 126 template <typename RootType>
Chris@64 127 Orphan<RootType> newOrphan(uint size) const;
Chris@64 128 // Allocate a new orphaned list or blob.
Chris@64 129
Chris@64 130 Orphan<DynamicStruct> newOrphan(StructSchema schema) const;
Chris@64 131 // Dynamically create an orphan struct with the given schema. You must
Chris@64 132 // #include <capnp/dynamic.h> to use this.
Chris@64 133
Chris@64 134 Orphan<DynamicList> newOrphan(ListSchema schema, uint size) const;
Chris@64 135 // Dynamically create an orphan list with the given schema. You must #include <capnp/dynamic.h>
Chris@64 136 // to use this.
Chris@64 137
Chris@64 138 template <typename Reader>
Chris@64 139 Orphan<FromReader<Reader>> newOrphanCopy(Reader copyFrom) const;
Chris@64 140 // Allocate a new orphaned object (struct, list, or blob) and initialize it as a copy of the
Chris@64 141 // given object.
Chris@64 142
Chris@64 143 template <typename T>
Chris@64 144 Orphan<List<ListElementType<FromReader<T>>>> newOrphanConcat(kj::ArrayPtr<T> lists) const;
Chris@64 145 template <typename T>
Chris@64 146 Orphan<List<ListElementType<FromReader<T>>>> newOrphanConcat(kj::ArrayPtr<const T> lists) const;
Chris@64 147 // Given an array of List readers, copy and concatenate the lists, creating a new Orphan.
Chris@64 148 //
Chris@64 149 // Note that compared to allocating the list yourself and using `setWithCaveats()` to set each
Chris@64 150 // item, this method avoids the "caveats": the new list will be allocated with the element size
Chris@64 151 // being the maximum of that from all the input lists. This is particularly important when
Chris@64 152 // concatenating struct lists: if the lists were created using a newer version of the protocol
Chris@64 153 // in which some new fields had been added to the struct, using `setWithCaveats()` would
Chris@64 154 // truncate off those new fields.
Chris@64 155
Chris@64 156 Orphan<Data> referenceExternalData(Data::Reader data) const;
Chris@64 157 // Creates an Orphan<Data> that points at an existing region of memory (e.g. from another message)
Chris@64 158 // without copying it. There are some SEVERE restrictions on how this can be used:
Chris@64 159 // - The memory must remain valid until the `MessageBuilder` is destroyed (even if the orphan is
Chris@64 160 // abandoned).
Chris@64 161 // - Because the data is const, you will not be allowed to obtain a `Data::Builder`
Chris@64 162 // for this blob. Any call which would return such a builder will throw an exception. You
Chris@64 163 // can, however, obtain a Reader, e.g. via orphan.getReader() or from a parent Reader (once
Chris@64 164 // the orphan is adopted). It is your responsibility to make sure your code can deal with
Chris@64 165 // these problems when using this optimization; if you can't, allocate a copy instead.
Chris@64 166 // - `data.begin()` must be aligned to a machine word boundary (32-bit or 64-bit depending on
Chris@64 167 // the CPU). Any pointer returned by malloc() as well as any data blob obtained from another
Chris@64 168 // Cap'n Proto message satisfies this.
Chris@64 169 // - If `data.size()` is not a multiple of 8, extra bytes past data.end() up until the next 8-byte
Chris@64 170 // boundary will be visible in the raw message when it is written out. Thus, there must be no
Chris@64 171 // secrets in these bytes. Data blobs obtained from other Cap'n Proto messages should be safe
Chris@64 172 // as these bytes should be zero (unless the sender had the same problem).
Chris@64 173 //
Chris@64 174 // The array will actually become one of the message's segments. The data can thus be adopted
Chris@64 175 // into the message tree without copying it. This is particularly useful when referencing very
Chris@64 176 // large blobs, such as whole mmap'd files.
Chris@64 177
Chris@64 178 private:
Chris@64 179 _::BuilderArena* arena;
Chris@64 180 _::CapTableBuilder* capTable;
Chris@64 181
Chris@64 182 inline explicit Orphanage(_::BuilderArena* arena, _::CapTableBuilder* capTable)
Chris@64 183 : arena(arena), capTable(capTable) {}
Chris@64 184
Chris@64 185 template <typename T, Kind = CAPNP_KIND(T)>
Chris@64 186 struct GetInnerBuilder;
Chris@64 187 template <typename T, Kind = CAPNP_KIND(T)>
Chris@64 188 struct GetInnerReader;
Chris@64 189 template <typename T>
Chris@64 190 struct NewOrphanListImpl;
Chris@64 191
Chris@64 192 friend class MessageBuilder;
Chris@64 193 friend struct _::OrphanageInternal;
Chris@64 194 };
Chris@64 195
Chris@64 196 // =======================================================================================
Chris@64 197 // Inline implementation details.
Chris@64 198
Chris@64 199 namespace _ { // private
Chris@64 200
Chris@64 201 template <typename T, Kind = CAPNP_KIND(T)>
Chris@64 202 struct OrphanGetImpl;
Chris@64 203
Chris@64 204 template <typename T>
Chris@64 205 struct OrphanGetImpl<T, Kind::PRIMITIVE> {
Chris@64 206 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 207 builder.truncate(size, _::elementSizeForType<T>());
Chris@64 208 }
Chris@64 209 };
Chris@64 210
Chris@64 211 template <typename T>
Chris@64 212 struct OrphanGetImpl<T, Kind::STRUCT> {
Chris@64 213 static inline typename T::Builder apply(_::OrphanBuilder& builder) {
Chris@64 214 return typename T::Builder(builder.asStruct(_::structSize<T>()));
Chris@64 215 }
Chris@64 216 static inline typename T::Reader applyReader(const _::OrphanBuilder& builder) {
Chris@64 217 return typename T::Reader(builder.asStructReader(_::structSize<T>()));
Chris@64 218 }
Chris@64 219 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 220 builder.truncate(size, _::structSize<T>());
Chris@64 221 }
Chris@64 222 };
Chris@64 223
Chris@64 224 #if !CAPNP_LITE
Chris@64 225 template <typename T>
Chris@64 226 struct OrphanGetImpl<T, Kind::INTERFACE> {
Chris@64 227 static inline typename T::Client apply(_::OrphanBuilder& builder) {
Chris@64 228 return typename T::Client(builder.asCapability());
Chris@64 229 }
Chris@64 230 static inline typename T::Client applyReader(const _::OrphanBuilder& builder) {
Chris@64 231 return typename T::Client(builder.asCapability());
Chris@64 232 }
Chris@64 233 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 234 builder.truncate(size, ElementSize::POINTER);
Chris@64 235 }
Chris@64 236 };
Chris@64 237 #endif // !CAPNP_LITE
Chris@64 238
Chris@64 239 template <typename T, Kind k>
Chris@64 240 struct OrphanGetImpl<List<T, k>, Kind::LIST> {
Chris@64 241 static inline typename List<T>::Builder apply(_::OrphanBuilder& builder) {
Chris@64 242 return typename List<T>::Builder(builder.asList(_::ElementSizeForType<T>::value));
Chris@64 243 }
Chris@64 244 static inline typename List<T>::Reader applyReader(const _::OrphanBuilder& builder) {
Chris@64 245 return typename List<T>::Reader(builder.asListReader(_::ElementSizeForType<T>::value));
Chris@64 246 }
Chris@64 247 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 248 builder.truncate(size, ElementSize::POINTER);
Chris@64 249 }
Chris@64 250 };
Chris@64 251
Chris@64 252 template <typename T>
Chris@64 253 struct OrphanGetImpl<List<T, Kind::STRUCT>, Kind::LIST> {
Chris@64 254 static inline typename List<T>::Builder apply(_::OrphanBuilder& builder) {
Chris@64 255 return typename List<T>::Builder(builder.asStructList(_::structSize<T>()));
Chris@64 256 }
Chris@64 257 static inline typename List<T>::Reader applyReader(const _::OrphanBuilder& builder) {
Chris@64 258 return typename List<T>::Reader(builder.asListReader(_::ElementSizeForType<T>::value));
Chris@64 259 }
Chris@64 260 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 261 builder.truncate(size, ElementSize::POINTER);
Chris@64 262 }
Chris@64 263 };
Chris@64 264
Chris@64 265 template <>
Chris@64 266 struct OrphanGetImpl<Text, Kind::BLOB> {
Chris@64 267 static inline Text::Builder apply(_::OrphanBuilder& builder) {
Chris@64 268 return Text::Builder(builder.asText());
Chris@64 269 }
Chris@64 270 static inline Text::Reader applyReader(const _::OrphanBuilder& builder) {
Chris@64 271 return Text::Reader(builder.asTextReader());
Chris@64 272 }
Chris@64 273 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 274 builder.truncate(size, ElementSize::POINTER);
Chris@64 275 }
Chris@64 276 };
Chris@64 277
Chris@64 278 template <>
Chris@64 279 struct OrphanGetImpl<Data, Kind::BLOB> {
Chris@64 280 static inline Data::Builder apply(_::OrphanBuilder& builder) {
Chris@64 281 return Data::Builder(builder.asData());
Chris@64 282 }
Chris@64 283 static inline Data::Reader applyReader(const _::OrphanBuilder& builder) {
Chris@64 284 return Data::Reader(builder.asDataReader());
Chris@64 285 }
Chris@64 286 static inline void truncateListOf(_::OrphanBuilder& builder, ElementCount size) {
Chris@64 287 builder.truncate(size, ElementSize::POINTER);
Chris@64 288 }
Chris@64 289 };
Chris@64 290
Chris@64 291 struct OrphanageInternal {
Chris@64 292 static inline _::BuilderArena* getArena(Orphanage orphanage) { return orphanage.arena; }
Chris@64 293 static inline _::CapTableBuilder* getCapTable(Orphanage orphanage) { return orphanage.capTable; }
Chris@64 294 };
Chris@64 295
Chris@64 296 } // namespace _ (private)
Chris@64 297
Chris@64 298 template <typename T>
Chris@64 299 inline BuilderFor<T> Orphan<T>::get() {
Chris@64 300 return _::OrphanGetImpl<T>::apply(builder);
Chris@64 301 }
Chris@64 302
Chris@64 303 template <typename T>
Chris@64 304 inline ReaderFor<T> Orphan<T>::getReader() const {
Chris@64 305 return _::OrphanGetImpl<T>::applyReader(builder);
Chris@64 306 }
Chris@64 307
Chris@64 308 template <typename T>
Chris@64 309 inline void Orphan<T>::truncate(uint size) {
Chris@64 310 _::OrphanGetImpl<ListElementType<T>>::truncateListOf(builder, bounded(size) * ELEMENTS);
Chris@64 311 }
Chris@64 312
Chris@64 313 template <>
Chris@64 314 inline void Orphan<Text>::truncate(uint size) {
Chris@64 315 builder.truncateText(bounded(size) * ELEMENTS);
Chris@64 316 }
Chris@64 317
Chris@64 318 template <>
Chris@64 319 inline void Orphan<Data>::truncate(uint size) {
Chris@64 320 builder.truncate(bounded(size) * ELEMENTS, ElementSize::BYTE);
Chris@64 321 }
Chris@64 322
Chris@64 323 template <typename T>
Chris@64 324 struct Orphanage::GetInnerBuilder<T, Kind::STRUCT> {
Chris@64 325 static inline _::StructBuilder apply(typename T::Builder& t) {
Chris@64 326 return t._builder;
Chris@64 327 }
Chris@64 328 };
Chris@64 329
Chris@64 330 template <typename T>
Chris@64 331 struct Orphanage::GetInnerBuilder<T, Kind::LIST> {
Chris@64 332 static inline _::ListBuilder apply(typename T::Builder& t) {
Chris@64 333 return t.builder;
Chris@64 334 }
Chris@64 335 };
Chris@64 336
Chris@64 337 template <typename BuilderType>
Chris@64 338 Orphanage Orphanage::getForMessageContaining(BuilderType builder) {
Chris@64 339 auto inner = GetInnerBuilder<FromBuilder<BuilderType>>::apply(builder);
Chris@64 340 return Orphanage(inner.getArena(), inner.getCapTable());
Chris@64 341 }
Chris@64 342
Chris@64 343 template <typename RootType>
Chris@64 344 Orphan<RootType> Orphanage::newOrphan() const {
Chris@64 345 return Orphan<RootType>(_::OrphanBuilder::initStruct(arena, capTable, _::structSize<RootType>()));
Chris@64 346 }
Chris@64 347
Chris@64 348 template <typename T, Kind k>
Chris@64 349 struct Orphanage::NewOrphanListImpl<List<T, k>> {
Chris@64 350 static inline _::OrphanBuilder apply(
Chris@64 351 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
Chris@64 352 return _::OrphanBuilder::initList(
Chris@64 353 arena, capTable, bounded(size) * ELEMENTS, _::ElementSizeForType<T>::value);
Chris@64 354 }
Chris@64 355 };
Chris@64 356
Chris@64 357 template <typename T>
Chris@64 358 struct Orphanage::NewOrphanListImpl<List<T, Kind::STRUCT>> {
Chris@64 359 static inline _::OrphanBuilder apply(
Chris@64 360 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
Chris@64 361 return _::OrphanBuilder::initStructList(
Chris@64 362 arena, capTable, bounded(size) * ELEMENTS, _::structSize<T>());
Chris@64 363 }
Chris@64 364 };
Chris@64 365
Chris@64 366 template <>
Chris@64 367 struct Orphanage::NewOrphanListImpl<Text> {
Chris@64 368 static inline _::OrphanBuilder apply(
Chris@64 369 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
Chris@64 370 return _::OrphanBuilder::initText(arena, capTable, bounded(size) * BYTES);
Chris@64 371 }
Chris@64 372 };
Chris@64 373
Chris@64 374 template <>
Chris@64 375 struct Orphanage::NewOrphanListImpl<Data> {
Chris@64 376 static inline _::OrphanBuilder apply(
Chris@64 377 _::BuilderArena* arena, _::CapTableBuilder* capTable, uint size) {
Chris@64 378 return _::OrphanBuilder::initData(arena, capTable, bounded(size) * BYTES);
Chris@64 379 }
Chris@64 380 };
Chris@64 381
Chris@64 382 template <typename RootType>
Chris@64 383 Orphan<RootType> Orphanage::newOrphan(uint size) const {
Chris@64 384 return Orphan<RootType>(NewOrphanListImpl<RootType>::apply(arena, capTable, size));
Chris@64 385 }
Chris@64 386
Chris@64 387 template <typename T>
Chris@64 388 struct Orphanage::GetInnerReader<T, Kind::STRUCT> {
Chris@64 389 static inline _::StructReader apply(const typename T::Reader& t) {
Chris@64 390 return t._reader;
Chris@64 391 }
Chris@64 392 };
Chris@64 393
Chris@64 394 template <typename T>
Chris@64 395 struct Orphanage::GetInnerReader<T, Kind::LIST> {
Chris@64 396 static inline _::ListReader apply(const typename T::Reader& t) {
Chris@64 397 return t.reader;
Chris@64 398 }
Chris@64 399 };
Chris@64 400
Chris@64 401 template <typename T>
Chris@64 402 struct Orphanage::GetInnerReader<T, Kind::BLOB> {
Chris@64 403 static inline const typename T::Reader& apply(const typename T::Reader& t) {
Chris@64 404 return t;
Chris@64 405 }
Chris@64 406 };
Chris@64 407
Chris@64 408 template <typename Reader>
Chris@64 409 inline Orphan<FromReader<Reader>> Orphanage::newOrphanCopy(Reader copyFrom) const {
Chris@64 410 return Orphan<FromReader<Reader>>(_::OrphanBuilder::copy(
Chris@64 411 arena, capTable, GetInnerReader<FromReader<Reader>>::apply(copyFrom)));
Chris@64 412 }
Chris@64 413
Chris@64 414 template <typename T>
Chris@64 415 inline Orphan<List<ListElementType<FromReader<T>>>>
Chris@64 416 Orphanage::newOrphanConcat(kj::ArrayPtr<T> lists) const {
Chris@64 417 return newOrphanConcat(kj::implicitCast<kj::ArrayPtr<const T>>(lists));
Chris@64 418 }
Chris@64 419 template <typename T>
Chris@64 420 inline Orphan<List<ListElementType<FromReader<T>>>>
Chris@64 421 Orphanage::newOrphanConcat(kj::ArrayPtr<const T> lists) const {
Chris@64 422 // Optimization / simplification: Rely on List<T>::Reader containing nothing except a
Chris@64 423 // _::ListReader.
Chris@64 424 static_assert(sizeof(T) == sizeof(_::ListReader), "lists are not bare readers?");
Chris@64 425 kj::ArrayPtr<const _::ListReader> raw(
Chris@64 426 reinterpret_cast<const _::ListReader*>(lists.begin()), lists.size());
Chris@64 427 typedef ListElementType<FromReader<T>> Element;
Chris@64 428 return Orphan<List<Element>>(
Chris@64 429 _::OrphanBuilder::concat(arena, capTable,
Chris@64 430 _::elementSizeForType<Element>(),
Chris@64 431 _::minStructSizeForElement<Element>(), raw));
Chris@64 432 }
Chris@64 433
Chris@64 434 inline Orphan<Data> Orphanage::referenceExternalData(Data::Reader data) const {
Chris@64 435 return Orphan<Data>(_::OrphanBuilder::referenceExternalData(arena, data));
Chris@64 436 }
Chris@64 437
Chris@64 438 } // namespace capnp
Chris@64 439
Chris@64 440 #endif // CAPNP_ORPHAN_H_