NATS C Client with JetStream and Streaming support
3.11.0
The nats.io C Client, Supported by Synadia Communications Inc.
|
Modules | |
Object Stores management | |
Object Store management | |
Functions | |
NATS_EXTERN natsStatus | objStoreMeta_Init (objStoreMeta *meta) |
Initializes an object store meta structure. | |
NATS_EXTERN natsStatus | objStore_Put (objStorePut **new_put, objStore *obs, objStoreMeta *meta) |
Initiates a session to put bytes into an object. | |
NATS_EXTERN natsStatus | objStorePut_Add (objStorePut *put, const void *data, int dataLen) |
Add data to the object. | |
NATS_EXTERN natsStatus | objStorePut_Complete (objStoreInfo **new_info, objStorePut *put, int64_t timeout) |
Complete a put operation. | |
NATS_EXTERN void | objStorePut_Destroy (objStorePut *put) |
Destroys the object store's put object. | |
NATS_EXTERN natsStatus | objStore_PutString (objStoreInfo **new_info, objStore *obs, const char *name, const char *data) |
Put a string into this object. | |
NATS_EXTERN natsStatus | objStore_PutBytes (objStoreInfo **new_info, objStore *obs, const char *name, const void *data, int dataLen) |
Put bytes into this object. | |
NATS_EXTERN natsStatus | objStore_PutFile (objStoreInfo **new_info, objStore *obs, const char *fileName) |
Put the content of a file into this object. | |
NATS_EXTERN natsStatus | objStore_Get (objStoreGet **new_get, objStore *obs, const char *name, objStoreOptions *opts) |
Pull the named object from the object store. | |
NATS_EXTERN natsStatus | objStoreGet_Info (const objStoreInfo **new_info, objStoreGet *get) |
Returns a handle to the information object own by the objStoreGet object. | |
NATS_EXTERN natsStatus | objStoreGet_Read (bool *done, void **new_data, int *dataLen, objStoreGet *get, int64_t timeout) |
Returns some bytes of the pulled object. | |
NATS_EXTERN natsStatus | objStoreGet_ReadAll (void **new_data, int *dataLen, objStoreGet *get, int64_t timeout) |
Returns the remaining bytes of the pulled object. | |
NATS_EXTERN void | objStoreGet_Destroy (objStoreGet *get) |
Destroys the object store's get object. | |
NATS_EXTERN natsStatus | objStore_GetString (char **new_str, objStore *obs, const char *name, objStoreOptions *opts) |
Pull the named object from the object store and return it as a string. | |
NATS_EXTERN natsStatus | objStore_GetBytes (void **new_data, int *dataLen, objStore *obs, const char *name, objStoreOptions *opts) |
Pull the named object from the object store and return it as a byte array. | |
NATS_EXTERN natsStatus | objStore_GetFile (objStore *obs, const char *name, const char *fileName, objStoreOptions *opts) |
Pull the named object from the object store and place it into a file. | |
Object Stores offer a straightforward method for storing large objects within JetStream. These stores are backed by a specially configured streams, designed to efficiently and compactly store these objects.
The Object Store, also known as a bucket, enables the execution of various operations:
NATS_EXTERN natsStatus objStoreMeta_Init | ( | objStoreMeta * | meta | ) |
Typically, the user will declare an objStoreMeta variable on the stack and call this function to initializes the structure, set some fields and pass it to an API.
meta | the pointer to the objStoreMeta structure to initialize. |
NATS_EXTERN natsStatus objStore_Put | ( | objStorePut ** | new_put, |
objStore * | obs, | ||
objStoreMeta * | meta | ||
) |
If the object already exists, it will be overwritten. The object name is required and taken from the objStoreMeta.Name field.
On success, an objStorePut object will be returned. This should then be passed to the functions to add and complete the put operation.
new_put | the location where to store the pointer to the objStorePut object. |
obs | the pointer to the objStore object. |
meta | the pointer to the objStoreMeta object. |
NATS_EXTERN natsStatus objStorePut_Add | ( | objStorePut * | put, |
const void * | data, | ||
int | dataLen | ||
) |
After successfully calling objStore_Put, the returned objStorePut object is used by this function to add bytes to the object. When there is no more data to add, call objStorePut_Complete to complete the operation.
If an error occurs, invoking this function again will immediately error out. The only outcome is to call objStorePut_Complete to undo the partial additions and free the object.
See objStore_Put for an example on how to use the set of APIs.
put | the pointer to the objStorePut object. |
data | the pointer to the byte array to add to the object. |
dataLen | the number of bytes of the byte array to add. |
NATS_EXTERN natsStatus objStorePut_Complete | ( | objStoreInfo ** | new_info, |
objStorePut * | put, | ||
int64_t | timeout | ||
) |
After adding data, this call will complete the operation and on success return the objStoreInfo (if desired).
If there were errors adding the data, this function will purge the partial data added.
new_info | the location where to store the pointer to the objStoreInfo object, or NULL if not needed. |
put | the pointer to the objStorePut object. |
timeout | the amount of time (in milliseconds) to wait for the operation to complete. |
NATS_EXTERN void objStorePut_Destroy | ( | objStorePut * | put | ) |
Releases memory allocated for this objStorePut object.
put | the pointer to the objStorePut object. |
NATS_EXTERN natsStatus objStore_PutString | ( | objStoreInfo ** | new_info, |
objStore * | obs, | ||
const char * | name, | ||
const char * | data | ||
) |
This is a convenience function to put a string into this object store under the given name.
An objStoreInfo will be returned, containing the object's metadata, digest and instance information.
new_info | the location where to store the pointer to the objStoreInfo object, or NULL if not needed. |
obs | the pointer to the objStore object. |
name | the name of the object to put the string into. |
data | the string to put into the object. |
NATS_EXTERN natsStatus objStore_PutBytes | ( | objStoreInfo ** | new_info, |
objStore * | obs, | ||
const char * | name, | ||
const void * | data, | ||
int | dataLen | ||
) |
This is a convenience function to put bytes into this object store under the given name.
An objStoreInfo will be returned, containing the object's metadata, digest and instance information.
new_info | the location where to store the pointer to the objStoreInfo object, or NULL if not needed. |
obs | the pointer to the objStore object. |
name | the name of the object to put the string into. |
data | the bytes to put into the object. |
dataLen | the number of bytes to put into the object. |
NATS_EXTERN natsStatus objStore_PutFile | ( | objStoreInfo ** | new_info, |
objStore * | obs, | ||
const char * | fileName | ||
) |
This is a convenience function to put a file content into this object store. The name of the object will be the path of the file.
new_info | the location where to store the pointer to the objStoreInfo object, or NULL if not needed. |
obs | the pointer to the objStore object. |
fileName | the name of the file whose content will be put into the object. |
NATS_EXTERN natsStatus objStore_Get | ( | objStoreGet ** | new_get, |
objStore * | obs, | ||
const char * | name, | ||
objStoreOptions * | opts | ||
) |
If the object does not exist, NATS_NOT_FOUND will be returned.
The returned objStoreGet object will contain the object's metadata and the user can call objStoreGet_Read to get some bytes as they become available, or objStoreGet_ReadAll to get the whole object in one call.
The option objStoreOptions.ShowDeleted can be provided to return an object even if it was marked as deleted.
Here is an example to read data by chunks:
Here is an example to read data all at once. Unless the user needs to inspect the object store information's object prior to read the data, the convenience functtion objStore_GetBytes will be equivalent much simpler to use.
new_get | the location where to store the pointer to the objStoreGet object. |
obs | the pointer to the objStore object. |
name | the name of the object to pull data from. |
opts | the pointer to the objStoreOptions object, possibly NULL . |
NATS_EXTERN natsStatus objStoreGet_Info | ( | const objStoreInfo ** | new_info, |
objStoreGet * | get | ||
) |
Allows the user to get information about the pulled object.
new_info | the location where to store the pointer to the objStoreInfo object. |
get | the pointer to the objStoreGet object owning this information object. |
NATS_EXTERN natsStatus objStoreGet_Read | ( | bool * | done, |
void ** | new_data, | ||
int * | dataLen, | ||
objStoreGet * | get, | ||
int64_t | timeout | ||
) |
This call returns up to a chunk of bytes of the object. The dataLen
will be set with the number of bytes that were returned.
The done
boolean will be set to true
if the call detects that this was the last bit of data that consistuted this object. Calling this function again would result in the NATS_ILLEGAL_STATE error returned.
data
must be freed by the user.See objStore_Get for example on how to use the set of APIs.
done | the location where to store the boolean indicating if this is the last read. |
new_data | the location where to store the pointer to a chunk of the object's data. |
dataLen | the location where to store the number of bytes returned. |
get | the pointer to the objStoreGet object. |
timeout | the amount of time (in milliseconds) allowed to perform the operation. |
NATS_EXTERN natsStatus objStoreGet_ReadAll | ( | void ** | new_data, |
int * | dataLen, | ||
objStoreGet * | get, | ||
int64_t | timeout | ||
) |
This call returns all data representing the object, or the remaining of the data if some were already collected using objStoreGet_Read.
This function should be called only once (except in the case of a NATS_TIMEOUT), if not the error NATS_ILLEGAL_STATE error will be returned.
data
must be freed by the user.See objStore_Get for example on how to use the set of APIs.
new_data | the location where to store the pointer to a chunk of the object's data. |
dataLen | the location where to store the number of bytes returned. |
get | the pointer to the objStoreGet object. |
timeout | the amount of time (in milliseconds) allowed to perform the operation. |
NATS_EXTERN void objStoreGet_Destroy | ( | objStoreGet * | get | ) |
Releases memory allocated for this objStoreGet object.
get | the pointer to the objStoreGet object. |
NATS_EXTERN natsStatus objStore_GetString | ( | char ** | new_str, |
objStore * | obs, | ||
const char * | name, | ||
objStoreOptions * | opts | ||
) |
This is a convenience function to pull an object from this object store and return it as a string.
If the object does not exist, NATS_NOT_FOUND will be returned.
The option objStoreOptions.ShowDeleted can be provided to return an object even if it was marked as deleted.
Here is an example:
new_str | the location where to store the pointer to the retrieved string. |
obs | the pointer to the objStore object. |
name | the name of the object to pull the string from. |
opts | the pointer to the objStoreOptions object, possibly NULL . |
NATS_EXTERN natsStatus objStore_GetBytes | ( | void ** | new_data, |
int * | dataLen, | ||
objStore * | obs, | ||
const char * | name, | ||
objStoreOptions * | opts | ||
) |
This is a convenience function to pull an object from this object store and return it as a byte array.
If the object does not exist, NATS_NOT_FOUND will be returned.
The option objStoreOptions.ShowDeleted can be provided to return an object even if it was marked as deleted. See objStore_GetString for an example on how to do so.
new_data | the location where to store the pointer to the retrieved byte array. |
dataLen | the location where to store the number of bytes of the byte array. |
obs | the pointer to the objStore object. |
name | the name of the object to pull the string from. |
opts | the pointer to the objStoreOptions object, possibly NULL . |
NATS_EXTERN natsStatus objStore_GetFile | ( | objStore * | obs, |
const char * | name, | ||
const char * | fileName, | ||
objStoreOptions * | opts | ||
) |
This is a convenience function to pull an object from this object store and place it in a file. If the file already exists, it will be overwritten, otherwise it will be created.
If the object does not exist, NATS_NOT_FOUND will be returned.
The option objStoreOptions.ShowDeleted can be provided to return an object even if it was marked as deleted. See objStore_GetString for an example on how to do so.
obs | the pointer to the objStore object. |
name | the name of the object to pull the string from. |
fileName | the name of the file to write the content into. |
opts | the pointer to the objStoreOptions object, possibly NULL . |