public byte[] GetBytes()
        {
            MemoryStream stream = new MemoryStream();

            BinaryWriter writer = new BinaryWriter(stream);

            switch (DataType)
            {
            case 2: writer.Write((double)(Data)); break;

            case 3: writer.Write((bool)(Data)); break;

            case 4: PackedInt.SaveToBin((PackedInt)Data, writer); break;

            case 5: writer.Write(Data.ToString()); break;

            case 6: PackedVariant.SaveToBin((PackedVariant)Data, writer); break;

            case 7: VariantDict.SaveToBin((VariantDict)Data, writer); break;
            }

            writer.Close();

            BinaryReader reader = new BinaryReader(stream);

            long length = stream.Length;

            byte[] result = reader.ReadBytes((int)length);

            return(result);
        }
Esempio n. 2
0
        public static void SaveToBin(PackedVariant item, BinaryWriter writer)
        {
            PackedInt.SaveToBin(new PackedInt()
            {
                Value = (ulong)item.Variants.Count
            }, writer);

            for (int i = 0; i < item.Variants.Count; i++)
            {
                Variant.SaveToBin(item.Variants[i], writer);
            }
        }
Esempio n. 3
0
        public static PackedVariant LoadFromBin(BinaryReader reader)
        {
            PackedVariant result = new PackedVariant();

            PackedInt numVariants = PackedInt.LoadFromBin(reader);

            for (ulong i = 0; i < numVariants.Value; i++)
            {
                result.Variants.Add(Variant.LoadFromBin(reader));
            }

            return(result);
        }
        public static Variant LoadFromBin(BinaryReader reader)
        {
            Variant result = new Variant();

            result.DataType = reader.ReadByte();

            switch (result.DataType)
            {
            case 2: result.Data = reader.ReadDouble(); break;

            case 3: result.Data = reader.ReadBoolean(); break;

            case 4: result.Data = PackedInt.LoadFromBin(reader); break;

            case 5: result.Data = StringIO.LoadFromBin(reader); break;

            case 6: result.Data = PackedVariant.LoadFromBin(reader); break;

            case 7: result.Data = VariantDict.LoadFromBin(reader); break;
            }

            return(result);
        }