Serializer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Container/HashMap.h"
  24. #include "../Core/Variant.h"
  25. #include "../Math/BoundingBox.h"
  26. #include "../Math/StringHash.h"
  27. namespace Atomic
  28. {
  29. class Color;
  30. class IntRect;
  31. class IntVector2;
  32. class IntVector3;
  33. class Quaternion;
  34. class Rect;
  35. class Vector2;
  36. class Vector3;
  37. class Vector4;
  38. /// Abstract stream for writing.
  39. class ATOMIC_API Serializer
  40. {
  41. public:
  42. /// Destruct.
  43. virtual ~Serializer();
  44. /// Write bytes to the stream. Return number of bytes actually written.
  45. virtual unsigned Write(const void* data, unsigned size) = 0;
  46. /// Write a 64-bit integer.
  47. bool WriteInt64(long long value);
  48. /// Write a 32-bit integer.
  49. bool WriteInt(int value);
  50. /// Write a 16-bit integer.
  51. bool WriteShort(short value);
  52. /// Write an 8-bit integer.
  53. bool WriteByte(signed char value);
  54. /// Write a 64-bit unsigned integer.
  55. bool WriteUInt64(unsigned long long value);
  56. /// Write a 32-bit unsigned integer.
  57. bool WriteUInt(unsigned value);
  58. /// Write a 16-bit unsigned integer.
  59. bool WriteUShort(unsigned short value);
  60. /// Write an 8-bit unsigned integer.
  61. bool WriteUByte(unsigned char value);
  62. /// Write a bool.
  63. bool WriteBool(bool value);
  64. /// Write a float.
  65. bool WriteFloat(float value);
  66. /// Write a double.
  67. bool WriteDouble(double value);
  68. /// Write an IntRect.
  69. bool WriteIntRect(const IntRect& value);
  70. /// Write an IntVector2.
  71. bool WriteIntVector2(const IntVector2& value);
  72. /// Write an IntVector3.
  73. bool WriteIntVector3(const IntVector3& value);
  74. /// Write a Rect.
  75. bool WriteRect(const Rect& value);
  76. /// Write a Vector2.
  77. bool WriteVector2(const Vector2& value);
  78. /// Write a Vector3.
  79. bool WriteVector3(const Vector3& value);
  80. /// Write a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  81. bool WritePackedVector3(const Vector3& value, float maxAbsCoord);
  82. /// Write a Vector4.
  83. bool WriteVector4(const Vector4& value);
  84. /// Write a quaternion.
  85. bool WriteQuaternion(const Quaternion& value);
  86. /// Write a quaternion with each component packed in 16 bits.
  87. bool WritePackedQuaternion(const Quaternion& value);
  88. /// Write a Matrix3.
  89. bool WriteMatrix3(const Matrix3& value);
  90. /// Write a Matrix3x4.
  91. bool WriteMatrix3x4(const Matrix3x4& value);
  92. /// Write a Matrix4.
  93. bool WriteMatrix4(const Matrix4& value);
  94. /// Write a color.
  95. bool WriteColor(const Color& value);
  96. /// Write a bounding box.
  97. bool WriteBoundingBox(const BoundingBox& value);
  98. /// Write a null-terminated string.
  99. bool WriteString(const String& value);
  100. /// Write a four-letter file ID. If the string is not long enough, spaces will be appended.
  101. bool WriteFileID(const String& value);
  102. /// Write a 32-bit StringHash.
  103. bool WriteStringHash(const StringHash& value);
  104. /// Write a buffer, with size encoded as VLE.
  105. bool WriteBuffer(const PODVector<unsigned char>& buffer);
  106. /// Write a resource reference.
  107. bool WriteResourceRef(const ResourceRef& value);
  108. /// Write a resource reference list.
  109. bool WriteResourceRefList(const ResourceRefList& value);
  110. /// Write a variant.
  111. bool WriteVariant(const Variant& value);
  112. /// Write a variant without the type information.
  113. bool WriteVariantData(const Variant& value);
  114. /// Write a variant vector.
  115. bool WriteVariantVector(const VariantVector& value);
  116. /// Write a variant vector.
  117. bool WriteStringVector(const StringVector& value);
  118. /// Write a variant map.
  119. bool WriteVariantMap(const VariantMap& value);
  120. /// Write a variable-length encoded unsigned integer, which can use 29 bits maximum.
  121. bool WriteVLE(unsigned value);
  122. /// Write a 24-bit network object ID.
  123. bool WriteNetID(unsigned value);
  124. /// Write a text line. Char codes 13 & 10 will be automatically appended.
  125. bool WriteLine(const String& value);
  126. };
  127. }