Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Field.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "Field.h"
7#include "Errors.h"
8
10{
11 data.value = nullptr;
12 data.type = MYSQL_TYPE_NULL;
13 data.length = 0;
14 data.raw = false;
15}
16
18{
19 CleanUp();
20}
21
22void Field::SetByteValue(const void* newValue, const size_t newSize, enum_field_types newType, uint32 length)
23{
24 if (data.value)
25 CleanUp();
26
27 // This value stores raw bytes that have to be explicitly casted later
28 if (newValue)
29 {
30 data.value = new char[newSize];
31 memcpy(data.value, newValue, newSize);
32 data.length = length;
33 }
34 data.type = newType;
35 data.raw = true;
36}
37
38void Field::SetStructuredValue(char* newValue, enum_field_types newType, uint32 length)
39{
40 if (data.value)
41 CleanUp();
42
43 // This value stores somewhat structured data that needs function style casting
44 if (newValue)
45 {
46 data.value = new char[length + 1];
47 memcpy(data.value, newValue, length);
48 *(reinterpret_cast<char*>(data.value) + length) = '\0';
49 data.length = length;
50 }
51
52 data.type = newType;
53 data.raw = false;
54}
55
56std::vector<uint8> Field::GetBinary() const
57{
58 std::vector<uint8> result;
59 if (!data.value || !data.length)
60 return result;
61
62 result.resize(data.length);
63 memcpy(result.data(), data.value, data.length);
64 return result;
65}
66
68{
69 ASSERT(data.value && (data.length == length));
70 memcpy(buf, data.value, length);
71}
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define ASSERT
Definition Errors.h:29
void CleanUp()
Definition Field.h:286
void SetByteValue(void const *newValue, size_t const newSize, enum_field_types newType, uint32 length)
Definition Field.cpp:22
uint32 length
Definition Field.h:272
Field()
Definition Field.cpp:9
~Field()
Definition Field.cpp:17
std::vector< uint8 > GetBinary() const
Definition Field.cpp:56
struct Field::@103301115010007122255114047010240314374313114334 data
void GetBinarySizeChecked(uint8 *buf, size_t size) const
Definition Field.cpp:67
void SetStructuredValue(char *newValue, enum_field_types newType, uint32 length)
Definition Field.cpp:38