summaryrefslogtreecommitdiffstats
path: root/code/FieldParser.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-13 16:01:56 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-13 16:01:56 +0200
commit1563ae5be6bc130a9b3a23464f7e28fdb1e87da3 (patch)
treeb1f65a03827494fa78e320b134f4cc7df54754bb /code/FieldParser.cpp
parent2017-05-12 (diff)
downloadAltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar.gz
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar.bz2
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar.lz
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar.xz
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.tar.zst
AltCraft-1563ae5be6bc130a9b3a23464f7e28fdb1e87da3.zip
Diffstat (limited to 'code/FieldParser.cpp')
-rw-r--r--code/FieldParser.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/code/FieldParser.cpp b/code/FieldParser.cpp
new file mode 100644
index 0000000..500a973
--- /dev/null
+++ b/code/FieldParser.cpp
@@ -0,0 +1,106 @@
+#include "FieldParser.hpp"
+
+Field FieldParser::Parse(FieldType type, byte *data, size_t len) {
+ switch (type) {
+ case VarInt:
+ return ParseVarInt(data, len);
+ case Boolean:
+ return ParseBool(data, len);
+ case String:
+ return ParseString(data, len);
+ case Long:
+ return ParseLong(data, len);
+ case Int:
+ return ParseInt(data, len);
+ case UnsignedByte:
+ return ParseUByte(data, len);
+ case Byte8_t:
+ return ParseByte(data, len);
+ case Float:
+ return ParseFloat(data, len);
+ case Position:
+ return ParsePosition(data, len);
+ case Double:
+ return ParseDouble(data, len);
+ case ByteArray:
+ return ParseByteArray(data, len);
+ default:
+ throw 105;
+ }
+}
+
+Field FieldParser::ParseString(byte *data, size_t len) {
+ Field fLen = ParseVarInt(data, 0);
+ Field f;
+ f.SetRaw(data, fLen.GetLength() + fLen.GetVarInt(), String);
+ return f;
+}
+
+Field FieldParser::ParseBool(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data,1,Boolean);
+ return f;
+}
+
+Field FieldParser::ParseVarInt(byte *data, size_t len) {
+ if (len != 0) {
+ Field f;
+ f.SetRaw(data, len, VarInt);
+ return f;
+ }
+ int val = VarIntRead(data, len);
+ Field f;
+ f.SetVarInt(val);
+ return f;
+}
+
+Field FieldParser::ParseLong(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 8, Long);
+ return f;
+}
+
+Field FieldParser::ParseInt(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 4, Int);
+ return f;
+}
+
+Field FieldParser::ParseUByte(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 1, UnsignedByte);
+ return f;
+}
+
+Field FieldParser::ParseByte(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 1, Byte8_t);
+ return f;
+}
+
+Field FieldParser::ParseFloat(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 4, Float);
+ return f;
+}
+
+Field FieldParser::ParsePosition(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 8, Position);
+ return f;
+}
+
+Field FieldParser::ParseDouble(byte *data, size_t len) {
+ Field f;
+ f.SetRaw(data, 8, Double);
+ return f;
+}
+
+Field FieldParser::ParseByteArray(byte *data, size_t len) {
+ if (len == 0)
+ throw 119;
+ Field f;
+ f.SetRaw(data, len, Byte8_t);
+ //f.SetRaw(data, len, ByteArray);
+ return f;
+}