blob: 8d1f784e0e36bb6be13d09000439715a2333728e [file] [log] [blame]
Jeff Thompson8dc775b2013-08-29 17:16:42 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson8dc775b2013-08-29 17:16:42 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_BLOB_H
Jeff Thompsone589c3f2013-10-12 17:30:50 -07008#define NDN_BLOB_H
Jeff Thompson8dc775b2013-08-29 17:16:42 -07009
Jeff Thompson25b4e612013-10-10 16:03:24 -070010#include <ndn-cpp/c/common.h>
11
Jeff Thompsone589c3f2013-10-12 17:30:50 -070012#ifdef __cplusplus
Jeff Thompson8dc775b2013-08-29 17:16:42 -070013extern "C" {
14#endif
15
16/**
17 * An ndn_Blob holds a pointer to a read-only pre-allocated buffer and its length.
18 */
19struct ndn_Blob {
Jeff Thompson93034532013-10-08 11:52:43 -070020 uint8_t *value; /**< pointer to the pre-allocated buffer for the value. Must be treated as read only. */
21 size_t length; /**< the number of bytes in value. */
Jeff Thompson8dc775b2013-08-29 17:16:42 -070022};
23
24/**
25 * Initialize the ndn_Blob struct with the given value.
26 * @param self pointer to the ndn_Blob struct.
27 * @param value The pre-allocated buffer for the value, or 0 for none.
Jeff Thompson93034532013-10-08 11:52:43 -070028 * @param length The number of bytes in value.
Jeff Thompson8dc775b2013-08-29 17:16:42 -070029 */
Jeff Thompson93034532013-10-08 11:52:43 -070030static inline void ndn_Blob_initialize(struct ndn_Blob *self, uint8_t *value, size_t length)
Jeff Thompson8dc775b2013-08-29 17:16:42 -070031{
32 self->value = value;
Jeff Thompson93034532013-10-08 11:52:43 -070033 self->length = length;
Jeff Thompson8dc775b2013-08-29 17:16:42 -070034}
35
Jeff Thompsone589c3f2013-10-12 17:30:50 -070036#ifdef __cplusplus
Jeff Thompson8dc775b2013-08-29 17:16:42 -070037}
38#endif
39
40#endif