Ejemplo n.º 1
0
void mongo_node_updateBlocks(node_t *node) {
	bson_t *query;
	bson_t *update;

	mongo_node_checkInit();

	query = BCON_NEW("_id", BCON_UTF8(node->id));
	update = BCON_NEW("$set", "{", "blocks", BCON_BIN(BSON_SUBTYPE_BINARY, (const uint8_t * ) node->blocks->bitarray, node->blocks->size), "blocksCount", BCON_INT32(node->blocksCount), "}");

	mongo_update(nodeCollection, query, update);
}
Ejemplo n.º 2
0
static void
test_binary (void)
{
   bson_subtype_t subtype;
   uint32_t len;
   const uint8_t *binary;

   bson_t *bcon = BCON_NEW (
      "foo", BCON_BIN (BSON_SUBTYPE_BINARY, (uint8_t *) "deadbeef", 8));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_BIN (subtype, binary, len)));

   assert (subtype == BSON_SUBTYPE_BINARY);
   assert (len == 8);
   assert (memcmp (binary, "deadbeef", 8) == 0);

   bson_destroy (bcon);
}
Ejemplo n.º 3
0
static void
test_binary (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_binary (
      &expected, "foo", -1, BSON_SUBTYPE_BINARY, (uint8_t *) "deadbeef", 8);

   BCON_APPEND (&bcon,
                "foo",
                BCON_BIN (BSON_SUBTYPE_BINARY, (const uint8_t *) "deadbeef", 8),
                NULL);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Ejemplo n.º 4
0
static void
test_value_basic (void)
{
   static const uint8_t raw[16] = { 0 };
   const bson_value_t *value;
   bson_value_t copy;
   bson_iter_t iter;
   bson_oid_t oid;
   bson_t other = BSON_INITIALIZER;
   bson_t *doc;
   bson_t sub = BSON_INITIALIZER;
   bool r;
   int i;

   bson_oid_init (&oid, NULL);

   doc = BCON_NEW ("double", BCON_DOUBLE (123.4),
                   "utf8", "this is my string",
                   "document", BCON_DOCUMENT (&sub),
                   "array", BCON_DOCUMENT (&sub),
                   "binary", BCON_BIN (BSON_SUBTYPE_BINARY, raw, sizeof raw),
                   "undefined", BCON_UNDEFINED,
                   "oid", BCON_OID (&oid),
                   "bool", BCON_BOOL (true),
                   "datetime", BCON_DATE_TIME (12345678),
                   "null", BCON_NULL,
                   "regex", BCON_REGEX ("^hello", "i"),
                   "dbpointer", BCON_DBPOINTER ("test.test", &oid),
                   "code", BCON_CODE ("var a = function() {}"),
                   "symbol", BCON_SYMBOL ("my_symbol"),
                   "codewscope", BCON_CODEWSCOPE ("var a = 1;", &sub),
                   "int32", BCON_INT32 (1234),
                   "timestamp", BCON_TIMESTAMP (1234, 4567),
                   "int64", BCON_INT32 (4321),
                   "maxkey", BCON_MAXKEY,
                   "minkey", BCON_MINKEY);

   r = bson_iter_init (&iter, doc);
   assert (r);

   for (i = 0; i < 20; i++) {
      r = bson_iter_next (&iter);
      assert (r);

      value = bson_iter_value (&iter);
      assert (value);

      bson_value_copy (value, &copy);

      r = bson_append_value (&other, bson_iter_key (&iter), -1, &copy);
      assert (r);

      bson_value_destroy (&copy);
   }

   r = bson_iter_next (&iter);
   assert (!r);

   bson_destroy (doc);
   bson_destroy (&other);
}