Serializer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/HashMap.h"
  5. #include "../Core/Variant.h"
  6. #include "../Math/BoundingBox.h"
  7. #include "../Math/StringHash.h"
  8. namespace Urho3D
  9. {
  10. class Color;
  11. class IntRect;
  12. class IntVector2;
  13. class IntVector3;
  14. class Quaternion;
  15. class Rect;
  16. class Vector2;
  17. class Vector3;
  18. class Vector4;
  19. /// Abstract stream for writing.
  20. /// @nocount
  21. class URHO3D_API Serializer
  22. {
  23. public:
  24. /// Destruct.
  25. virtual ~Serializer();
  26. /// Write bytes to the stream. Return number of bytes actually written.
  27. virtual i32 Write(const void* data, i32 size) = 0;
  28. /// Write a 64-bit integer.
  29. bool WriteI64(i64 value);
  30. /// Write a 32-bit integer.
  31. bool WriteI32(i32 value);
  32. /// Write a 16-bit integer.
  33. bool WriteI16(i16 value);
  34. /// Write an 8-bit integer.
  35. bool WriteI8(i8 value);
  36. /// Write a 64-bit unsigned integer.
  37. bool WriteU64(u64 value);
  38. /// Write a 32-bit unsigned integer.
  39. bool WriteU32(u32 value);
  40. /// Write a 16-bit unsigned integer.
  41. bool WriteU16(u16 value);
  42. /// Write an 8-bit unsigned integer.
  43. bool WriteU8(u8 value);
  44. /// Write an byte
  45. bool WriteByte(byte value);
  46. /// Write a bool.
  47. bool WriteBool(bool value);
  48. /// Write a float.
  49. bool WriteFloat(float value);
  50. /// Write a double.
  51. bool WriteDouble(double value);
  52. /// Write an IntRect.
  53. bool WriteIntRect(const IntRect& value);
  54. /// Write an IntVector2.
  55. bool WriteIntVector2(const IntVector2& value);
  56. /// Write an IntVector3.
  57. bool WriteIntVector3(const IntVector3& value);
  58. /// Write a Rect.
  59. bool WriteRect(const Rect& value);
  60. /// Write a Vector2.
  61. bool WriteVector2(const Vector2& value);
  62. /// Write a Vector3.
  63. bool WriteVector3(const Vector3& value);
  64. /// Write a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  65. bool WritePackedVector3(const Vector3& value, float maxAbsCoord);
  66. /// Write a Vector4.
  67. bool WriteVector4(const Vector4& value);
  68. /// Write a quaternion.
  69. bool WriteQuaternion(const Quaternion& value);
  70. /// Write a quaternion with each component packed in 16 bits.
  71. bool WritePackedQuaternion(const Quaternion& value);
  72. /// Write a Matrix3.
  73. bool WriteMatrix3(const Matrix3& value);
  74. /// Write a Matrix3x4.
  75. bool WriteMatrix3x4(const Matrix3x4& value);
  76. /// Write a Matrix4.
  77. bool WriteMatrix4(const Matrix4& value);
  78. /// Write a color.
  79. bool WriteColor(const Color& value);
  80. /// Write a bounding box.
  81. bool WriteBoundingBox(const BoundingBox& value);
  82. /// Write a null-terminated string.
  83. bool WriteString(const String& value);
  84. /// Write a four-letter file ID. If the string is not long enough, spaces will be appended.
  85. bool WriteFileID(const String& value);
  86. /// Write a 32-bit StringHash.
  87. bool WriteStringHash(const StringHash& value);
  88. /// Write a buffer, with size encoded as VLE.
  89. bool WriteBuffer(const Vector<byte>& value);
  90. /// Write a resource reference.
  91. bool WriteResourceRef(const ResourceRef& value);
  92. /// Write a resource reference list.
  93. bool WriteResourceRefList(const ResourceRefList& value);
  94. /// Write a variant.
  95. bool WriteVariant(const Variant& value);
  96. /// Write a variant without the type information.
  97. bool WriteVariantData(const Variant& value);
  98. /// Write a variant vector.
  99. bool WriteVariantVector(const VariantVector& value);
  100. /// Write a variant vector.
  101. bool WriteStringVector(const StringVector& value);
  102. /// Write a variant map.
  103. bool WriteVariantMap(const VariantMap& value);
  104. /// Write a variable-length encoded unsigned integer, which can use 29 bits maximum.
  105. bool WriteVLE(unsigned value);
  106. /// Write a 24-bit network object ID.
  107. bool WriteNetID(id32 value);
  108. /// Write a text line. Char codes 13 & 10 will be automatically appended.
  109. bool WriteLine(const String& value);
  110. };
  111. }