60#ifndef WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
77#elif defined(__APPLE__)
78# include <machine/endian.h>
79# include <architecture/byte_order.h>
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
91#if (!defined(__BYTE_ORDER) && !defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
92# if !defined(htonll) && !defined(ntohll)
93# define htonll(x) bswap_64(x)
94# define ntohll(x) bswap_64(x)
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
109# if !defined(htonl) && !defined(ntohl)
113# if !defined(htons) && !defined(ntohs)
118#pragma clang diagnostic pop
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
130 if (len >= bufferSize) {
134 len += snprintf(descString + len, bufferSize - len,
"count=%lld", self->count);
136 len += snprintf(descString + len, bufferSize - len,
"count=%ld", self->count);
139#pragma clang diagnostic pop
147#pragma clang diagnostic push
148#pragma clang diagnostic ignored "-Wunused-variable"
150 if (len >= bufferSize) {
154 len += snprintf(toString + len, bufferSize - len,
"%lld", self->count);
156 len += snprintf(toString + len, bufferSize - len,
"%ld", self->count);
159#pragma clang diagnostic pop
167 size_t temp_length = strlen(str);
168 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
173 char* var_str = &var_str_buffer[0];
175 char* key = &key_buffer[0];
182 if (index == 0 && str[0] ==
'{') {
188 for (
int i = index; i < length; i++) {
190 if (bracecount == 0 && str[i] ==
'=') {
195 if (bracecount == 0 && isspace(str[i])) {
202 if (bracecount == 0 && str[i] ==
',') {
212 if (bracecount < 0) {
217 if (i == length - 1) {
221 if (endKey >= startKey && endKey - startKey < length) {
222 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
223 key[(endKey - startKey) + 1] = 0;
227 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
228 var_str[(index - startVar) + 1] = 0;
234 if (strlen(key) > 0) {
235 if (0 == strcmp(
"count", key)) {
246 self->count = ((int64_t)atoll(var_str));
248 self->count = ((int64_t)atol(var_str));
256 }
while(index < length);
267 uint16_t bit_offset = 0;
268 int64_t count_nbo =
htonll(self->count);
271 for (b = (64 - 1); b >= 0; b--) {
273 uint16_t
byte = bit_offset / 8;
274 uint16_t bit = 7 - (bit_offset % 8);
275 unsigned long newbit = !!((count_nbo >> b) & 1U);
276 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
277 bit_offset = bit_offset + 1;
292 uint16_t bit_offset = 0;
295 for (b = (64 - 1); b >= 0; b--) {
297 uint16_t
byte = bit_offset / 8;
298 uint16_t bit = 7 - (bit_offset % 8);
299 char dataByte = src[byte];
300 unsigned char bitValue = (dataByte >> bit) & 1U;
301 dst->
count ^= (-bitValue ^ dst->
count) & (1UL << b);
302 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
size_t wb_count_from_network_serialised(const char *src, struct wb_count *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_count_to_string(const struct wb_count *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_count_description(const struct wb_count *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_count_to_network_serialised(const struct wb_count *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
struct wb_count * wb_count_from_string(struct wb_count *self, const char *str)
Convert from a string.
#define COUNT_DESC_BUFFER_SIZE