Deserializer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Core/Variant.h"
  5. #include "../Math/BoundingBox.h"
  6. #include "../Math/Rect.h"
  7. namespace Urho3D
  8. {
  9. /// Abstract stream for reading.
  10. /// @nocount
  11. class URHO3D_API Deserializer
  12. {
  13. public:
  14. /// Construct with zero size.
  15. Deserializer();
  16. /// Construct with defined size.
  17. explicit Deserializer(i64 size);
  18. /// Destruct.
  19. virtual ~Deserializer();
  20. /// Read bytes from the stream. Return number of bytes actually read.
  21. virtual i32 Read(void* dest, i32 size) = 0;
  22. /// Set position from the beginning of the stream. Return actual new position.
  23. virtual i64 Seek(i64 position) = 0;
  24. /// Return name of the stream.
  25. /// @property
  26. virtual const String& GetName() const;
  27. /// Return a checksum if applicable.
  28. /// @property
  29. virtual hash32 GetChecksum();
  30. /// Return whether the end of stream has been reached.
  31. /// @property
  32. virtual bool IsEof() const { return position_ >= size_; }
  33. /// Set position relative to current position. Return actual new position.
  34. i64 SeekRelative(i64 delta);
  35. /// Return current position.
  36. /// @property
  37. i64 GetPosition() const { return position_; }
  38. /// Return current position.
  39. i64 Tell() const { return position_; }
  40. /// Return size.
  41. /// @property
  42. i64 GetSize() const { return size_; }
  43. /// Read a 64-bit integer.
  44. i64 ReadI64();
  45. /// Read a 32-bit integer.
  46. i32 ReadI32();
  47. /// Read a 16-bit integer.
  48. i16 ReadI16();
  49. /// Read an 8-bit integer.
  50. i8 ReadI8();
  51. /// Read a 64-bit unsigned integer.
  52. u64 ReadU64();
  53. /// Read a 32-bit unsigned integer.
  54. u32 ReadU32();
  55. /// Read a 16-bit unsigned integer.
  56. u16 ReadU16();
  57. /// Read an 8-bit unsigned integer.
  58. u8 ReadU8();
  59. /// Read an 8-bit unsigned integer
  60. byte ReadByte();
  61. /// Read a bool.
  62. bool ReadBool();
  63. /// Read a float.
  64. float ReadFloat();
  65. /// Read a double.
  66. double ReadDouble();
  67. /// Read an IntRect.
  68. IntRect ReadIntRect();
  69. /// Read an IntVector2.
  70. IntVector2 ReadIntVector2();
  71. /// Read an IntVector3.
  72. IntVector3 ReadIntVector3();
  73. /// Read a Rect.
  74. Rect ReadRect();
  75. /// Read a Vector2.
  76. Vector2 ReadVector2();
  77. /// Read a Vector3.
  78. Vector3 ReadVector3();
  79. /// Read a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  80. Vector3 ReadPackedVector3(float maxAbsCoord);
  81. /// Read a Vector4.
  82. Vector4 ReadVector4();
  83. /// Read a quaternion.
  84. Quaternion ReadQuaternion();
  85. /// Read a quaternion with each component packed in 16 bits.
  86. Quaternion ReadPackedQuaternion();
  87. /// Read a Matrix3.
  88. Matrix3 ReadMatrix3();
  89. /// Read a Matrix3x4.
  90. Matrix3x4 ReadMatrix3x4();
  91. /// Read a Matrix4.
  92. Matrix4 ReadMatrix4();
  93. /// Read a color.
  94. Color ReadColor();
  95. /// Read a bounding box.
  96. BoundingBox ReadBoundingBox();
  97. /// Read a null-terminated string.
  98. String ReadString();
  99. /// Read a four-letter file ID.
  100. String ReadFileID();
  101. /// Read a 32-bit StringHash.
  102. StringHash ReadStringHash();
  103. /// Read a buffer with size encoded as VLE.
  104. Vector<byte> ReadBuffer();
  105. /// Read a resource reference.
  106. ResourceRef ReadResourceRef();
  107. /// Read a resource reference list.
  108. ResourceRefList ReadResourceRefList();
  109. /// Read a variant.
  110. Variant ReadVariant();
  111. /// Read a variant whose type is already known.
  112. Variant ReadVariant(VariantType type);
  113. /// Read a variant vector.
  114. VariantVector ReadVariantVector();
  115. /// Read a string vector.
  116. StringVector ReadStringVector();
  117. /// Read a variant map.
  118. VariantMap ReadVariantMap();
  119. /// Read a variable-length encoded unsigned integer, which can use 29 bits maximum.
  120. unsigned ReadVLE();
  121. /// Read a 24-bit network object ID.
  122. id32 ReadNetID();
  123. /// Read a text line.
  124. String ReadLine();
  125. protected:
  126. /// Stream position.
  127. i64 position_;
  128. /// Stream size.
  129. i64 size_;
  130. };
  131. }