npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ccpm/oid

v1.0.7

Published

C implemention for MongoDB ObjectID

Downloads

14

Readme

oid-cpp

C implemention for MongoDB ObjectID

This is a C++ library, not for Node.js.

Setup

$ npm install @ccpm/oid
add_subdirectory(...)
target_link_libraries(<TARGET> oid)

C API

// #include "oid/oid.h"
typedef struct object_id {
  uint8_t id[12];
} object_id;

OID_API int oid_construct(object_id* oid);
OID_API int oid_construct_with_time(object_id* oid, uint32_t time);
OID_API int oid_construct_with_buf(object_id* oid, const uint8_t* buf, uint32_t len);
OID_API int oid_construct_with_oid(object_id* oid, const object_id* other);

OID_API int oid_generate(uint32_t time, uint8_t* id);
OID_API int oid_create_from_hex_string(const char* hex_string, object_id* oid);
OID_API int oid_to_hex_string(const object_id* oid, char* res);
OID_API int oid_is_valid(const char* res);

OID_API int oid_equals_buf(const object_id* oid, const uint8_t* buf, uint32_t len);
OID_API int oid_equals_oid(const object_id* oid, const object_id* other);
OID_API int oid_create_from_time(uint32_t time, object_id* oid);
OID_API uint32_t oid_get_timestamp(const object_id* oid);

C++ API

// #include "oid/oid.hpp"

class ObjectId {
private:
  object_id* oid;

public:
  ObjectId();
  ObjectId(ObjectId&&);
  ObjectId(const ObjectId&);
  ObjectId(const object_id&);
  ObjectId(uint32_t);
  ObjectId(const std::vector<uint8_t>&);
  ObjectId(const std::string&);
  ObjectId(const char*);
  ~ObjectId();

  ObjectId& operator=(const ObjectId&);
  ObjectId& operator=(ObjectId&&);

  bool operator==(const ObjectId&) const;

  friend std::ostream& operator<<(std::ostream&, const ObjectId&);

  static std::vector<uint8_t> generate();
  static std::vector<uint8_t> generate(uint32_t);
  static ObjectId createFromHexString(const std::string&);
  static ObjectId createFromTime(uint32_t);

  static bool isValid(const std::vector<uint8_t>&);
  static bool isValid(const std::string&);

  std::string toHexString() const;
  bool equals(const ObjectId&) const;
  const object_id* data() const;

  uint32_t getTimestamp() const;
};