1#include "engine/shared/snapshot.h"
2#include <array>
3#include <cassert>
4#include <cstddef>
5#include <cstdint>
6#include <iterator>
7#include <new>
8#include <stdexcept>
9#include <type_traits>
10#include <utility>
11
12namespace rust {
13inline namespace cxxbridge1 {
14// #include "rust/cxx.h"
15
16#ifndef CXXBRIDGE1_PANIC
17#define CXXBRIDGE1_PANIC
18template <typename Exception>
19void panic [[noreturn]] (const char *msg);
20#endif // CXXBRIDGE1_PANIC
21
22namespace {
23template <typename T>
24class impl;
25} // namespace
26
27template <typename T>
28::std::size_t size_of();
29template <typename T>
30::std::size_t align_of();
31
32#ifndef CXXBRIDGE1_RUST_SLICE
33#define CXXBRIDGE1_RUST_SLICE
34namespace detail {
35template <bool>
36struct copy_assignable_if {};
37
38template <>
39struct copy_assignable_if<false> {
40 copy_assignable_if() noexcept = default;
41 copy_assignable_if(const copy_assignable_if &) noexcept = default;
42 copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete;
43 copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default;
44};
45} // namespace detail
46
47template <typename T>
48class Slice final
49 : private detail::copy_assignable_if<std::is_const<T>::value> {
50public:
51 using value_type = T;
52
53 Slice() noexcept;
54 Slice(T *, std::size_t count) noexcept;
55
56 Slice &operator=(const Slice<T> &) &noexcept = default;
57 Slice &operator=(Slice<T> &&) &noexcept = default;
58
59 T *data() const noexcept;
60 std::size_t size() const noexcept;
61 std::size_t length() const noexcept;
62 bool empty() const noexcept;
63
64 T &operator[](std::size_t n) const noexcept;
65 T &at(std::size_t n) const;
66 T &front() const noexcept;
67 T &back() const noexcept;
68
69 Slice(const Slice<T> &) noexcept = default;
70 ~Slice() noexcept = default;
71
72 class iterator;
73 iterator begin() const noexcept;
74 iterator end() const noexcept;
75
76 void swap(Slice &) noexcept;
77
78private:
79 class uninit;
80 Slice(uninit) noexcept;
81 friend impl<Slice>;
82 friend void sliceInit(void *, const void *, std::size_t) noexcept;
83 friend void *slicePtr(const void *) noexcept;
84 friend std::size_t sliceLen(const void *) noexcept;
85
86 std::array<std::uintptr_t, 2> repr;
87};
88
89template <typename T>
90class Slice<T>::iterator final {
91public:
92 using iterator_category = std::random_access_iterator_tag;
93 using value_type = T;
94 using difference_type = std::ptrdiff_t;
95 using pointer = typename std::add_pointer<T>::type;
96 using reference = typename std::add_lvalue_reference<T>::type;
97
98 reference operator*() const noexcept;
99 pointer operator->() const noexcept;
100 reference operator[](difference_type) const noexcept;
101
102 iterator &operator++() noexcept;
103 iterator operator++(int) noexcept;
104 iterator &operator--() noexcept;
105 iterator operator--(int) noexcept;
106
107 iterator &operator+=(difference_type) noexcept;
108 iterator &operator-=(difference_type) noexcept;
109 iterator operator+(difference_type) const noexcept;
110 iterator operator-(difference_type) const noexcept;
111 difference_type operator-(const iterator &) const noexcept;
112
113 bool operator==(const iterator &) const noexcept;
114 bool operator!=(const iterator &) const noexcept;
115 bool operator<(const iterator &) const noexcept;
116 bool operator<=(const iterator &) const noexcept;
117 bool operator>(const iterator &) const noexcept;
118 bool operator>=(const iterator &) const noexcept;
119
120private:
121 friend class Slice;
122 void *pos;
123 std::size_t stride;
124};
125
126template <typename T>
127Slice<T>::Slice() noexcept {
128 sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0);
129}
130
131template <typename T>
132Slice<T>::Slice(T *s, std::size_t count) noexcept {
133 assert(s != nullptr || count == 0);
134 sliceInit(this,
135 s == nullptr && count == 0
136 ? reinterpret_cast<void *>(align_of<T>())
137 : const_cast<typename std::remove_const<T>::type *>(s),
138 count);
139}
140
141template <typename T>
142T *Slice<T>::data() const noexcept {
143 return reinterpret_cast<T *>(slicePtr(this));
144}
145
146template <typename T>
147std::size_t Slice<T>::size() const noexcept {
148 return sliceLen(this);
149}
150
151template <typename T>
152std::size_t Slice<T>::length() const noexcept {
153 return this->size();
154}
155
156template <typename T>
157bool Slice<T>::empty() const noexcept {
158 return this->size() == 0;
159}
160
161template <typename T>
162T &Slice<T>::operator[](std::size_t n) const noexcept {
163 assert(n < this->size());
164 auto ptr = static_cast<char *>(slicePtr(this)) + size_of<T>() * n;
165 return *reinterpret_cast<T *>(ptr);
166}
167
168template <typename T>
169T &Slice<T>::at(std::size_t n) const {
170 if (n >= this->size()) {
171 panic<std::out_of_range>("rust::Slice index out of range");
172 }
173 return (*this)[n];
174}
175
176template <typename T>
177T &Slice<T>::front() const noexcept {
178 assert(!this->empty());
179 return (*this)[0];
180}
181
182template <typename T>
183T &Slice<T>::back() const noexcept {
184 assert(!this->empty());
185 return (*this)[this->size() - 1];
186}
187
188template <typename T>
189typename Slice<T>::iterator::reference
190Slice<T>::iterator::operator*() const noexcept {
191 return *static_cast<T *>(this->pos);
192}
193
194template <typename T>
195typename Slice<T>::iterator::pointer
196Slice<T>::iterator::operator->() const noexcept {
197 return static_cast<T *>(this->pos);
198}
199
200template <typename T>
201typename Slice<T>::iterator::reference Slice<T>::iterator::operator[](
202 typename Slice<T>::iterator::difference_type n) const noexcept {
203 auto ptr = static_cast<char *>(this->pos) + this->stride * n;
204 return *reinterpret_cast<T *>(ptr);
205}
206
207template <typename T>
208typename Slice<T>::iterator &Slice<T>::iterator::operator++() noexcept {
209 this->pos = static_cast<char *>(this->pos) + this->stride;
210 return *this;
211}
212
213template <typename T>
214typename Slice<T>::iterator Slice<T>::iterator::operator++(int) noexcept {
215 auto ret = iterator(*this);
216 this->pos = static_cast<char *>(this->pos) + this->stride;
217 return ret;
218}
219
220template <typename T>
221typename Slice<T>::iterator &Slice<T>::iterator::operator--() noexcept {
222 this->pos = static_cast<char *>(this->pos) - this->stride;
223 return *this;
224}
225
226template <typename T>
227typename Slice<T>::iterator Slice<T>::iterator::operator--(int) noexcept {
228 auto ret = iterator(*this);
229 this->pos = static_cast<char *>(this->pos) - this->stride;
230 return ret;
231}
232
233template <typename T>
234typename Slice<T>::iterator &Slice<T>::iterator::operator+=(
235 typename Slice<T>::iterator::difference_type n) noexcept {
236 this->pos = static_cast<char *>(this->pos) + this->stride * n;
237 return *this;
238}
239
240template <typename T>
241typename Slice<T>::iterator &Slice<T>::iterator::operator-=(
242 typename Slice<T>::iterator::difference_type n) noexcept {
243 this->pos = static_cast<char *>(this->pos) - this->stride * n;
244 return *this;
245}
246
247template <typename T>
248typename Slice<T>::iterator Slice<T>::iterator::operator+(
249 typename Slice<T>::iterator::difference_type n) const noexcept {
250 auto ret = iterator(*this);
251 ret.pos = static_cast<char *>(this->pos) + this->stride * n;
252 return ret;
253}
254
255template <typename T>
256typename Slice<T>::iterator Slice<T>::iterator::operator-(
257 typename Slice<T>::iterator::difference_type n) const noexcept {
258 auto ret = iterator(*this);
259 ret.pos = static_cast<char *>(this->pos) - this->stride * n;
260 return ret;
261}
262
263template <typename T>
264typename Slice<T>::iterator::difference_type
265Slice<T>::iterator::operator-(const iterator &other) const noexcept {
266 auto diff = std::distance(static_cast<char *>(other.pos),
267 static_cast<char *>(this->pos));
268 return diff / this->stride;
269}
270
271template <typename T>
272bool Slice<T>::iterator::operator==(const iterator &other) const noexcept {
273 return this->pos == other.pos;
274}
275
276template <typename T>
277bool Slice<T>::iterator::operator!=(const iterator &other) const noexcept {
278 return this->pos != other.pos;
279}
280
281template <typename T>
282bool Slice<T>::iterator::operator<(const iterator &other) const noexcept {
283 return this->pos < other.pos;
284}
285
286template <typename T>
287bool Slice<T>::iterator::operator<=(const iterator &other) const noexcept {
288 return this->pos <= other.pos;
289}
290
291template <typename T>
292bool Slice<T>::iterator::operator>(const iterator &other) const noexcept {
293 return this->pos > other.pos;
294}
295
296template <typename T>
297bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept {
298 return this->pos >= other.pos;
299}
300
301template <typename T>
302typename Slice<T>::iterator Slice<T>::begin() const noexcept {
303 iterator it;
304 it.pos = slicePtr(this);
305 it.stride = size_of<T>();
306 return it;
307}
308
309template <typename T>
310typename Slice<T>::iterator Slice<T>::end() const noexcept {
311 iterator it = this->begin();
312 it.pos = static_cast<char *>(it.pos) + it.stride * this->size();
313 return it;
314}
315
316template <typename T>
317void Slice<T>::swap(Slice &rhs) noexcept {
318 std::swap(*this, rhs);
319}
320#endif // CXXBRIDGE1_RUST_SLICE
321
322#ifndef CXXBRIDGE1_RUST_BOX
323#define CXXBRIDGE1_RUST_BOX
324template <typename T>
325class Box final {
326public:
327 using element_type = T;
328 using const_pointer =
329 typename std::add_pointer<typename std::add_const<T>::type>::type;
330 using pointer = typename std::add_pointer<T>::type;
331
332 Box() = delete;
333 Box(Box &&) noexcept;
334 ~Box() noexcept;
335
336 explicit Box(const T &);
337 explicit Box(T &&);
338
339 Box &operator=(Box &&) &noexcept;
340
341 const T *operator->() const noexcept;
342 const T &operator*() const noexcept;
343 T *operator->() noexcept;
344 T &operator*() noexcept;
345
346 template <typename... Fields>
347 static Box in_place(Fields &&...);
348
349 void swap(Box &) noexcept;
350
351 static Box from_raw(T *) noexcept;
352
353 T *into_raw() noexcept;
354
355 /* Deprecated */ using value_type = element_type;
356
357private:
358 class uninit;
359 class allocation;
360 Box(uninit) noexcept;
361 void drop() noexcept;
362
363 friend void swap(Box &lhs, Box &rhs) noexcept { lhs.swap(rhs); }
364
365 T *ptr;
366};
367
368template <typename T>
369class Box<T>::uninit {};
370
371template <typename T>
372class Box<T>::allocation {
373 static T *alloc() noexcept;
374 static void dealloc(T *) noexcept;
375
376public:
377 allocation() noexcept : ptr(alloc()) {}
378 ~allocation() noexcept {
379 if (this->ptr) {
380 dealloc(this->ptr);
381 }
382 }
383 T *ptr;
384};
385
386template <typename T>
387Box<T>::Box(Box &&other) noexcept : ptr(other.ptr) {
388 other.ptr = nullptr;
389}
390
391template <typename T>
392Box<T>::Box(const T &val) {
393 allocation alloc;
394 ::new (alloc.ptr) T(val);
395 this->ptr = alloc.ptr;
396 alloc.ptr = nullptr;
397}
398
399template <typename T>
400Box<T>::Box(T &&val) {
401 allocation alloc;
402 ::new (alloc.ptr) T(std::move(val));
403 this->ptr = alloc.ptr;
404 alloc.ptr = nullptr;
405}
406
407template <typename T>
408Box<T>::~Box() noexcept {
409 if (this->ptr) {
410 this->drop();
411 }
412}
413
414template <typename T>
415Box<T> &Box<T>::operator=(Box &&other) &noexcept {
416 if (this->ptr) {
417 this->drop();
418 }
419 this->ptr = other.ptr;
420 other.ptr = nullptr;
421 return *this;
422}
423
424template <typename T>
425const T *Box<T>::operator->() const noexcept {
426 return this->ptr;
427}
428
429template <typename T>
430const T &Box<T>::operator*() const noexcept {
431 return *this->ptr;
432}
433
434template <typename T>
435T *Box<T>::operator->() noexcept {
436 return this->ptr;
437}
438
439template <typename T>
440T &Box<T>::operator*() noexcept {
441 return *this->ptr;
442}
443
444template <typename T>
445template <typename... Fields>
446Box<T> Box<T>::in_place(Fields &&...fields) {
447 allocation alloc;
448 auto ptr = alloc.ptr;
449 ::new (ptr) T{std::forward<Fields>(fields)...};
450 alloc.ptr = nullptr;
451 return from_raw(ptr);
452}
453
454template <typename T>
455void Box<T>::swap(Box &rhs) noexcept {
456 using std::swap;
457 swap(this->ptr, rhs.ptr);
458}
459
460template <typename T>
461Box<T> Box<T>::from_raw(T *raw) noexcept {
462 Box box = uninit{};
463 box.ptr = raw;
464 return box;
465}
466
467template <typename T>
468T *Box<T>::into_raw() noexcept {
469 T *raw = this->ptr;
470 this->ptr = nullptr;
471 return raw;
472}
473
474template <typename T>
475Box<T>::Box(uninit) noexcept {}
476#endif // CXXBRIDGE1_RUST_BOX
477
478#ifndef CXXBRIDGE1_RUST_OPAQUE
479#define CXXBRIDGE1_RUST_OPAQUE
480class Opaque {
481public:
482 Opaque() = delete;
483 Opaque(const Opaque &) = delete;
484 ~Opaque() = delete;
485};
486#endif // CXXBRIDGE1_RUST_OPAQUE
487
488#ifndef CXXBRIDGE1_IS_COMPLETE
489#define CXXBRIDGE1_IS_COMPLETE
490namespace detail {
491namespace {
492template <typename T, typename = std::size_t>
493struct is_complete : std::false_type {};
494template <typename T>
495struct is_complete<T, decltype(sizeof(T))> : std::true_type {};
496} // namespace
497} // namespace detail
498#endif // CXXBRIDGE1_IS_COMPLETE
499
500#ifndef CXXBRIDGE1_LAYOUT
501#define CXXBRIDGE1_LAYOUT
502class layout {
503 template <typename T>
504 friend std::size_t size_of();
505 template <typename T>
506 friend std::size_t align_of();
507 template <typename T>
508 static typename std::enable_if<std::is_base_of<Opaque, T>::value,
509 std::size_t>::type
510 do_size_of() {
511 return T::layout::size();
512 }
513 template <typename T>
514 static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
515 std::size_t>::type
516 do_size_of() {
517 return sizeof(T);
518 }
519 template <typename T>
520 static
521 typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
522 size_of() {
523 return do_size_of<T>();
524 }
525 template <typename T>
526 static typename std::enable_if<std::is_base_of<Opaque, T>::value,
527 std::size_t>::type
528 do_align_of() {
529 return T::layout::align();
530 }
531 template <typename T>
532 static typename std::enable_if<!std::is_base_of<Opaque, T>::value,
533 std::size_t>::type
534 do_align_of() {
535 return alignof(T);
536 }
537 template <typename T>
538 static
539 typename std::enable_if<detail::is_complete<T>::value, std::size_t>::type
540 align_of() {
541 return do_align_of<T>();
542 }
543};
544
545template <typename T>
546std::size_t size_of() {
547 return layout::size_of<T>();
548}
549
550template <typename T>
551std::size_t align_of() {
552 return layout::align_of<T>();
553}
554#endif // CXXBRIDGE1_LAYOUT
555
556template <typename T>
557class Slice<T>::uninit {};
558template <typename T>
559inline Slice<T>::Slice(uninit) noexcept {}
560
561namespace {
562namespace repr {
563using Fat = ::std::array<::std::uintptr_t, 2>;
564} // namespace repr
565
566template <typename T>
567class impl<Slice<T>> final {
568public:
569 static Slice<T> slice(repr::Fat repr) noexcept {
570 Slice<T> slice = typename Slice<T>::uninit{};
571 slice.repr = repr;
572 return slice;
573 }
574};
575} // namespace
576} // namespace cxxbridge1
577} // namespace rust
578
579struct CSnapshotDelta;
580
581#ifndef CXXBRIDGE1_STRUCT_CSnapshotDelta
582#define CXXBRIDGE1_STRUCT_CSnapshotDelta
583struct CSnapshotDelta final : public ::rust::Opaque {
584 ::rust::Box<::CSnapshotDelta> Clone() noexcept;
585 ::std::uint64_t GetDataRate(::std::int32_t type_) const noexcept;
586 ::std::uint64_t GetDataUpdates(::std::int32_t type_) const noexcept;
587 void SetStaticsize(::std::int32_t type_, ::std::size_t size) noexcept;
588 ::rust::Slice<const ::std::int32_t> EmptyDelta() const noexcept;
589 ::std::int32_t CreateDelta(const ::CSnapshot &from, const ::CSnapshot &to, ::rust::Slice<::std::int32_t> delta) noexcept;
590 ::std::int32_t UnpackDelta(const ::CSnapshot &from, ::CSnapshotBuffer &to, ::rust::Slice<const ::std::int32_t> delta) noexcept;
591 ~CSnapshotDelta() = delete;
592
593private:
594 friend ::rust::layout;
595 struct layout {
596 static ::std::size_t size() noexcept;
597 static ::std::size_t align() noexcept;
598 };
599};
600#endif // CXXBRIDGE1_STRUCT_CSnapshotDelta
601
602extern "C" {
603::std::size_t cxxbridge1$CSnapshotDelta$operator$sizeof() noexcept;
604::std::size_t cxxbridge1$CSnapshotDelta$operator$alignof() noexcept;
605
606void cxxbridge1$CSnapshotDelta_DiffItem(::rust::Slice<const ::std::int32_t> past, ::rust::Slice<const ::std::int32_t> current, ::rust::Slice<::std::int32_t> out) noexcept;
607
608::CSnapshotDelta *cxxbridge1$CSnapshotDelta_New() noexcept;
609
610::CSnapshotDelta *cxxbridge1$CSnapshotDelta$Clone(::CSnapshotDelta &self) noexcept;
611
612::std::uint64_t cxxbridge1$CSnapshotDelta$GetDataRate(const ::CSnapshotDelta &self, ::std::int32_t type_) noexcept;
613
614::std::uint64_t cxxbridge1$CSnapshotDelta$GetDataUpdates(const ::CSnapshotDelta &self, ::std::int32_t type_) noexcept;
615
616void cxxbridge1$CSnapshotDelta$SetStaticsize(::CSnapshotDelta &self, ::std::int32_t type_, ::std::size_t size) noexcept;
617
618::rust::repr::Fat cxxbridge1$CSnapshotDelta$EmptyDelta(const ::CSnapshotDelta &self) noexcept;
619
620::std::int32_t cxxbridge1$CSnapshotDelta$CreateDelta(::CSnapshotDelta &self, const ::CSnapshot &from, const ::CSnapshot &to, ::rust::Slice<::std::int32_t> delta) noexcept;
621
622::std::int32_t cxxbridge1$CSnapshotDelta$UnpackDelta(::CSnapshotDelta &self, const ::CSnapshot &from, ::CSnapshotBuffer &to, ::rust::Slice<const ::std::int32_t> delta) noexcept;
623} // extern "C"
624
625::std::size_t CSnapshotDelta::layout::size() noexcept {
626 return cxxbridge1$CSnapshotDelta$operator$sizeof();
627}
628
629::std::size_t CSnapshotDelta::layout::align() noexcept {
630 return cxxbridge1$CSnapshotDelta$operator$alignof();
631}
632
633void CSnapshotDelta_DiffItem(::rust::Slice<const ::std::int32_t> past, ::rust::Slice<const ::std::int32_t> current, ::rust::Slice<::std::int32_t> out) noexcept {
634 cxxbridge1$CSnapshotDelta_DiffItem(past, current, out);
635}
636
637// Create a new snapshot delta.
638//
639// # Example
640//
641// ```
642// # extern crate ddnet_test;
643// use ddnet_engine_shared::CSnapshotDelta_New;
644//
645// let delta = CSnapshotDelta_New();
646// ```
647::rust::Box<::CSnapshotDelta> CSnapshotDelta_New() noexcept {
648 return ::rust::Box<::CSnapshotDelta>::from_raw(raw: cxxbridge1$CSnapshotDelta_New());
649}
650
651::rust::Box<::CSnapshotDelta> CSnapshotDelta::Clone() noexcept {
652 return ::rust::Box<::CSnapshotDelta>::from_raw(raw: cxxbridge1$CSnapshotDelta$Clone(self&: *this));
653}
654
655::std::uint64_t CSnapshotDelta::GetDataRate(::std::int32_t type_) const noexcept {
656 return cxxbridge1$CSnapshotDelta$GetDataRate(self: *this, type_);
657}
658
659::std::uint64_t CSnapshotDelta::GetDataUpdates(::std::int32_t type_) const noexcept {
660 return cxxbridge1$CSnapshotDelta$GetDataUpdates(self: *this, type_);
661}
662
663void CSnapshotDelta::SetStaticsize(::std::int32_t type_, ::std::size_t size) noexcept {
664 cxxbridge1$CSnapshotDelta$SetStaticsize(self&: *this, type_, size);
665}
666
667::rust::Slice<const ::std::int32_t> CSnapshotDelta::EmptyDelta() const noexcept {
668 return ::rust::impl<::rust::Slice<const ::std::int32_t>>::slice(repr: cxxbridge1$CSnapshotDelta$EmptyDelta(self: *this));
669}
670
671::std::int32_t CSnapshotDelta::CreateDelta(const ::CSnapshot &from, const ::CSnapshot &to, ::rust::Slice<::std::int32_t> delta) noexcept {
672 return cxxbridge1$CSnapshotDelta$CreateDelta(self&: *this, from, to, delta);
673}
674
675::std::int32_t CSnapshotDelta::UnpackDelta(const ::CSnapshot &from, ::CSnapshotBuffer &to, ::rust::Slice<const ::std::int32_t> delta) noexcept {
676 return cxxbridge1$CSnapshotDelta$UnpackDelta(self&: *this, from, to, delta);
677}
678
679extern "C" {
680::CSnapshotDelta *cxxbridge1$box$CSnapshotDelta$alloc() noexcept;
681void cxxbridge1$box$CSnapshotDelta$dealloc(::CSnapshotDelta *) noexcept;
682void cxxbridge1$box$CSnapshotDelta$drop(::rust::Box<::CSnapshotDelta> *ptr) noexcept;
683} // extern "C"
684
685namespace rust {
686inline namespace cxxbridge1 {
687template <>
688::CSnapshotDelta *Box<::CSnapshotDelta>::allocation::alloc() noexcept {
689 return cxxbridge1$box$CSnapshotDelta$alloc();
690}
691template <>
692void Box<::CSnapshotDelta>::allocation::dealloc(::CSnapshotDelta *ptr) noexcept {
693 cxxbridge1$box$CSnapshotDelta$dealloc(ptr);
694}
695template <>
696void Box<::CSnapshotDelta>::drop() noexcept {
697 cxxbridge1$box$CSnapshotDelta$drop(ptr: this);
698}
699} // namespace cxxbridge1
700} // namespace rust
701