diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-18 16:03:05 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-18 16:03:05 +0200 |
commit | 4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79 (patch) | |
tree | 548911d4e341fd5717acff3b5bc752c7b5650bf4 /src/packet/Field.hpp | |
parent | 2017-05-13 (diff) | |
download | AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.gz AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.bz2 AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.lz AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.xz AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.zst AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.zip |
Diffstat (limited to 'src/packet/Field.hpp')
-rw-r--r-- | src/packet/Field.hpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/packet/Field.hpp b/src/packet/Field.hpp new file mode 100644 index 0000000..8be9c9b --- /dev/null +++ b/src/packet/Field.hpp @@ -0,0 +1,119 @@ +#pragma once + +#include <cstddef> +#include <cstdint> +#include <string> +#include <vector> +#include "../utility/utility.h" +#include "../utility/Vector.hpp" + +typedef unsigned char byte; +typedef signed char sbyte; + +enum FieldType { + Unknown = 0, + Boolean, //Bool + Byte8_t, //int8_t + UnsignedByte, //uint8_t + Short, //int16_t + UnsignedShort, //uint16_t + Int, //int32_t + Long, //int64_t + Float, //float + Double, //double + Position, //PositionI + Angle, //uint8_t + Uuid, //byte* (2 bytes) + //Unknown-length data + + String = 100, //std::string + Chat, //std::string + VarInt, //int32_t + VarLong, //int64_t + ChunkSection, //byte* + EntityMetadata, //byte* + Slot, //byte* + NbtTag, //byte* + ByteArray, //byte* +}; + +class Field { +public: + Field(); + + Field(const Field &other); + + void swap(Field &other); + + Field &operator=(Field other); + + ~Field(); + + size_t GetLength(); + + void Clear(); + + void CopyToBuff(byte *ptr); + + void SetRaw(byte *ptr, size_t len = 0, FieldType type = Unknown); + + FieldType GetType(); + + void Attach(Field field); + + static size_t GetFieldLength(FieldType type); + + //Cpp-types setters/getters for binary content of MC's data types + + int GetVarInt(); + + void SetVarInt(int value); + + int GetInt(); + + void SetInt(int value); + + bool GetBool(); + + void SetBool(bool value); + + unsigned short GetUShort(); + + void SetUShort(unsigned short value); + + std::string GetString(); + + void SetString(std::string value); + + long long GetLong(); + + void SetLong(long long value); + + byte GetUByte(); + + void SetUByte(byte value); + + sbyte GetByte(); + + void SetByte(sbyte value); + + float GetFloat(); + + void SetFloat(float value); + + Vector GetPosition(); + + void SetPosition(Vector value); + + double GetDouble(); + + void SetDouble(double value); + + std::vector<Field> GetArray(); + +private: + size_t m_dataLength = 0; + byte *m_data = nullptr; + FieldType m_type = Unknown; + std::vector<Field> m_childs; +}; |