コード例 #1
0
        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);
        }
コード例 #2
0
        public static void SaveToBin(VariantDict item, BinaryWriter writer)
        {
            PackedInt.SaveToBin(new PackedInt()
            {
                Value = (ulong)item.Dict.Count
            }, writer);

            foreach (KeyValuePair <string, Variant> kvp in item.Dict)
            {
                StringIO.SaveToBin(kvp.Key, writer);
                Variant.SaveToBin(kvp.Value, writer);
            }
        }
コード例 #3
0
        public static VariantDict LoadFromBin(BinaryReader reader)
        {
            VariantDict result = new VariantDict();

            PackedInt numDictKeys = PackedInt.LoadFromBin(reader);

            for (ulong i = 0; i < numDictKeys.Value; i++)
            {
                string  key     = StringIO.LoadFromBin(reader);
                Variant variant = Variant.LoadFromBin(reader);
                result.Dict.Add(key, variant);
            }

            return(result);
        }
コード例 #4
0
        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);
        }