< Summary

Class:GDX.Serializable
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Serializable.cs
Covered lines:67
Uncovered lines:138
Coverable lines:205
Total lines:432
Line coverage:32.6% (67 of 205)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:7
Method coverage:42.8% (3 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Serializable()0%110100%
GetHashCode(...)0%11223300%
GetLabel(...)0%33.233094.29%
GetLabelFromTypeValue(...)0%110100%
GetTypeFromHashCode(...)0%9923100%
GetTypeFromLabel(...)0%2100%
IsReferenceType(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/Serializable.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System.Runtime.CompilerServices;
 6
 7namespace GDX
 8{
 9    public static class Serializable
 10    {
 11        public enum SerializableTypes
 12        {
 13            Invalid = -1,
 14            String,
 15            Char,
 16            Bool,
 17            SByte,
 18            Byte,
 19            Short,
 20            UShort,
 21            Int,
 22            UInt,
 23            Long,
 24            ULong,
 25            Float,
 26            Double,
 27            Vector2,
 28            Vector3,
 29            Vector4,
 30            Vector2Int,
 31            Vector3Int,
 32            Quaternion,
 33            Rect,
 34            RectInt,
 35            Color,
 36            LayerMask,
 37            Bounds,
 38            BoundsInt,
 39            Hash128,
 40            Gradient,
 41            AnimationCurve,
 42            Object,
 43            EnumInt
 44        }
 45
 46        const string k_Invalid = "Invalid";
 47        const string k_String = "String";
 48        const string k_Char = "Character";
 49        const string k_Bool = "Boolean";
 50        const string k_SByte = "Signed Byte";
 51        const string k_Byte = "Unsigned Byte";
 52        const string k_Short = "Short";
 53        const string k_UShort = "Unsigned Short";
 54        const string k_Int = "Integer";
 55        const string k_UInt = "UInt";
 56        const string k_Long = "Long";
 57        const string k_ULong = "Unsigned Long";
 58        const string k_Float = "Float";
 59        const string k_Double = "Double";
 60        const string k_Vector2 = "Vector2";
 61        const string k_Vector3 = "Vector3";
 62        const string k_Vector4 = "Vector4";
 63        const string k_Vector2Int = "Vector2 (Integer)";
 64        const string k_Vector3Int = "Vector3 (Integer)";
 65        const string k_Quaternion = "Quaternion";
 66        const string k_Rect = "Rectangle";
 67        const string k_RectInt = "Rectangle (Integer)";
 68        const string k_Color = "Color";
 69        const string k_LayerMask = "Layer (Mask)";
 70        const string k_Bounds = "Bounds";
 71        const string k_BoundsInt = "Bounds (Integer)";
 72        const string k_Hash128 = "Hash128";
 73        const string k_Gradient = "Gradient";
 74        const string k_AnimationCurve = "AnimationCurve";
 75        const string k_Object = "Object";
 76        const string k_EnumInt = "Enum (Integer)";
 77
 78        public const int SerializableTypesCount = 30;
 179        static readonly int k_InvalidHashCode = k_Invalid.GetStableHashCode();
 180        static readonly int k_StringHashCode = k_String.GetStableHashCode();
 181        static readonly int k_CharHashCode = k_Char.GetStableHashCode();
 182        static readonly int k_BoolHashCode = k_Bool.GetStableHashCode();
 183        static readonly int k_SByteHashCode = k_SByte.GetStableHashCode();
 184        static readonly int k_ByteHashCode = k_Byte.GetStableHashCode();
 185        static readonly int k_ShortHashCode = k_Short.GetStableHashCode();
 186        static readonly int k_UShortHashCode = k_UShort.GetStableHashCode();
 187        static readonly int k_IntHashCode = k_Int.GetStableHashCode();
 188        static readonly int k_UIntHashCode = k_UInt.GetStableHashCode();
 189        static readonly int k_LongHashCode = k_Long.GetStableHashCode();
 190        static readonly int k_ULongHashCode = k_ULong.GetStableHashCode();
 191        static readonly int k_FloatHashCode = k_Float.GetStableHashCode();
 192        static readonly int k_DoubleHashCode = k_Double.GetStableHashCode();
 193        static readonly int k_Vector2HashCode = k_Vector2.GetStableHashCode();
 194        static readonly int k_Vector3HashCode = k_Vector3.GetStableHashCode();
 195        static readonly int k_Vector4HashCode = k_Vector4.GetStableHashCode();
 196        static readonly int k_Vector2IntHashCode = k_Vector2Int.GetStableHashCode();
 197        static readonly int k_Vector3IntHashCode = k_Vector3Int.GetStableHashCode();
 198        static readonly int k_QuaternionHashCode = k_Quaternion.GetStableHashCode();
 199        static readonly int k_RectHashCode = k_Rect.GetStableHashCode();
 1100        static readonly int k_RectIntHashCode = k_RectInt.GetStableHashCode();
 1101        static readonly int k_ColorHashCode = k_Color.GetStableHashCode();
 1102        static readonly int k_LayerMaskHashCode = k_LayerMask.GetStableHashCode();
 1103        static readonly int k_BoundsHashCode = k_Bounds.GetStableHashCode();
 1104        static readonly int k_BoundsIntHashCode = k_BoundsInt.GetStableHashCode();
 1105        static readonly int k_Hash128HashCode = k_Hash128.GetStableHashCode();
 1106        static readonly int k_GradientHashCode = k_Gradient.GetStableHashCode();
 1107        static readonly int k_AnimationCurveHashCode = k_AnimationCurve.GetStableHashCode();
 1108        static readonly int k_ObjectHashCode = k_Object.GetStableHashCode();
 1109        static readonly int k_EnumIntHashCode = k_EnumInt.GetStableHashCode();
 110
 111        public static int GetHashCode(this SerializableTypes serializableTypes)
 0112        {
 0113            switch (serializableTypes)
 114            {
 115                case SerializableTypes.Invalid:
 0116                    return k_InvalidHashCode;
 117                case SerializableTypes.String:
 0118                    return k_StringHashCode;
 119                case SerializableTypes.Char:
 0120                    return k_CharHashCode;
 121                case SerializableTypes.Bool:
 0122                    return k_BoolHashCode;
 123                case SerializableTypes.SByte:
 0124                    return k_SByteHashCode;
 125                case SerializableTypes.Byte:
 0126                    return k_ByteHashCode;
 127                case SerializableTypes.Short:
 0128                    return k_ShortHashCode;
 129                case SerializableTypes.UShort:
 0130                    return k_UShortHashCode;
 131                case SerializableTypes.Int:
 0132                    return k_IntHashCode;
 133                case SerializableTypes.UInt:
 0134                    return k_UIntHashCode;
 135                case SerializableTypes.Long:
 0136                    return k_LongHashCode;
 137                case SerializableTypes.ULong:
 0138                    return k_ULongHashCode;
 139                case SerializableTypes.Float:
 0140                    return k_FloatHashCode;
 141                case SerializableTypes.Double:
 0142                    return k_DoubleHashCode;
 143                case SerializableTypes.Vector2:
 0144                    return k_Vector2HashCode;
 145                case SerializableTypes.Vector3:
 0146                    return k_Vector3HashCode;
 147                case SerializableTypes.Vector4:
 0148                    return k_Vector4HashCode;
 149                case SerializableTypes.Vector2Int:
 0150                    return k_Vector2IntHashCode;
 151                case SerializableTypes.Vector3Int:
 0152                    return k_Vector3IntHashCode;
 153                case SerializableTypes.Quaternion:
 0154                    return k_QuaternionHashCode;
 155                case SerializableTypes.Rect:
 0156                    return k_RectHashCode;
 157                case SerializableTypes.RectInt:
 0158                    return k_RectIntHashCode;
 159                case SerializableTypes.Color:
 0160                    return k_ColorHashCode;
 161                case SerializableTypes.LayerMask:
 0162                    return k_LayerMaskHashCode;
 163                case SerializableTypes.Bounds:
 0164                    return k_BoundsHashCode;
 165                case SerializableTypes.BoundsInt:
 0166                    return k_BoundsIntHashCode;
 167                case SerializableTypes.Hash128:
 0168                    return k_Hash128HashCode;
 169                case SerializableTypes.Gradient:
 0170                    return k_GradientHashCode;
 171                case SerializableTypes.AnimationCurve:
 0172                    return k_AnimationCurveHashCode;
 173                case SerializableTypes.Object:
 0174                    return k_ObjectHashCode;
 175                case SerializableTypes.EnumInt:
 0176                    return k_EnumIntHashCode;
 177            }
 178
 0179            return k_InvalidHashCode;
 0180        }
 181
 182        public static string GetLabel(this SerializableTypes serializableType)
 38183        {
 38184            switch (serializableType)
 185            {
 186                case SerializableTypes.Invalid:
 0187                    return k_Invalid;
 188                case SerializableTypes.String:
 9189                    return k_String;
 190                case SerializableTypes.Char:
 1191                    return k_Char;
 192                case SerializableTypes.Bool:
 1193                    return k_Bool;
 194                case SerializableTypes.SByte:
 1195                    return k_SByte;
 196                case SerializableTypes.Byte:
 1197                    return k_Byte;
 198                case SerializableTypes.Short:
 1199                    return k_Short;
 200                case SerializableTypes.UShort:
 1201                    return k_UShort;
 202                case SerializableTypes.Int:
 1203                    return k_Int;
 204                case SerializableTypes.UInt:
 1205                    return k_UInt;
 206                case SerializableTypes.Long:
 1207                    return k_Long;
 208                case SerializableTypes.ULong:
 1209                    return k_ULong;
 210                case SerializableTypes.Float:
 1211                    return k_Float;
 212                case SerializableTypes.Double:
 1213                    return k_Double;
 214                case SerializableTypes.Vector2:
 1215                    return k_Vector2;
 216                case SerializableTypes.Vector3:
 1217                    return k_Vector3;
 218                case SerializableTypes.Vector4:
 1219                    return k_Vector4;
 220                case SerializableTypes.Vector2Int:
 1221                    return k_Vector2Int;
 222                case SerializableTypes.Vector3Int:
 1223                    return k_Vector3Int;
 224                case SerializableTypes.Quaternion:
 1225                    return k_Quaternion;
 226                case SerializableTypes.Rect:
 1227                    return k_Rect;
 228                case SerializableTypes.RectInt:
 1229                    return k_RectInt;
 230                case SerializableTypes.Color:
 1231                    return k_Color;
 232                case SerializableTypes.LayerMask:
 1233                    return k_LayerMask;
 234                case SerializableTypes.Bounds:
 1235                    return k_Bounds;
 236                case SerializableTypes.BoundsInt:
 1237                    return k_BoundsInt;
 238                case SerializableTypes.Hash128:
 1239                    return k_Hash128;
 240                case SerializableTypes.Gradient:
 1241                    return k_Gradient;
 242                case SerializableTypes.AnimationCurve:
 1243                    return k_AnimationCurve;
 244                case SerializableTypes.Object:
 1245                    return k_Object;
 246                case SerializableTypes.EnumInt:
 1247                    return k_EnumInt;
 248            }
 249
 0250            return k_Invalid;
 38251        }
 252
 253        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 254        public static string GetLabelFromTypeValue(int typeValue)
 8255        {
 8256            return GetLabel((SerializableTypes)typeValue);
 8257        }
 258
 259        public static SerializableTypes GetTypeFromHashCode(int hashCode)
 0260        {
 0261            if (hashCode == k_StringHashCode)
 0262            {
 0263                return SerializableTypes.String;
 264            }
 265
 0266            if (hashCode == k_CharHashCode)
 0267            {
 0268                return SerializableTypes.Char;
 269            }
 270
 0271            if (hashCode == k_BoolHashCode)
 0272            {
 0273                return SerializableTypes.Bool;
 274            }
 275
 0276            if (hashCode == k_SByteHashCode)
 0277            {
 0278                return SerializableTypes.SByte;
 279            }
 280
 0281            if (hashCode == k_ByteHashCode)
 0282            {
 0283                return SerializableTypes.Byte;
 284            }
 285
 0286            if (hashCode == k_ShortHashCode)
 0287            {
 0288                return SerializableTypes.Short;
 289            }
 290
 0291            if (hashCode == k_UShortHashCode)
 0292            {
 0293                return SerializableTypes.UShort;
 294            }
 295
 0296            if (hashCode == k_IntHashCode)
 0297            {
 0298                return SerializableTypes.Int;
 299            }
 300
 0301            if (hashCode == k_UIntHashCode)
 0302            {
 0303                return SerializableTypes.UInt;
 304            }
 305
 0306            if (hashCode == k_LongHashCode)
 0307            {
 0308                return SerializableTypes.Long;
 309            }
 310
 0311            if (hashCode == k_ULongHashCode)
 0312            {
 0313                return SerializableTypes.ULong;
 314            }
 315
 0316            if (hashCode == k_FloatHashCode)
 0317            {
 0318                return SerializableTypes.Float;
 319            }
 320
 0321            if (hashCode == k_DoubleHashCode)
 0322            {
 0323                return SerializableTypes.Double;
 324            }
 325
 0326            if (hashCode == k_Vector2HashCode)
 0327            {
 0328                return SerializableTypes.Vector2;
 329            }
 330
 0331            if (hashCode == k_Vector3HashCode)
 0332            {
 0333                return SerializableTypes.Vector3;
 334            }
 335
 0336            if (hashCode == k_Vector4HashCode)
 0337            {
 0338                return SerializableTypes.Vector4;
 339            }
 340
 0341            if (hashCode == k_Vector2IntHashCode)
 0342            {
 0343                return SerializableTypes.Vector2Int;
 344            }
 345
 0346            if (hashCode == k_Vector3IntHashCode)
 0347            {
 0348                return SerializableTypes.Vector3Int;
 349            }
 350
 0351            if (hashCode == k_QuaternionHashCode)
 0352            {
 0353                return SerializableTypes.Quaternion;
 354            }
 355
 0356            if (hashCode == k_RectHashCode)
 0357            {
 0358                return SerializableTypes.Rect;
 359            }
 360
 0361            if (hashCode == k_RectIntHashCode)
 0362            {
 0363                return SerializableTypes.RectInt;
 364            }
 365
 0366            if (hashCode == k_ColorHashCode)
 0367            {
 0368                return SerializableTypes.Color;
 369            }
 370
 0371            if (hashCode == k_LayerMaskHashCode)
 0372            {
 0373                return SerializableTypes.LayerMask;
 374            }
 375
 0376            if (hashCode == k_BoundsHashCode)
 0377            {
 0378                return SerializableTypes.Bounds;
 379            }
 380
 0381            if (hashCode == k_BoundsIntHashCode)
 0382            {
 0383                return SerializableTypes.BoundsInt;
 384            }
 385
 0386            if (hashCode == k_Hash128HashCode)
 0387            {
 0388                return SerializableTypes.Hash128;
 389            }
 390
 0391            if (hashCode == k_GradientHashCode)
 0392            {
 0393                return SerializableTypes.Gradient;
 394            }
 395
 0396            if (hashCode == k_AnimationCurveHashCode)
 0397            {
 0398                return SerializableTypes.AnimationCurve;
 399            }
 400
 0401            if (hashCode == k_ObjectHashCode)
 0402            {
 0403                return SerializableTypes.Object;
 404            }
 405
 0406            if (hashCode == k_EnumIntHashCode)
 0407            {
 0408                return SerializableTypes.EnumInt;
 409            }
 410
 0411            return SerializableTypes.Invalid;
 0412        }
 413
 414        public static SerializableTypes GetTypeFromLabel(string label)
 0415        {
 0416            return GetTypeFromHashCode(label.GetStableHashCode());
 0417        }
 418
 419        public static bool IsReferenceType(this SerializableTypes type)
 0420        {
 0421            switch (type)
 422            {
 423                case SerializableTypes.Gradient:
 424                case SerializableTypes.AnimationCurve:
 425                case SerializableTypes.Object:
 0426                    return true;
 427                default:
 0428                    return false;
 429            }
 0430        }
 431    }
 432}

Coverage by test methods






Methods/Properties

Serializable()
GetHashCode(GDX.Serializable/SerializableTypes)
GetLabel(GDX.Serializable/SerializableTypes)
GetLabelFromTypeValue(System.Int32)
GetTypeFromHashCode(System.Int32)
GetTypeFromLabel(System.String)
IsReferenceType(GDX.Serializable/SerializableTypes)