summaryrefslogtreecommitdiffstats
path: root/code/Field.hpp
blob: 43769dcea53dd3be6fb25deaa695ae741fb30ec0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
#include "utility.h"
#include "PositionI.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);

    PositionI GetPosition();

    void SetPosition(PositionI 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;
};