diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 14:04:47 -0700 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 14:04:47 -0700 |
commit | fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975 (patch) | |
tree | f16f7e7f54399ef9c753beb87069eed8122dbccb /src/unstable/uuid.cpp | |
parent | d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3 (diff) | |
download | libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.gz libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.bz2 libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.xz libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.zip |
Gradually moving to better archive structure.
It's dragging other new API changes along with it, including use of Blob
and Text.
Diffstat (limited to 'src/unstable/uuid.cpp')
-rw-r--r-- | src/unstable/uuid.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index 6642d75..9708423 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp | |||
@@ -10,6 +10,8 @@ | |||
10 | #include "bu/formatter.h" | 10 | #include "bu/formatter.h" |
11 | #include "bu/membuf.h" | 11 | #include "bu/membuf.h" |
12 | #include "bu/random.h" | 12 | #include "bu/random.h" |
13 | #include "bu/archive.h" | ||
14 | #include "bu/blobbuilder.h" | ||
13 | #include <string.h> | 15 | #include <string.h> |
14 | 16 | ||
15 | #ifdef WIN32 | 17 | #ifdef WIN32 |
@@ -27,11 +29,11 @@ Bu::Uuid::Uuid( const Uuid &src ) | |||
27 | memcpy( data, src.data, 16 ); | 29 | memcpy( data, src.data, 16 ); |
28 | } | 30 | } |
29 | 31 | ||
30 | Bu::Uuid::Uuid( const Bu::String &sSrc ) | 32 | Bu::Uuid::Uuid( const Bu::Blob &sSrc ) |
31 | { | 33 | { |
32 | if( sSrc.getSize() == 16 ) | 34 | if( sSrc.getSize() == 16 ) |
33 | { | 35 | { |
34 | memcpy( data, sSrc.getStr(), 16 ); | 36 | memcpy( data, sSrc.getData(), 16 ); |
35 | } | 37 | } |
36 | else if( sSrc.getSize() == 36 ) | 38 | else if( sSrc.getSize() == 36 ) |
37 | { | 39 | { |
@@ -44,12 +46,12 @@ Bu::Uuid::~Uuid() | |||
44 | { | 46 | { |
45 | } | 47 | } |
46 | 48 | ||
47 | Bu::String Bu::Uuid::toRawString() const | 49 | Bu::Blob Bu::Uuid::toRawBlob() const |
48 | { | 50 | { |
49 | return Bu::String( (char *)data, 16 ); | 51 | return Bu::Blob( (char *)data, 16 ); |
50 | } | 52 | } |
51 | 53 | ||
52 | Bu::String Bu::Uuid::toString() const | 54 | Bu::Blob Bu::Uuid::toBlob() const |
53 | { | 55 | { |
54 | Bu::MemBuf mb; | 56 | Bu::MemBuf mb; |
55 | Bu::Formatter f( mb ); | 57 | Bu::Formatter f( mb ); |
@@ -61,12 +63,14 @@ Bu::String Bu::Uuid::toString() const | |||
61 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; | 63 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; |
62 | } | 64 | } |
63 | 65 | ||
64 | return mb.getString(); | 66 | return mb.getBlob(); |
65 | } | 67 | } |
66 | 68 | ||
67 | Bu::String Bu::Uuid::toUrn() const | 69 | Bu::Blob Bu::Uuid::toUrn() const |
68 | { | 70 | { |
69 | return "urn:uuid:" + toString(); | 71 | BlobBuilder bb("urn:uuid:"); |
72 | bb.append( toBlob() ); | ||
73 | return bb.getBlob(); | ||
70 | } | 74 | } |
71 | 75 | ||
72 | int Bu::Uuid::getVersion() | 76 | int Bu::Uuid::getVersion() |
@@ -129,9 +133,9 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) | |||
129 | return id; | 133 | return id; |
130 | } | 134 | } |
131 | 135 | ||
132 | void Bu::Uuid::set( const Bu::String &sSrc ) | 136 | void Bu::Uuid::set( const Bu::Blob &sSrc ) |
133 | { | 137 | { |
134 | const char *dat = sSrc.getStr(); | 138 | const char *dat = sSrc.getData(); |
135 | int iNibble = 0; | 139 | int iNibble = 0; |
136 | memset( data, 0, 16 ); | 140 | memset( data, 0, 16 ); |
137 | for( int j = 0; j < 36; j++ ) | 141 | for( int j = 0; j < 36; j++ ) |
@@ -162,7 +166,7 @@ Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs ) | |||
162 | 166 | ||
163 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) | 167 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) |
164 | { | 168 | { |
165 | return __calcHashCode<String>( k.toRawString() ); | 169 | return __calcHashCode<Blob>( k.toRawBlob() ); |
166 | } | 170 | } |
167 | 171 | ||
168 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) | 172 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) |
@@ -172,18 +176,20 @@ template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid & | |||
172 | 176 | ||
173 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) | 177 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) |
174 | { | 178 | { |
175 | ar.read( u.data, 16 ); | 179 | Bu::Blob b; |
180 | ar >> b; | ||
181 | memcpy( b.getData(), u.data, 16 ); | ||
176 | return ar; | 182 | return ar; |
177 | } | 183 | } |
178 | 184 | ||
179 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) | 185 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) |
180 | { | 186 | { |
181 | ar.write( u.data, 16 ); | 187 | ar << u.toRawBlob(); |
182 | return ar; | 188 | return ar; |
183 | } | 189 | } |
184 | 190 | ||
185 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) | 191 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) |
186 | { | 192 | { |
187 | return f << u.toString(); | 193 | return f << u.toBlob(); |
188 | } | 194 | } |
189 | 195 | ||