Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_BLOB_H |
| 8 | #define NDN_BLOB_H |
| 9 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame^] | 10 | #include <ndn-cpp/c/common.h> |
| 11 | |
Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
| 16 | /** |
| 17 | * An ndn_Blob holds a pointer to a read-only pre-allocated buffer and its length. |
| 18 | */ |
| 19 | struct ndn_Blob { |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 20 | 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 Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 22 | }; |
| 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 Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 28 | * @param length The number of bytes in value. |
Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 29 | */ |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 30 | static inline void ndn_Blob_initialize(struct ndn_Blob *self, uint8_t *value, size_t length) |
Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 31 | { |
| 32 | self->value = value; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 33 | self->length = length; |
Jeff Thompson | 8dc775b | 2013-08-29 17:16:42 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | #endif |