aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib/bson
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-10-23 23:38:45 -0700
committerpx4dev <px4@purgatory.org>2012-10-23 23:51:13 -0700
commit2fc10320697ecaa9c4e0c52d4d047424e41e6336 (patch)
tree4f18f494ab811e29dc55452f92a63fff9d271dda /apps/systemlib/bson
parent34f99c7dca1995f8ddd9e8d61c4cbd7289f40e99 (diff)
downloadpx4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.tar.gz
px4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.tar.bz2
px4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.zip
Major formatting/whitespace cleanup
Diffstat (limited to 'apps/systemlib/bson')
-rw-r--r--apps/systemlib/bson/tinybson.c24
-rw-r--r--apps/systemlib/bson/tinybson.h27
2 files changed, 33 insertions, 18 deletions
diff --git a/apps/systemlib/bson/tinybson.c b/apps/systemlib/bson/tinybson.c
index 10b736fd6..75578d2ec 100644
--- a/apps/systemlib/bson/tinybson.c
+++ b/apps/systemlib/bson/tinybson.c
@@ -56,7 +56,7 @@
static int
read_int8(bson_decoder_t decoder, int8_t *b)
{
- return (read(decoder->fd, b, sizeof(*b)) == sizeof(*b)) ? 0 : -1;
+ return (read(decoder->fd, b, sizeof(*b)) == sizeof(*b)) ? 0 : -1;
}
static int
@@ -119,12 +119,14 @@ bson_decoder_next(bson_decoder_t decoder)
while (decoder->pending > 0) {
if (read_int8(decoder, &tbyte))
CODER_KILL(decoder, "read error discarding pending bytes");
+
decoder->pending--;
}
/* get the type byte */
if (read_int8(decoder, &tbyte))
CODER_KILL(decoder, "read error on type byte");
+
decoder->node.type = tbyte;
decoder->pending = 0;
@@ -135,13 +137,17 @@ bson_decoder_next(bson_decoder_t decoder)
/* get the node name */
nlen = 0;
+
for (;;) {
if (nlen >= BSON_MAXNAME)
CODER_KILL(decoder, "node name overflow");
+
if (read_int8(decoder, (int8_t *)&decoder->node.name[nlen]))
CODER_KILL(decoder, "read error on node name");
+
if (decoder->node.name[nlen] == '\0')
break;
+
nlen++;
}
@@ -151,20 +157,28 @@ bson_decoder_next(bson_decoder_t decoder)
case BSON_INT:
if (read_int32(decoder, &decoder->node.i))
CODER_KILL(decoder, "read error on BSON_INT");
+
break;
+
case BSON_DOUBLE:
if (read_double(decoder, &decoder->node.d))
CODER_KILL(decoder, "read error on BSON_DOUBLE");
+
break;
+
case BSON_STRING:
if (read_int32(decoder, &decoder->pending))
CODER_KILL(decoder, "read error on BSON_STRING length");
+
break;
+
case BSON_BINDATA:
if (read_int32(decoder, &decoder->pending))
CODER_KILL(decoder, "read error on BSON_BINDATA size");
+
if (read_int8(decoder, &tbyte))
CODER_KILL(decoder, "read error on BSON_BINDATA subtype");
+
decoder->node.subtype = tbyte;
break;
@@ -186,11 +200,12 @@ bson_decoder_copy_data(bson_decoder_t decoder, void *buf)
CODER_CHECK(decoder);
/* if data already copied, return zero bytes */
- if (decoder->pending == 0)
+ if (decoder->pending == 0)
return 0;
/* copy bytes per the node size */
result = read(decoder->fd, buf, decoder->pending);
+
if (result != decoder->pending)
CODER_KILL(decoder, "read error on copy_data");
@@ -209,7 +224,7 @@ static int
write_int8(bson_encoder_t encoder, int8_t b)
{
debug("write_int8 %d", b);
- return (write(encoder->fd, &b, sizeof(b)) == sizeof(b)) ? 0 : -1;
+ return (write(encoder->fd, &b, sizeof(b)) == sizeof(b)) ? 0 : -1;
}
static int
@@ -233,6 +248,7 @@ write_name(bson_encoder_t encoder, const char *name)
if (len > BSON_MAXNAME)
return -1;
+
debug("write name '%s' len %d", name, len);
return (write(encoder->fd, name, len + 1) == (int)(len + 1)) ? 0 : -1;
}
@@ -300,6 +316,7 @@ bson_encoder_append_string(bson_encoder_t encoder, const char *name, const char
write_int32(encoder, len) ||
write(encoder->fd, name, len + 1) != (int)(len + 1))
CODER_KILL(encoder, "write error on BSON_STRING");
+
return 0;
}
@@ -314,5 +331,6 @@ bson_encoder_append_binary(bson_encoder_t encoder, const char *name, bson_binary
write_int8(encoder, subtype) ||
write(encoder->fd, data, size) != (int)(size))
CODER_KILL(encoder, "write error on BSON_BINDATA");
+
return 0;
}
diff --git a/apps/systemlib/bson/tinybson.h b/apps/systemlib/bson/tinybson.h
index 1b9de5cd3..b6229dc50 100644
--- a/apps/systemlib/bson/tinybson.h
+++ b/apps/systemlib/bson/tinybson.h
@@ -31,14 +31,14 @@
*
****************************************************************************/
- /**
- * @file tinybson.h
- *
- * A simple subset SAX-style BSON parser and generator. See http://bsonspec.org
- *
- * Some types and defines taken from the standalone BSON parser/generator
- * in the Mongo C connector.
- */
+/**
+* @file tinybson.h
+*
+* A simple subset SAX-style BSON parser and generator. See http://bsonspec.org
+*
+* Some types and defines taken from the standalone BSON parser/generator
+* in the Mongo C connector.
+*/
#ifndef _TINYBSON_H
#define _TINYBSON_H
@@ -77,8 +77,7 @@ typedef enum bson_binary_subtype {
/**
* Node structure passed to the callback.
*/
-typedef struct bson_node_s
-{
+typedef struct bson_node_s {
char name[BSON_MAXNAME];
bson_type_t type;
bson_binary_subtype_t subtype;
@@ -96,8 +95,7 @@ typedef struct bson_decoder_s *bson_decoder_t;
*/
typedef int (* bson_decoder_callback)(bson_decoder_t decoder, void *private, bson_node_t node);
-struct bson_decoder_s
-{
+struct bson_decoder_s {
int fd;
bson_decoder_callback callback;
void *private;
@@ -143,8 +141,7 @@ __EXPORT size_t bson_decoder_data_pending(bson_decoder_t decoder);
/**
* Encoder state structure.
*/
-typedef struct bson_encoder_s
-{
+typedef struct bson_encoder_s {
int fd;
} *bson_encoder_t;
@@ -169,7 +166,7 @@ __EXPORT int bson_encoder_append_int(bson_encoder_t encoder, const char *name, i
*/
__EXPORT int bson_encoder_append_double(bson_encoder_t encoder, const char *name, double value);
-/**
+/**
* Append a string to the encoded stream.
*/
__EXPORT int bson_encoder_append_string(bson_encoder_t encoder, const char *name, const char *string);