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) {
133 len = gu_strlcat(descString,
"leftPoint={", bufferSize);
134 if (len >= bufferSize) {
138 char* leftPoint_p = leftPoint_buffer;
140 len = gu_strlcat(descString, leftPoint_p, bufferSize);
141 if (len >= bufferSize) {
144 len = gu_strlcat(descString,
"}", bufferSize);
145 if (len >= bufferSize) {
148 len = gu_strlcat(descString,
", ", bufferSize);
149 if (len >= bufferSize) {
152 len = gu_strlcat(descString,
"rightPoint={", bufferSize);
153 if (len >= bufferSize) {
157 char* rightPoint_p = rightPoint_buffer;
159 len = gu_strlcat(descString, rightPoint_p, bufferSize);
160 if (len >= bufferSize) {
163 len = gu_strlcat(descString,
"}", bufferSize);
164 if (len >= bufferSize) {
167 len = gu_strlcat(descString,
", ", bufferSize);
168 if (len >= bufferSize) {
171 switch (self->sightingType) {
174 len += snprintf(descString + len, bufferSize - len,
"sightingType=FieldLineSightingType");
179 len += snprintf(descString + len, bufferSize - len,
"sightingType=HorizonLineSightingType");
184#pragma clang diagnostic pop
192#pragma clang diagnostic push
193#pragma clang diagnostic ignored "-Wunused-variable"
195 if (len >= bufferSize) {
198 len = gu_strlcat(toString,
"{", bufferSize);
199 if (len >= bufferSize) {
203 char* leftPoint_p = leftPoint_buffer;
205 len = gu_strlcat(toString, leftPoint_p, bufferSize);
206 if (len >= bufferSize) {
209 len = gu_strlcat(toString,
"}", bufferSize);
210 if (len >= bufferSize) {
213 len = gu_strlcat(toString,
", ", bufferSize);
214 if (len >= bufferSize) {
217 len = gu_strlcat(toString,
"{", bufferSize);
218 if (len >= bufferSize) {
222 char* rightPoint_p = rightPoint_buffer;
224 len = gu_strlcat(toString, rightPoint_p, bufferSize);
225 if (len >= bufferSize) {
228 len = gu_strlcat(toString,
"}", bufferSize);
229 if (len >= bufferSize) {
232 len = gu_strlcat(toString,
", ", bufferSize);
233 if (len >= bufferSize) {
236 switch (self->sightingType) {
239 len += snprintf(toString + len, bufferSize - len,
"FieldLineSightingType");
244 len += snprintf(toString + len, bufferSize - len,
"HorizonLineSightingType");
249#pragma clang diagnostic pop
257 size_t temp_length = strlen(str);
258 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
263 char* var_str = &var_str_buffer[0];
265 char* key = &key_buffer[0];
272 if (index == 0 && str[0] ==
'{') {
278 for (
int i = index; i < length; i++) {
280 if (bracecount == 0 && str[i] ==
'=') {
285 if (bracecount == 0 && isspace(str[i])) {
292 if (bracecount == 0 && str[i] ==
',') {
302 if (bracecount < 0) {
307 if (i == length - 1) {
311 if (endKey >= startKey && endKey - startKey < length) {
312 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
313 key[(endKey - startKey) + 1] = 0;
317 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
318 var_str[(index - startVar) + 1] = 0;
324 if (strlen(key) > 0) {
325 if (0 == strcmp(
"leftPoint", key)) {
327 }
else if (0 == strcmp(
"rightPoint", key)) {
329 }
else if (0 == strcmp(
"sightingType", key)) {
349 if (strcmp(
"FieldLineSightingType", var_str) == 0) {
350#pragma clang diagnostic push
351#pragma clang diagnostic ignored "-Wbad-function-cast"
353#pragma clang diagnostic pop
354 }
else if (strcmp(
"HorizonLineSightingType", var_str) == 0) {
355#pragma clang diagnostic push
356#pragma clang diagnostic ignored "-Wbad-function-cast"
358#pragma clang diagnostic pop
360#pragma clang diagnostic push
361#pragma clang diagnostic ignored "-Wbad-function-cast"
363#pragma clang diagnostic pop
371 }
while(index < length);
382 uint16_t bit_offset = 0;
386 for (b = (32 - 1); b >= 0; b--) {
388 uint16_t
byte = bit_offset / 8;
389 uint16_t bit = 7 - (bit_offset % 8);
390 unsigned long newbit = !!((sightingType_nbo >> b) & 1U);
391 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
392 bit_offset = bit_offset + 1;
407 uint16_t bit_offset = 0;
410 for (b = (32 - 1); b >= 0; b--) {
412 uint16_t
byte = bit_offset / 8;
413 uint16_t bit = 7 - (bit_offset % 8);
414 char dataByte = src[byte];
415 unsigned char bitValue = (dataByte >> bit) & 1U;
417 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
enum LineSightingType sightingType
The type of sighting.
const char * wb_line_sighting_description(const struct wb_line_sighting *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_line_sighting_to_network_serialised(const struct wb_line_sighting *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_line_sighting_to_string(const struct wb_line_sighting *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_line_sighting_from_network_serialised(const char *src, struct wb_line_sighting *dst)
Convert from a compressed, serialised, network byte order byte stream.
struct wb_line_sighting * wb_line_sighting_from_string(struct wb_line_sighting *self, const char *str)
Convert from a string.
@ HorizonLineSightingType
#define LINE_SIGHTING_DESC_BUFFER_SIZE
struct wb_polar_coordinate * wb_polar_coordinate_from_string(struct wb_polar_coordinate *self, const char *str)
Convert from a string.
const char * wb_polar_coordinate_to_string(const struct wb_polar_coordinate *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_polar_coordinate_description(const struct wb_polar_coordinate *self, char *descString, size_t bufferSize)
Convert to a description string.
#define POLAR_COORDINATE_DESC_BUFFER_SIZE
#define POLAR_COORDINATE_TO_STRING_BUFFER_SIZE