Add Float and Double

This commit is contained in:
BtbN
2019-04-17 17:01:17 +02:00
parent e932c1ce1c
commit b69652dc3f
2 changed files with 49 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ using System.Reflection;
using System.Net;
using System.Text;
using System.Collections;
using System.Globalization;
namespace eAmuseCore.KBinXML.XmlTypes
{
@@ -162,6 +163,52 @@ namespace eAmuseCore.KBinXML.XmlTypes
}
}
[KValue(14, "float", "f", Count = 1, Size = 4)]
public class KFloat : KValue<float>
{
public KFloat(float value) => Value = value;
public override string ToString()
{
return Value.ToString(CultureInfo.InvariantCulture);
}
public override IEnumerable<byte> ToBytes()
{
IEnumerable<byte> res = BitConverter.GetBytes(Value);
if (BitConverter.IsLittleEndian)
res = res.Reverse();
return res;
}
static public KFloat FromString(string input) => new KFloat(Convert.ToSingle(input, CultureInfo.InvariantCulture));
static public KFloat FromBytes(IEnumerable<byte> input) => new KFloat(input.FirstF());
}
[KValue(15, "double", "d", Count = 1, Size = 8)]
public class KDouble : KValue<double>
{
public KDouble(double value) => Value = value;
public override string ToString()
{
return Value.ToString(CultureInfo.InvariantCulture);
}
public override IEnumerable<byte> ToBytes()
{
IEnumerable<byte> res = BitConverter.GetBytes(Value);
if (BitConverter.IsLittleEndian)
res = res.Reverse();
return res;
}
static public KDouble FromString(string input) => new KDouble(Convert.ToDouble(input, CultureInfo.InvariantCulture));
static public KDouble FromBytes(IEnumerable<byte> input) => new KDouble(input.FirstD());
}
[KValue(27, "3u8", Count = 3, Size = 1)]
public class K3U8 : KValueList<U8>
{
@@ -207,7 +254,7 @@ namespace eAmuseCore.KBinXML.XmlTypes
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
KValueAttribute attr = type.GetCustomAttribute<KValueAttribute>(true);
KValueAttribute attr = type.GetCustomAttribute<KValueAttribute>(false);
if (attr == null)
continue;

View File

@@ -46,9 +46,7 @@ namespace eAmuseTest
else if (compress != "none")
throw new ArgumentException("Unsupported compression algorithm");
Console.WriteLine(BytesToString(BitConverter.GetBytes((byte)1)));
KBinXML kbinxml = new KBinXML(rawData);
//KBinXML kbinxml = new KBinXML(rawData);
KBinXML testDoc = new KBinXML(ExtractResource("eAmuseTest.testcases_out.kbin"));
}