Exemple #1
0
/**
 * Generate the next object id.
 */
VALUE rb_bson_object_id_generator_next(int argc, VALUE* args, VALUE self)
{
  char bytes[12];
  uint32_t t;
  uint32_t c;
  uint16_t pid = BSON_UINT16_TO_BE(getpid());

  if (argc == 0 || (argc == 1 && *args == Qnil)) {
    t = BSON_UINT32_TO_BE((int) time(NULL));
  }
  else {
    t = BSON_UINT32_TO_BE(NUM2ULONG(rb_funcall(*args, rb_intern("to_i"), 0)));
  }

  c = BSON_UINT32_TO_BE(rb_bson_object_id_counter << 8);

  memcpy(&bytes, &t, 4);
  memcpy(&bytes[4], rb_bson_machine_id_hash, 3);
  memcpy(&bytes[7], &pid, 2);
  memcpy(&bytes[9], (unsigned char*) &c, 3);
  rb_bson_object_id_counter++;
  return rb_str_new(bytes, 12);
}
void
bson_oid_init_sequence (bson_oid_t     *oid,     /* OUT */
                        bson_context_t *context) /* IN */
{
   uint32_t now = (uint32_t)(time (NULL));

   if (!context) {
      context = bson_context_get_default ();
   }

   now = BSON_UINT32_TO_BE (now);

   memcpy (&oid->bytes[0], &now, sizeof (now));
   context->oid_get_seq64 (context, oid);
}
Exemple #3
0
void
bson_oid_init_sequence (bson_oid_t     *oid,
                        bson_context_t *context)
{
   bson_uint32_t now = time(NULL);

   if (!context) {
      context = bson_context_get_default();
   }

   now = BSON_UINT32_TO_BE(now);

   memcpy(&oid->bytes[0], &now, 4);
   context->oid_get_seq64(context, oid);
}
Exemple #4
0
void
bson_oid_init (bson_oid_t     *oid,
               bson_context_t *context)
{
   bson_uint32_t now = time(NULL);

   bson_return_if_fail(oid);

   if (!context) {
      context = bson_context_get_default();
   }

   now = BSON_UINT32_TO_BE(now);
   memcpy(&oid->bytes[0], &now, 4);

   context->oid_get_host(context, oid);
   context->oid_get_pid(context, oid);
   context->oid_get_seq32(context, oid);
}
Exemple #5
0
void
bson_oid_init (bson_oid_t     *oid,     /* OUT */
               bson_context_t *context) /* IN */
{
    uint32_t now = (uint32_t)(time (NULL));

    bson_return_if_fail (oid);

    if (!context) {
        context = bson_context_get_default ();
    }

    now = BSON_UINT32_TO_BE (now);
    memcpy (&oid->bytes[0], &now, sizeof (now));

    context->oid_get_host (context, oid);
    context->oid_get_pid (context, oid);
    context->oid_get_seq32 (context, oid);
}