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 23 #pragma once 24 25 #include "../Container/HashMap.h" 26 #include "../Core/Variant.h" 27 #include "../Math/BoundingBox.h" 28 #include "../Math/StringHash.h" 29 30 namespace Urho3D 31 { 32 33 class Color; 34 class IntRect; 35 class IntVector2; 36 class IntVector3; 37 class Quaternion; 38 class Rect; 39 class Vector2; 40 class Vector3; 41 class Vector4; 42 43 /// Abstract stream for writing. 44 class URHO3D_API Serializer 45 { 46 public: 47 /// Destruct. 48 virtual ~Serializer(); 49 50 /// Write bytes to the stream. Return number of bytes actually written. 51 virtual unsigned Write(const void* data, unsigned size) = 0; 52 53 /// Write a 64-bit integer. 54 bool WriteInt64(long long value); 55 /// Write a 32-bit integer. 56 bool WriteInt(int value); 57 /// Write a 16-bit integer. 58 bool WriteShort(short value); 59 /// Write an 8-bit integer. 60 bool WriteByte(signed char value); 61 /// Write a 64-bit unsigned integer. 62 bool WriteUInt64(unsigned long long value); 63 /// Write a 32-bit unsigned integer. 64 bool WriteUInt(unsigned value); 65 /// Write a 16-bit unsigned integer. 66 bool WriteUShort(unsigned short value); 67 /// Write an 8-bit unsigned integer. 68 bool WriteUByte(unsigned char value); 69 /// Write a bool. 70 bool WriteBool(bool value); 71 /// Write a float. 72 bool WriteFloat(float value); 73 /// Write a double. 74 bool WriteDouble(double value); 75 /// Write an IntRect. 76 bool WriteIntRect(const IntRect& value); 77 /// Write an IntVector2. 78 bool WriteIntVector2(const IntVector2& value); 79 /// Write an IntVector3. 80 bool WriteIntVector3(const IntVector3& value); 81 /// Write a Rect. 82 bool WriteRect(const Rect& value); 83 /// Write a Vector2. 84 bool WriteVector2(const Vector2& value); 85 /// Write a Vector3. 86 bool WriteVector3(const Vector3& value); 87 /// Write a Vector3 packed into 3 x 16 bits with the specified maximum absolute range. 88 bool WritePackedVector3(const Vector3& value, float maxAbsCoord); 89 /// Write a Vector4. 90 bool WriteVector4(const Vector4& value); 91 /// Write a quaternion. 92 bool WriteQuaternion(const Quaternion& value); 93 /// Write a quaternion with each component packed in 16 bits. 94 bool WritePackedQuaternion(const Quaternion& value); 95 /// Write a Matrix3. 96 bool WriteMatrix3(const Matrix3& value); 97 /// Write a Matrix3x4. 98 bool WriteMatrix3x4(const Matrix3x4& value); 99 /// Write a Matrix4. 100 bool WriteMatrix4(const Matrix4& value); 101 /// Write a color. 102 bool WriteColor(const Color& value); 103 /// Write a bounding box. 104 bool WriteBoundingBox(const BoundingBox& value); 105 /// Write a null-terminated string. 106 bool WriteString(const String& value); 107 /// Write a four-letter file ID. If the string is not long enough, spaces will be appended. 108 bool WriteFileID(const String& value); 109 /// Write a 32-bit StringHash. 110 bool WriteStringHash(const StringHash& value); 111 /// Write a buffer, with size encoded as VLE. 112 bool WriteBuffer(const PODVector<unsigned char>& buffer); 113 /// Write a resource reference. 114 bool WriteResourceRef(const ResourceRef& value); 115 /// Write a resource reference list. 116 bool WriteResourceRefList(const ResourceRefList& value); 117 /// Write a variant. 118 bool WriteVariant(const Variant& value); 119 /// Write a variant without the type information. 120 bool WriteVariantData(const Variant& value); 121 /// Write a variant vector. 122 bool WriteVariantVector(const VariantVector& value); 123 /// Write a variant vector. 124 bool WriteStringVector(const StringVector& value); 125 /// Write a variant map. 126 bool WriteVariantMap(const VariantMap& value); 127 /// Write a variable-length encoded unsigned integer, which can use 29 bits maximum. 128 bool WriteVLE(unsigned value); 129 /// Write a 24-bit network object ID. 130 bool WriteNetID(unsigned value); 131 /// Write a text line. Char codes 13 & 10 will be automatically appended. 132 bool WriteLine(const String& value); 133 }; 134 135 } 136