Skip to content

Commit

Permalink
* update api of snowid.h
Browse files Browse the repository at this point in the history
* update requirements in readme
  • Loading branch information
beyonddream committed Nov 3, 2022
1 parent eb41dea commit 504f8a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,37 @@ Two main functions to generate id are provided:

A)
```c
/**
* Attempts to set `dest_as_binary` with a 128-bit id (represented as byte array). * Return true if operation succeeds.
/*
* Attempts to set `dest_as_binary` with a 128-bit id (represented as byte
* array). Return true if operation succeeds.
*/
bool snow_get_id_as_binary(snow_id_binary_t dest_as_binary);
bool snow_get_id_as_binary(snow_id_binary_t snowid_as_bin);
```
B)
```c
/**
/*
* Attempts to set `dest` with a `struct snow_id` that consists of individual
* components of the id. Return true if operation succeeds.
*/
bool snow_get_id(snow_id_t *dest);
bool snow_get_id(snow_id_t *snowid);
```

The third function to convert A) from B).
```c
/**
/*
* Convenience function that attempts to convert `snowid` of type `struct
* snow_id` into binary `dest_as_bin`. Return true if operation succeeds.
*/
bool snow_id_convert(snow_id_binary_t dest_as_bin, const snow_id_t *snowid);
bool snow_id_convert(snow_id_binary_t snowid_as_bin, const snow_id_t *snowid);
```
For full usage of reset of the public API's (`snowid.h`), checkout `main.c` that provides a driver program on how to use the library from an application (e.g. a (web)service).
## Dependencies
* Tested on macOS and GNU/Linux (via Docker). PR welcome to make it work on Windows.
* C99 compatible C compiler (e.g. GCC or Clang).
* This library doesn't depend on any external libraries.
* This library doesn't depend on any external libraries.
## Build/Test/Benchmark
Expand Down
14 changes: 7 additions & 7 deletions snowid.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ typedef unsigned char snow_id_binary_t[16];
* sequence_id is incremented as many times as the function is called within the
* same timestamp.
*
* @arg dest - If able to generate an id, set the value of id to `snow_id`.
* @arg snowid - If able to generate an id, set the value of id to `snow_id`.
* @return true if successfully able to generate an id, false if not.
*/
bool snow_get_id(snow_id_t *dest);
bool snow_get_id(snow_id_t *snowid);

/**
* Dump snow state and config to stdout for debugging.
Expand Down Expand Up @@ -85,17 +85,17 @@ void snow_shutdown(void);
* Represented as:
* <unix timestamp (64 bits) + MAC address (48 bits) + sequence number (16 bits)>
*
* @param dest_as_bin - set to snowid converted to 128 bits
* @param snowid_as_bin - set to snowid as binary
* @return true if success, else false.
*/
bool snow_get_id_as_binary(snow_id_binary_t dest_as_bin);
bool snow_get_id_as_binary(snow_id_binary_t snowid_as_bin);

/**
* Convert an already generated snow_id as binary - contiguous array of 128 bits.
* Convert an already generated snow_id as binary (represented as byte array).
*
* @param out - set the converted snowid as binary
* @param snowid_as_bin - set the converted snowid as binary
* @param snowid - pass in already generated snowid
*/
bool snow_id_convert(snow_id_binary_t out, const snow_id_t *snowid);
bool snow_id_convert(snow_id_binary_t snowid_as_bin, const snow_id_t *snowid);

#endif /* __SNOWID_H__ */

0 comments on commit 504f8a6

Please sign in to comment.