Ejemplo n.º 1
0
        public void WriteNumerical_Decimal()
        {
            var val = ABSaveWriter.WriteNumerical(616136316631790.13613137137177m, TypeCode.Decimal, true);

            // Act/Assert
            Assert.AreEqual(val, "\b\u000f\u0019\u008e[Òr½o2\u0001\u009a\u0015Ç\0\0\u000e");
        }
Ejemplo n.º 2
0
        public void WriteNumerical_DecimalToSB()
        {
            // Act
            var sb = new StringBuilder();

            ABSaveWriter.WriteNumerical(616136316631790.13613137137177m, TypeCode.Decimal, true, true, sb);

            // Act/Assert
            Assert.AreEqual(sb.ToString(), "\b\u000f\u0019\u008e[Òr½o2\u0001\u009a\u0015Ç\0\0\u000e");
        }
Ejemplo n.º 3
0
        public void WriteNumerical_Int16ToSB()
        {
            // Act
            StringBuilder sb = new StringBuilder();

            ABSaveWriter.WriteNumerical(243, TypeCode.Int16, true, true, sb);

            // Act/Assert
            Assert.AreEqual(sb.ToString(), "\u0001ó");
        }
Ejemplo n.º 4
0
        public void Escape_NoNeedToEscapeString()
        {
            // Arrange
            var str = "ab as+_Ag[ag;g[sa]gas'#g;sg['asgas[]lfawa.";

            // Act
            var result = ABSaveWriter.Escape(str);

            // Assert
            Assert.AreEqual(result, str);
        }
Ejemplo n.º 5
0
        public void Escape_OneReasonToEscapeString()
        {
            // Arrange
            var str = "ab as+_Ag[ag;g\u0001[sa]gas'#g;sg['asgas[]lfawa.";

            // Act
            var result = ABSaveWriter.Escape(str);

            // Assert
            Assert.AreEqual(result, "ab as+_Ag[ag;g\\\u0001[sa]gas'#g;sg['asgas[]lfawa.");
        }
Ejemplo n.º 6
0
        public void Escape_ReasonsToEscapeString()
        {
            // Arrange
            var str = "ab as+_Ag[ag;g\u0001[sa]g\u0004as\u0005'#g;sg['\u0003asga\u0005s[]lfa\u0006wa.";

            // Act
            var result = ABSaveWriter.Escape(str);

            // Assert
            Assert.AreEqual(result, "ab as+_Ag[ag;g\\\u0001[sa]g\\\u0004as\\\u0005'#g;sg['\\\u0003asga\\\u0005s[]lfa\\\u0006wa.");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Turns a whole object into an ABSave document, and places the result in a StringBuilder.
        /// </summary>
        /// <param name="obj">The object to convert.</param>
        /// <param name="type">The way of serializing this ABSave (unnamed/named).</param>
        /// <param name="sb">The StringBuilder to write to</param>
        /// <param name="settings">The settings for how to handle certain parts.</param>
        /// <param name="writeHeader">Whether we should write the header in or not.</param>
        public static void ObjectToABSaveDocument(object obj, ABSaveType type, StringBuilder sb, ABSaveSettings settings, bool writeHeader = true)
        {
            // If the type is invalid, throw an exception.
            if (type == ABSaveType.Infer)
            {
                settings.ErrorHandler.InferTypeWhenSerializing();
                return;
            }

            // Write the header.
            ABSaveWriter.WriteHeader(type, sb, settings, writeHeader);

            // Write the actual object.
            ObjectToABSave(obj, type, sb, settings);
        }
Ejemplo n.º 8
0
        static void ConvertVariableToABSave(ABSaveType type, StringBuilder sb, ABSaveSettings settings, Helpers.ABSaveObjectItems members, ref bool notFirst, ref ABSavePrimitiveType lastType, int i)
        {
            // If we're doing it named - write the name.
            if (type == ABSaveType.WithNames)
            {
                // Write the name out, don't write the Next Instruction character if it's the first item or the last item had a "lowerInnerlevel" sign after it.
                ABSaveWriter.WriteString(members.Items[i].Info.Name, ABSaveUtils.RequiresLowerInnerLevelSymbol(lastType) ? false : notFirst, true, sb);

                // Since we've written the name out... And the "notFirst" variable is used to determine whether to write the next instruction symbol or not... Set "notFirst" to true since it will HAVE to have the next instruction symbol now.
                notFirst = true;
            }

            // Serialize each variable, to the StringBuilder. If the last member was an array or object, then instead of getting it to write the
            // "next instruction" character, we need to get it to write the "lower" symbol instead.
            ABSaveSerializer.Serialize(members.Items[i].Value, type, settings, out lastType, true, sb, ABSaveUtils.RequiresLowerInnerLevelSymbol(lastType) ? false : notFirst, i == members.Count - 1);

            // Update the "notFirst" variable if it's false and we've gone through one item.
            if (!notFirst)
            {
                notFirst = true;
            }
        }
Ejemplo n.º 9
0
 public void WriteObjectClose()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteObjectClose(), "\u0005");
 }
