Kùzu C++ API
Loading...
Searching...
No Matches
blob.h
Go to the documentation of this file.
1#pragma once
2
3#include "ku_string.h"
4
5namespace kuzu {
6namespace common {
7
8struct blob_t {
10};
11
13 // map of integer -> hex value.
14 static constexpr const char* HEX_TABLE = "0123456789ABCDEF";
15 // reverse map of byte -> integer value, or -1 for invalid hex values.
16 static const int HEX_MAP[256];
17 static constexpr const uint64_t NUM_BYTES_TO_SHIFT_FOR_FIRST_BYTE = 4;
18 static constexpr const uint64_t SECOND_BYTE_MASK = 0x0F;
19 static constexpr const char PREFIX[] = "\\x";
20 static constexpr const uint64_t PREFIX_LENGTH = 2;
21 static constexpr const uint64_t FIRST_BYTE_POS = PREFIX_LENGTH;
22 static constexpr const uint64_t SECOND_BYTES_POS = PREFIX_LENGTH + 1;
23 static constexpr const uint64_t LENGTH = 4;
24};
25
26struct Blob {
27 static std::string toString(const uint8_t* value, uint64_t len);
28
29 static inline std::string toString(const blob_t& blob) {
30 return toString(blob.value.getData(), blob.value.len);
31 }
32
33 static uint64_t getBlobSize(const ku_string_t& blob);
34
35 static uint64_t fromString(const char* str, uint64_t length, uint8_t* resultBuffer);
36
37 template<typename T>
38 static inline T getValue(const blob_t& data) {
39 return *reinterpret_cast<const T*>(data.value.getData());
40 }
41 template<typename T>
42 // NOLINTNEXTLINE(readability-non-const-parameter): Would cast away qualifiers.
43 static inline T getValue(char* data) {
44 return *reinterpret_cast<T*>(data);
45 }
46
47private:
48 static void validateHexCode(const uint8_t* blobStr, uint64_t length, uint64_t curPos);
49};
50
51} // namespace common
52} // namespace kuzu
Definition alter_type.h:5
Definition blob.h:26
static uint64_t getBlobSize(const ku_string_t &blob)
static T getValue(char *data)
Definition blob.h:43
static uint64_t fromString(const char *str, uint64_t length, uint8_t *resultBuffer)
static std::string toString(const uint8_t *value, uint64_t len)
static T getValue(const blob_t &data)
Definition blob.h:38
static std::string toString(const blob_t &blob)
Definition blob.h:29
static constexpr const char PREFIX[]
Definition blob.h:19
static constexpr const uint64_t PREFIX_LENGTH
Definition blob.h:20
static constexpr const uint64_t LENGTH
Definition blob.h:23
static constexpr const uint64_t FIRST_BYTE_POS
Definition blob.h:21
static constexpr const uint64_t SECOND_BYTES_POS
Definition blob.h:22
static constexpr const uint64_t SECOND_BYTE_MASK
Definition blob.h:18
static constexpr const uint64_t NUM_BYTES_TO_SHIFT_FOR_FIRST_BYTE
Definition blob.h:17
static constexpr const char * HEX_TABLE
Definition blob.h:14
static const int HEX_MAP[256]
Definition blob.h:16
Definition blob.h:8
ku_string_t value
Definition blob.h:9
Definition ku_string.h:12
uint32_t len
Definition ku_string.h:18
const uint8_t * getData() const
Definition ku_string.h:30