-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtdClassId.cpp
84 lines (69 loc) · 1.44 KB
/
ArtdClassId.cpp
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
#include "artd/ArtdClassId.h"
#include "artd/pointer_math.h"
#include "artd/HexFormatter.h"
#include <stdlib.h>
#include <string.h>
#include "artd/RcArray.h"
ARTD_BEGIN
ArtdClassId &
ArtdClassId::operator=(const ArtdClassId &from) noexcept {
if (this != &from) {
length_ = from.length_;
::memcpy(bytes_,from.bytes_,sizeof(bytes_));
} else {
setNull();
}
return(*this);
}
ArtdClassId::ArtdClassId(int length, const char *bytes) {
if (length > MaxLength) {
length = MaxLength;
}
length_ = length;
--bytes; // to compensate for extra first byte
while (length > 0) {
bytes_[length] = bytes[length];
--length;
}
bytes_[0] = GlobalDomain;
}
void
ArtdClassId::setFromBytes(const void *data, int length) {
if(length > MaxLength) {
length = MaxLength;
}
length_ = length;
::memcpy(&bytes_[1], data, length);
bytes_[0] = GlobalDomain;
}
int
ArtdClassId::getBytes(void *data) const {
::memcpy(data, &bytes_[1], length_);
return(length_);
}
ByteArray
ArtdClassId::getBytes() const {
ByteArray ret(length_);
getBytes(ret.data());
return(ret);
}
int
ArtdClassId::equals(const ArtdClassId &b) const {
if(isNull(b)) {
return(false);
}
int ret = 1;
if (length_ == b.length_) {
ret = ::memcmp(&bytes_, &b.bytes_, length_);
}
if(ret) {
return(false);
}
return(true);
}
RcString
ArtdClassId::toString() const {
static RcString nul("[null]");
return(length_ == 0 ? nul : HexFormatter::binToHex(&bytes_[1], length_));
}
ARTD_END