Ejemplo n.º 1
0
            /// <summary>
            /// Just calculates the compression efficiency
            /// </summary>
            /// <param name="value"></param>
            /// <param name="format"></param>
            /// <param name="ctx"></param>
            /// <param name="compressionLevel"></param>
            /// <returns></returns>
            public static string GetEfficiency(object value, DataFormat format, SerializationContext ctx = null,
                                               OdinLZ4Level compressionLevel = OdinLZ4Level.FAST)
            {
                float compressedLengh   = SerializeValue(value, format, ctx, compressionLevel).Length;
                float uncompressedLengh = SerializationUtility.SerializeValue(value, format, ctx).Length;

                return((100f - ((compressedLengh / uncompressedLengh) * 100f)).ToString("F3") + " %");
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Counts the time spent on compression
            /// </summary>
            /// <param name="value"></param>
            /// <param name="format"></param>
            /// <param name="ctx"></param>
            /// <param name="compressionLevel"></param>
            /// <returns></returns>
            public static string CalculatingSpeed(object value, DataFormat format, SerializationContext ctx = null,
                                                  OdinLZ4Level compressionLevel = OdinLZ4Level.FAST)
            {
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();

                SerializeValue(value, format, ctx, compressionLevel);
                SerializationUtility.SerializeValue(value, format, ctx);

                stopwatch.Stop();
                return("Elapsed time : " + stopwatch.ElapsedMilliseconds + "(ms)");
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Short version of <see cref="SerializeValue{T}(T, DataFormat, out List{UnityEngine.Object}, SerializationContext, OdinLZ4Level)"/>
 /// for fast data serialization in binary format. Fills a <paramref name="unityObjects"/> list with the Unity objects
 /// which were referenced during serialization.
 /// </summary>
 /// <param name="value">The value to serialize</param>
 /// <param name="unityObjects">A list of the Unity objects which were referenced during serialization</param>
 /// <param name="level">Level of compression</param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static byte[] LazySerialization <T>(T value, out List <UnityEngine.Object> unityObjects,
                                            OdinLZ4Level level = OdinLZ4Level.FAST) => SerializeValue <T>(value, DataFormat.Binary, out unityObjects, level: level);
Ejemplo n.º 4
0
 /// <summary>
 /// Short version of <see cref="SerializeValue{T}(T, DataFormat, SerializationContext, OdinLZ4Level)"/>
 /// for fast data serialization in binary format
 /// </summary>
 /// <param name="value">The value to serialize</param>
 /// <param name="level">Level of compression</param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static byte[] LazySerialization <T>(T value, OdinLZ4Level level = OdinLZ4Level.FAST) =>
 SerializeValue <T>(value, DataFormat.Binary, level: level);
Ejemplo n.º 5
0
 /// <summary>
 /// Serialize type and compress it via LZ4. Fills a <paramref name="unityObjects"/> list with the Unity objects
 /// which were referenced during serialization.
 /// </summary>
 /// <param name="value">The value to serialize</param>
 /// <param name="format">The format of serialization</param>
 /// <param name="unityObjects">A list of the Unity objects which were referenced during serialization</param>
 /// <param name="ctx">The context of a given serialization session</param>
 /// <param name="level">Level of compression</param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static byte[] SerializeValue <T>(T value, DataFormat format, out List <UnityEngine.Object> unityObjects,
                                         SerializationContext ctx = null, OdinLZ4Level level = OdinLZ4Level.FAST) =>
 OdinLZ4Engine.Encode(SerializationUtility.SerializeValue <T>(value, format, out unityObjects, ctx), (LZ4Level)level);