Ejemplo n.º 10
0
 public void WriteString_ShouldNotWriteNextItem()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteString("cool", false), "cool");
 }
Ejemplo n.º 11
0
 public void WriteString_ShouldWriteNextItem()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteString("cool", true), "\u0001cool");
 }
Ejemplo n.º 12
0
 public void WriteNextItem_ShouldNotWriteNextItem()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNextItem(false), "");
 }
Ejemplo n.º 13
0
 public void WriteNextItem_ShouldWriteNextItem()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNextItem(true), "\u0001");
 }
Ejemplo n.º 14
0
 public void WriteNumerical_Int64()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNumerical(626136617721, TypeCode.Int64, true), "\b\u0005ù\u0092¦È\u0091");
 }
Ejemplo n.º 15
0
 public void WriteNumerical_Int32()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNumerical(6261, TypeCode.Int32, true), "\u0007u\u0018");
 }
Ejemplo n.º 16
0
 public void WriteDictionaryOpening()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteDictionaryOpening(), "\u0006");
 }
Ejemplo n.º 17
0
 public void WriteNumerical_Float()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNumerical(62613661.36161f, TypeCode.Single, true), "\b\u0004'ÚnL");
 }
Ejemplo n.º 18
0
 public void WriteNumerical_Int16()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNumerical(243, TypeCode.Int16, true), "\u0001ó");
 }
Ejemplo n.º 19
0
 public void WriteObjectOpen()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteObjectOpen(), "\u0003");
 }
Ejemplo n.º 20
0
 public void WriteNumerical_Double()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteNumerical(6261366.36161d, TypeCode.Double, true), "\b\bE\u009e$\u0097\u009dâWA");
 }
Ejemplo n.º 21
0
        private static void NumberExperimenting()
        {
            var num   = 216161;
            var bytes = BitConverter.GetBytes(num);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            Console.ReadLine();
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            var num_recreate = BitConverter.ToInt32(bytes, 0);

            // Convert a decimal to bytes
            Stopwatch watch = Stopwatch.StartNew();

            decimal dec = 261663061631136316003160.1616754194237272794327232324747478442882884282m;

            var decBytes = decimal.GetBits(dec);

            var final = new byte[16];

            BitConverter.GetBytes(decBytes[0]).CopyTo(final, 0);
            BitConverter.GetBytes(decBytes[1]).CopyTo(final, 4);
            BitConverter.GetBytes(decBytes[2]).CopyTo(final, 8);
            BitConverter.GetBytes(decBytes[3]).CopyTo(final, 12);

            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds + ": " + watch.ElapsedTicks);

            // Convert back.
            Stopwatch watch2 = Stopwatch.StartNew();

            var recreate_arr = new int[4];

            recreate_arr[0] = BitConverter.ToInt32(final, 0);
            recreate_arr[1] = BitConverter.ToInt32(final, 4);
            recreate_arr[2] = BitConverter.ToInt32(final, 8);
            recreate_arr[3] = BitConverter.ToInt32(final, 12);

            var finalDec = new decimal(recreate_arr);

            watch2.Stop();


            // Test byte lengths.
            var single = BitConverter.GetBytes(612316f);
            var dou    = BitConverter.GetBytes(362361d);

            while (true)
            {
                var current = ABSaveWriter.WriteNumerical(626136617721, TypeCode.Int64, false);

                Console.WriteLine(watch2.ElapsedMilliseconds + ": " + watch2.ElapsedTicks);
            }


            //BitConverter.
        }
Ejemplo n.º 22
0
 public void WriteArrayOpening()
 {
     // Act/Assert
     Assert.AreEqual(ABSaveWriter.WriteArrayOpening(), "\u0004");
 }