| 1 | #include "engine/shared/snapshot.h" |
| 2 | #include "generated/protocolglue.h" |
| 3 | #include <array> |
| 4 | #include <cassert> |
| 5 | #include <cstddef> |
| 6 | #include <cstdint> |
| 7 | #include <iterator> |
| 8 | #include <memory> |
| 9 | #include <new> |
| 10 | #include <stdexcept> |
| 11 | #include <type_traits> |
| 12 | #include <utility> |
| 13 | #if __cplusplus >= 202002L |
| 14 | #include <ranges> |
| 15 | #endif |
| 16 | |
| 17 | #ifdef __GNUC__ |
| 18 | #pragma GCC diagnostic ignored "-Wmissing-declarations" |
| 19 | #ifdef __clang__ |
| 20 | #pragma clang diagnostic ignored "-Wdollar-in-identifier-extension" |
| 21 | #endif // __clang__ |
| 22 | #endif // __GNUC__ |
| 23 | |
| 24 | namespace rust { |
| 25 | inline namespace cxxbridge1 { |
| 26 | // #include "rust/cxx.h" |
| 27 | |
| 28 | #ifndef CXXBRIDGE1_PANIC |
| 29 | #define CXXBRIDGE1_PANIC |
| 30 | template <typename Exception> |
| 31 | void panic [[noreturn]] (const char *msg); |
| 32 | #endif // CXXBRIDGE1_PANIC |
| 33 | |
| 34 | namespace { |
| 35 | template <typename T> |
| 36 | class impl; |
| 37 | } // namespace |
| 38 | |
| 39 | class Opaque; |
| 40 | |
| 41 | template <typename T> |
| 42 | ::std::size_t size_of(); |
| 43 | template <typename T> |
| 44 | ::std::size_t align_of(); |
| 45 | |
| 46 | #ifndef CXXBRIDGE1_RUST_SLICE |
| 47 | #define CXXBRIDGE1_RUST_SLICE |
| 48 | namespace detail { |
| 49 | template <bool> |
| 50 | struct copy_assignable_if {}; |
| 51 | |
| 52 | template <> |
| 53 | struct copy_assignable_if<false> { |
| 54 | copy_assignable_if() noexcept = default; |
| 55 | copy_assignable_if(const copy_assignable_if &) noexcept = default; |
| 56 | copy_assignable_if &operator=(const copy_assignable_if &) & noexcept = delete; |
| 57 | copy_assignable_if &operator=(copy_assignable_if &&) & noexcept = default; |
| 58 | }; |
| 59 | } // namespace detail |
| 60 | |
| 61 | template <typename T> |
| 62 | class Slice final |
| 63 | : private detail::copy_assignable_if<std::is_const<T>::value> { |
| 64 | public: |
| 65 | using value_type = T; |
| 66 | |
| 67 | Slice() noexcept; |
| 68 | Slice(T *, std::size_t count) noexcept; |
| 69 | |
| 70 | template <typename C> |
| 71 | explicit Slice(C &c) : Slice(c.data(), c.size()) {} |
| 72 | |
| 73 | Slice &operator=(const Slice<T> &) & noexcept = default; |
| 74 | Slice &operator=(Slice<T> &&) & noexcept = default; |
| 75 | |
| 76 | T *data() const noexcept; |
| 77 | std::size_t size() const noexcept; |
| 78 | std::size_t length() const noexcept; |
| 79 | bool empty() const noexcept; |
| 80 | |
| 81 | T &operator[](std::size_t n) const noexcept; |
| 82 | T &at(std::size_t n) const; |
| 83 | T &front() const noexcept; |
| 84 | T &back() const noexcept; |
| 85 | |
| 86 | Slice(const Slice<T> &) noexcept = default; |
| 87 | ~Slice() noexcept = default; |
| 88 | |
| 89 | class iterator; |
| 90 | iterator begin() const noexcept; |
| 91 | iterator end() const noexcept; |
| 92 | |
| 93 | void swap(Slice &) noexcept; |
| 94 | |
| 95 | private: |
| 96 | class uninit; |
| 97 | Slice(uninit) noexcept; |
| 98 | friend impl<Slice>; |
| 99 | friend void sliceInit(void *, const void *, std::size_t) noexcept; |
| 100 | friend void *slicePtr(const void *) noexcept; |
| 101 | friend std::size_t sliceLen(const void *) noexcept; |
| 102 | |
| 103 | std::array<std::uintptr_t, 2> repr; |
| 104 | }; |
| 105 | |
| 106 | #ifdef __cpp_deduction_guides |
| 107 | template <typename C> |
| 108 | explicit Slice(C &c) |
| 109 | -> Slice<std::remove_reference_t<decltype(*std::declval<C>().data())>>; |
| 110 | #endif // __cpp_deduction_guides |
| 111 | |
| 112 | template <typename T> |
| 113 | class Slice<T>::iterator final { |
| 114 | public: |
| 115 | #if __cplusplus >= 202002L |
| 116 | using iterator_category = std::contiguous_iterator_tag; |
| 117 | #else |
| 118 | using iterator_category = std::random_access_iterator_tag; |
| 119 | #endif |
| 120 | using value_type = T; |
| 121 | using difference_type = std::ptrdiff_t; |
| 122 | using pointer = typename std::add_pointer<T>::type; |
| 123 | using reference = typename std::add_lvalue_reference<T>::type; |
| 124 | |
| 125 | reference operator*() const noexcept; |
| 126 | pointer operator->() const noexcept; |
| 127 | reference operator[](difference_type) const noexcept; |
| 128 | |
| 129 | iterator &operator++() noexcept; |
| 130 | iterator operator++(int) noexcept; |
| 131 | iterator &operator--() noexcept; |
| 132 | iterator operator--(int) noexcept; |
| 133 | |
| 134 | iterator &operator+=(difference_type) noexcept; |
| 135 | iterator &operator-=(difference_type) noexcept; |
| 136 | iterator operator+(difference_type) const noexcept; |
| 137 | friend inline iterator operator+(difference_type lhs, iterator rhs) noexcept { |
| 138 | return rhs + lhs; |
| 139 | } |
| 140 | iterator operator-(difference_type) const noexcept; |
| 141 | difference_type operator-(const iterator &) const noexcept; |
| 142 | |
| 143 | bool operator==(const iterator &) const noexcept; |
| 144 | bool operator!=(const iterator &) const noexcept; |
| 145 | bool operator<(const iterator &) const noexcept; |
| 146 | bool operator<=(const iterator &) const noexcept; |
| 147 | bool operator>(const iterator &) const noexcept; |
| 148 | bool operator>=(const iterator &) const noexcept; |
| 149 | |
| 150 | private: |
| 151 | friend class Slice; |
| 152 | void *pos; |
| 153 | std::size_t stride; |
| 154 | }; |
| 155 | |
| 156 | #if __cplusplus >= 202002L |
| 157 | static_assert(std::ranges::contiguous_range<rust::Slice<const uint8_t>>); |
| 158 | static_assert(std::contiguous_iterator<rust::Slice<const uint8_t>::iterator>); |
| 159 | #endif |
| 160 | |
| 161 | template <typename T> |
| 162 | Slice<T>::Slice() noexcept { |
| 163 | sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0); |
| 164 | } |
| 165 | |
| 166 | template <typename T> |
| 167 | Slice<T>::Slice(T *s, std::size_t count) noexcept { |
| 168 | assert(s != nullptr || count == 0); |
| 169 | sliceInit(this, |
| 170 | s == nullptr && count == 0 |
| 171 | ? reinterpret_cast<void *>(align_of<T>()) |
| 172 | : const_cast<typename std::remove_const<T>::type *>(s), |
| 173 | count); |
| 174 | } |
| 175 | |
| 176 | template <typename T> |
| 177 | T *Slice<T>::data() const noexcept { |
| 178 | return reinterpret_cast<T *>(slicePtr(this)); |
| 179 | } |
| 180 | |
| 181 | template <typename T> |
| 182 | std::size_t Slice<T>::size() const noexcept { |
| 183 | return sliceLen(this); |
| 184 | } |
| 185 | |
| 186 | template <typename T> |
| 187 | std::size_t Slice<T>::length() const noexcept { |
| 188 | return this->size(); |
| 189 | } |
| 190 | |
| 191 | template <typename T> |
| 192 | bool Slice<T>::empty() const noexcept { |
| 193 | return this->size() == 0; |
| 194 | } |
| 195 | |
| 196 | template <typename T> |
| 197 | T &Slice<T>::operator[](std::size_t n) const noexcept { |
| 198 | assert(n < this->size()); |
| 199 | auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n; |
| 200 | return *reinterpret_cast<T *>(ptr); |
| 201 | } |
| 202 | |
| 203 | template <typename T> |
| 204 | T &Slice<T>::at(std::size_t n) const { |
| 205 | if (n >= this->size()) { |
| 206 | panic<std::out_of_range>("rust::Slice index out of range" ); |
| 207 | } |
| 208 | return (*this)[n]; |
| 209 | } |
| 210 | |
| 211 | template <typename T> |
| 212 | T &Slice<T>::front() const noexcept { |
| 213 | assert(!this->empty()); |
| 214 | return (*this)[0]; |
| 215 | } |
| 216 | |
| 217 | template <typename T> |
| 218 | T &Slice<T>::back() const noexcept { |
| 219 | assert(!this->empty()); |
| 220 | return (*this)[this->size() - 1]; |
| 221 | } |
| 222 | |
| 223 | template <typename T> |
| 224 | typename Slice<T>::iterator::reference |
| 225 | Slice<T>::iterator::operator*() const noexcept { |
| 226 | return *static_cast<T *>(this->pos); |
| 227 | } |
| 228 | |
| 229 | template <typename T> |
| 230 | typename Slice<T>::iterator::pointer |
| 231 | Slice<T>::iterator::operator->() const noexcept { |
| 232 | return static_cast<T *>(this->pos); |
| 233 | } |
| 234 | |
| 235 | template <typename T> |
| 236 | typename Slice<T>::iterator::reference Slice<T>::iterator::operator[]( |
| 237 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 238 | auto ptr = static_cast<char *>(this->pos) + this->stride * n; |
| 239 | return *reinterpret_cast<T *>(ptr); |
| 240 | } |
| 241 | |
| 242 | template <typename T> |
| 243 | typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept { |
| 244 | this->pos = static_cast<char *>(this->pos) + this->stride; |
| 245 | return *this; |
| 246 | } |
| 247 | |
| 248 | template <typename T> |
| 249 | typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept { |
| 250 | auto ret = iterator(*this); |
| 251 | this->pos = static_cast<char *>(this->pos) + this->stride; |
| 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | template <typename T> |
| 256 | typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept { |
| 257 | this->pos = static_cast<char *>(this->pos) - this->stride; |
| 258 | return *this; |
| 259 | } |
| 260 | |
| 261 | template <typename T> |
| 262 | typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept { |
| 263 | auto ret = iterator(*this); |
| 264 | this->pos = static_cast<char *>(this->pos) - this->stride; |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | template <typename T> |
| 269 | typename Slice<T>::iterator &Slice<T>::iterator::operator+=( |
| 270 | typename Slice<T>::iterator::difference_type n) noexcept { |
| 271 | this->pos = static_cast<char *>(this->pos) + this->stride * n; |
| 272 | return *this; |
| 273 | } |
| 274 | |
| 275 | template <typename T> |
| 276 | typename Slice<T>::iterator &Slice<T>::iterator::operator-=( |
| 277 | typename Slice<T>::iterator::difference_type n) noexcept { |
| 278 | this->pos = static_cast<char *>(this->pos) - this->stride * n; |
| 279 | return *this; |
| 280 | } |
| 281 | |
| 282 | template <typename T> |
| 283 | typename Slice<T>::iterator Slice<T>::iterator::operator+( |
| 284 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 285 | auto ret = iterator(*this); |
| 286 | ret.pos = static_cast<char *>(this->pos) + this->stride * n; |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | template <typename T> |
| 291 | typename Slice<T>::iterator Slice<T>::iterator::operator-( |
| 292 | typename Slice<T>::iterator::difference_type n) const noexcept { |
| 293 | auto ret = iterator(*this); |
| 294 | ret.pos = static_cast<char *>(this->pos) - this->stride * n; |
| 295 | return ret; |
| 296 | } |
| 297 | |
| 298 | template <typename T> |
| 299 | typename Slice<T>::iterator::difference_type |
| 300 | Slice<T>::iterator::operator-(const iterator &other) const noexcept { |
| 301 | auto diff = std::distance(static_cast<char *>(other.pos), |
| 302 | static_cast<char *>(this->pos)); |
| 303 | return diff / static_cast<typename Slice<T>::iterator::difference_type>( |
| 304 | this->stride); |
| 305 | } |
| 306 | |
| 307 | template <typename T> |
| 308 | bool Slice<T>::iterator::operator==(const iterator &other) const noexcept { |
| 309 | return this->pos == other.pos; |
| 310 | } |
| 311 | |
| 312 | template <typename T> |
| 313 | bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept { |
| 314 | return this->pos != other.pos; |
| 315 | } |
| 316 | |
| 317 | template <typename T> |
| 318 | bool Slice<T>::iterator::operator<(const iterator &other) const noexcept { |
| 319 | return this->pos < other.pos; |
| 320 | } |
| 321 | |
| 322 | template <typename T> |
| 323 | bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept { |
| 324 | return this->pos <= other.pos; |
| 325 | } |
| 326 | |
| 327 | template <typename T> |
| 328 | bool Slice<T>::iterator::operator>(const iterator &other) const noexcept { |
| 329 | return this->pos > other.pos; |
| 330 | } |
| 331 | |
| 332 | template <typename T> |
| 333 | bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept { |
| 334 | return this->pos >= other.pos; |
| 335 | } |
| 336 | |
| 337 | template <typename T> |
| 338 | typename Slice<T>::iterator Slice<T>::begin() const noexcept { |
| 339 | iterator it; |
| 340 | it.pos = slicePtr(this); |
| 341 | it.stride = size_of<T>(); |
| 342 | return it; |
| 343 | } |
| 344 | |
| 345 | template <typename T> |
| 346 | typename Slice<T>::iterator Slice<T>::end() const noexcept { |
| 347 | iterator it = this->begin(); |
| 348 | it.pos = static_cast<char *>(it.pos) + it.stride * this->size(); |
| 349 | return it; |
| 350 | } |
| 351 | |
| 352 | template <typename T> |
| 353 | void Slice<T>::swap(Slice &rhs) noexcept { |
| 354 | std::swap(*this, rhs); |
| 355 | } |
| 356 | #endif // CXXBRIDGE1_RUST_SLICE |
| 357 | |
| 358 | #ifndef CXXBRIDGE1_IS_COMPLETE |
| 359 | #define CXXBRIDGE1_IS_COMPLETE |
| 360 | namespace detail { |
| 361 | namespace { |
| 362 | template <typename T, typename = std::size_t> |
| 363 | struct is_complete : std::false_type {}; |
| 364 | template <typename T> |
| 365 | struct is_complete<T, decltype(sizeof(T))> : std::true_type {}; |
| 366 | } // namespace |
| 367 | } // namespace detail |
| 368 | #endif // CXXBRIDGE1_IS_COMPLETE |
| 369 | |
| 370 | #ifndef CXXBRIDGE1_LAYOUT |
| 371 | #define CXXBRIDGE1_LAYOUT |
| 372 | class layout { |
| 373 | template <typename T> |
| 374 | friend std::size_t size_of(); |
| 375 | template <typename T> |
| 376 | friend std::size_t align_of(); |
| 377 | template <typename T> |
| 378 | static typename std::enable_if<std::is_base_of<Opaque, T>::value, |
| 379 | std::size_t>::type |
| 380 | do_size_of() { |
| 381 | return T::layout::size(); |
| 382 | } |
| 383 | template <typename T> |
| 384 | static typename std::enable_if<!std::is_base_of<Opaque, T>::value, |
| 385 | std::size_t>::type |
| 386 | do_size_of() { |
| 387 | return sizeof(T); |
| 388 | } |
| 389 | template <typename T> |
| 390 | static |
| 391 | typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type |
| 392 | size_of() { |
| 393 | return do_size_of<T>(); |
| 394 | } |
| 395 | template <typename T> |
| 396 | static typename std::enable_if<std::is_base_of<Opaque, T>::value, |
| 397 | std::size_t>::type |
| 398 | do_align_of() { |
| 399 | return T::layout::align(); |
| 400 | } |
| 401 | template <typename T> |
| 402 | static typename std::enable_if<!std::is_base_of<Opaque, T>::value, |
| 403 | std::size_t>::type |
| 404 | do_align_of() { |
| 405 | return alignof(T); |
| 406 | } |
| 407 | template <typename T> |
| 408 | static |
| 409 | typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type |
| 410 | align_of() { |
| 411 | return do_align_of<T>(); |
| 412 | } |
| 413 | }; |
| 414 | |
| 415 | template <typename T> |
| 416 | std::size_t size_of() { |
| 417 | return layout::size_of<T>(); |
| 418 | } |
| 419 | |
| 420 | template <typename T> |
| 421 | std::size_t align_of() { |
| 422 | return layout::align_of<T>(); |
| 423 | } |
| 424 | #endif // CXXBRIDGE1_LAYOUT |
| 425 | |
| 426 | namespace { |
| 427 | template <bool> struct deleter_if { |
| 428 | template <typename T> void operator()(T *) {} |
| 429 | }; |
| 430 | template <> struct deleter_if<true> { |
| 431 | template <typename T> void operator()(T *ptr) { ptr->~T(); } |
| 432 | }; |
| 433 | } // namespace |
| 434 | } // namespace cxxbridge1 |
| 435 | } // namespace rust |
| 436 | |
| 437 | using CSnapshot = ::CSnapshot; |
| 438 | using CSnapshotBuffer = ::CSnapshotBuffer; |
| 439 | |
| 440 | extern "C" { |
| 441 | ::CSnapshotBuffer *cxxbridge1$194$CSnapshotBuffer$New() noexcept { |
| 442 | ::std::unique_ptr<::CSnapshotBuffer> (*New$)() = &::CSnapshotBuffer::New; |
| 443 | return New$().release(); |
| 444 | } |
| 445 | |
| 446 | void cxxbridge1$194$CSnapshot$AsSlice(::CSnapshot const &self, ::rust::Slice<::std::int32_t const> *return$) noexcept { |
| 447 | ::rust::Slice<::std::int32_t const> (::CSnapshot::*AsSlice$)() const = &::CSnapshot::AsSlice; |
| 448 | new (return$) ::rust::Slice<::std::int32_t const>((self.*AsSlice$)()); |
| 449 | } |
| 450 | |
| 451 | void cxxbridge1$194$CSnapshotBuffer$AsMutSlice(::CSnapshotBuffer &self, ::rust::Slice<::std::int32_t > *return$) noexcept { |
| 452 | ::rust::Slice<::std::int32_t > (::CSnapshotBuffer::*AsMutSlice$)() = &::CSnapshotBuffer::AsMutSlice; |
| 453 | new (return$) ::rust::Slice<::std::int32_t >((self.*AsMutSlice$)()); |
| 454 | } |
| 455 | |
| 456 | ::std::int32_t cxxbridge1$194$Obj_SixToSeven(::std::int32_t type_) noexcept { |
| 457 | ::std::int32_t (*Obj_SixToSeven$)(::std::int32_t) = ::Obj_SixToSeven; |
| 458 | return Obj_SixToSeven$(type_); |
| 459 | } |
| 460 | |
| 461 | static_assert(::rust::detail::is_complete<::std::remove_extent<::CSnapshotBuffer>::type>::value, "definition of `::CSnapshotBuffer` is required" ); |
| 462 | static_assert(sizeof(::std::unique_ptr<::CSnapshotBuffer>) == sizeof(void *), "" ); |
| 463 | static_assert(alignof(::std::unique_ptr<::CSnapshotBuffer>) == alignof(void *), "" ); |
| 464 | void cxxbridge1$unique_ptr$CSnapshotBuffer$null(::std::unique_ptr<::CSnapshotBuffer> *ptr) noexcept { |
| 465 | ::new (ptr) ::std::unique_ptr<::CSnapshotBuffer>(); |
| 466 | } |
| 467 | void cxxbridge1$unique_ptr$CSnapshotBuffer$raw(::std::unique_ptr<::CSnapshotBuffer> *ptr, ::std::unique_ptr<::CSnapshotBuffer>::pointer raw) noexcept { |
| 468 | ::new (ptr) ::std::unique_ptr<::CSnapshotBuffer>(raw); |
| 469 | } |
| 470 | ::std::unique_ptr<::CSnapshotBuffer>::element_type const *cxxbridge1$unique_ptr$CSnapshotBuffer$get(::std::unique_ptr<::CSnapshotBuffer> const &ptr) noexcept { |
| 471 | return ptr.get(); |
| 472 | } |
| 473 | ::std::unique_ptr<::CSnapshotBuffer>::pointer cxxbridge1$unique_ptr$CSnapshotBuffer$release(::std::unique_ptr<::CSnapshotBuffer> &ptr) noexcept { |
| 474 | return ptr.release(); |
| 475 | } |
| 476 | void cxxbridge1$unique_ptr$CSnapshotBuffer$drop(::std::unique_ptr<::CSnapshotBuffer> *ptr) noexcept { |
| 477 | ::rust::deleter_if<::rust::detail::is_complete<::CSnapshotBuffer>::value>{}(ptr); |
| 478 | } |
| 479 | } // extern "C" |
| 480 | |