aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib/bson
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-10-29 21:46:56 -0700
committerpx4dev <px4@purgatory.org>2012-10-29 21:47:51 -0700
commit0616d5834039cc08057b862f80f8129a7b4948af (patch)
tree3e7359e388c53bc92244773f4a990fabb00ebaf0 /apps/systemlib/bson
parent7203ba797e40b146e7b85b83a6f691e260245a58 (diff)
downloadpx4-firmware-0616d5834039cc08057b862f80f8129a7b4948af.tar.gz
px4-firmware-0616d5834039cc08057b862f80f8129a7b4948af.tar.bz2
px4-firmware-0616d5834039cc08057b862f80f8129a7b4948af.zip
Add 'show' and 'test' verbs to the boardinfo command. Teach rcS how to use the new version.
Diffstat (limited to 'apps/systemlib/bson')
-rw-r--r--apps/systemlib/bson/tinybson.c11
-rw-r--r--apps/systemlib/bson/tinybson.h4
2 files changed, 11 insertions, 4 deletions
diff --git a/apps/systemlib/bson/tinybson.c b/apps/systemlib/bson/tinybson.c
index 1b5a1e1ee..321466f87 100644
--- a/apps/systemlib/bson/tinybson.c
+++ b/apps/systemlib/bson/tinybson.c
@@ -127,13 +127,18 @@ bson_decoder_init_buf(bson_decoder_t decoder, void *buf, unsigned bufsize, bson_
int32_t len;
/* argument sanity */
- if ((buf == NULL) || (bufsize < 5) || (callback == NULL))
+ if ((buf == NULL) || (callback == NULL))
return -1;
decoder->fd = -1;
decoder->buf = (uint8_t *)buf;
decoder->dead = false;
- decoder->bufsize = bufsize;
+ if (bufsize == 0) {
+ decoder->bufsize = *(uint32_t *)buf;
+ debug("auto-detected %u byte object", decoder->bufsize);
+ } else {
+ decoder->bufsize = bufsize;
+ }
decoder->bufpos = 0;
decoder->callback = callback;
decoder->private = private;
@@ -144,7 +149,7 @@ bson_decoder_init_buf(bson_decoder_t decoder, void *buf, unsigned bufsize, bson_
/* read and discard document size */
if (read_int32(decoder, &len))
CODER_KILL(decoder, "failed reading length");
- if ((len > 0) && (len > (int)bufsize))
+ if ((len > 0) && (len > (int)decoder->bufsize))
CODER_KILL(decoder, "document length larger than buffer");
/* ready for decoding */
diff --git a/apps/systemlib/bson/tinybson.h b/apps/systemlib/bson/tinybson.h
index d820aa7b9..666f8191a 100644
--- a/apps/systemlib/bson/tinybson.h
+++ b/apps/systemlib/bson/tinybson.h
@@ -134,7 +134,9 @@ __EXPORT int bson_decoder_init_file(bson_decoder_t decoder, int fd, bson_decoder
*
* @param decoder Decoder state structure to be initialised.
* @param buf Buffer to read from.
- * @param bufsize Size of the buffer (BSON object may be smaller).
+ * @param bufsize Size of the buffer (BSON object may be smaller). May be
+ * passed as zero if the buffer size should be extracted from the
+ * BSON header only.
* @param callback Callback to be invoked by bson_decoder_next
* @param private Callback private data, stored in node.
* @return Zero on success.