blob: 52c730aabf44ba8e0835bf73c02d8c8e222a5f53 [file] [log] [blame]
Alexander Afanasyev11225012013-11-21 23:11:10 -08001.. _Blob:
2
3Blob Class
4==========
5
6:[C++]:
7 Namespace: ndn
8
9.. code-block:: c++
10
11 class Blob : public ptr_lib::shared_ptr<const std::vector<uint8_t> >
12
13A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>. This is like a JavaScript string which is a pointer to an immutable string. It is OK to pass a pointer to the string because the new owner can't change the bytes of the string. However, like a JavaScript string, it is possible to change the pointer, and so this does allow the copy constructor and assignment to change the pointer. Also remember that the pointer can be null.
14
15Blob Constructor
16----------------
17
18Create a new Blob to point to an existing byte array.
19
20IMPORTANT: After calling this constructor, if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
21
22:[C++]:
23
24 .. code-block:: c++
25
26 Blob(
27
28 [const ptr_lib::shared_ptr<std::vector<uint8_t> > &value]
29
30 );
31
32 Blob(
33
34 [const ptr_lib::shared_ptr<const std::vector<uint8_t> > &value]
35
36 );
37
38:[JavaScript]:
39
40 .. code-block:: c++
41
42 var Blob = function Blob(
43
44 [value // Blob]
45
46 )
47
48:Parameters:
49
50 - `value`
51 (optional) A pointer to a vector with the byte array. This takes another reference and does not copy the bytes. If omitted, this set this blob to a null pointer.
52
53Blob Constructor (``uint8_t *``)
54--------------------------------
55
56(C++ only) Create a new Blob with an immutable copy of the given array.
57
58:[C++]:
59
60 .. code-block:: c++
61
62 Blob(
63
64 const uint8_t* value,
65 size_t valueLength
66
67 );
68
69:Parameters:
70
71 - `value`
72 A pointer to the byte array which is copied.
73
74 - `valueLength`
75 The length of value.
76
77Blob Constructor (copy byte array)
78----------------------------------
79
80Create a new Blob with an immutable copy of the array in the given vector. If you want to transfer the array without copying, the the vector has to start as a type for the main Blob constructor.
81
82:[C++]:
83
84 .. code-block:: c++
85
86 Blob(
87
88 const std::vector<uint8_t> &value
89
90 );
91
92:[JavaScript]:
93
94 .. code-block:: javascript
95
96 var Blob = function Blob(
97
98 [value // Buffer|Array<number>]
99
100 )
101
102:Parameters:
103
104 - `value`
105 A reference to a vector which is copied.
106
107Blob.size Method
108----------------
109
110Return the length of the immutable byte array.
111
112:[C++]:
113
114 .. code-block:: c++
115
116 size_t size() const;
117
118:[JavaScript]:
119
120 .. code-block:: javascript
121
122 // Returns number
123 Blob.prototype.size = function()
124
125:Returns:
126
127 The length of the array. If the pointer to the array is null, return 0.
128
129Blob.buf Method
130---------------
131
132Return a pointer to the immutable byte array. DO NOT change the contents of the array. If you need to change it, make a copy.
133
134:[C++]:
135
136 .. code-block:: c++
137
138 const uint8_t* buf() const;
139
140:[JavaScript]:
141
142 .. code-block:: javascript
143
144 // Returns Buffer
145 Blob.prototype.buf = function()
146
147:Returns:
148
149 A pointer to the immutable byte array. If the pointer to the array is null, return null.
150
151.. _SignedBlob:
152
153SignedBlob Class
154================
155
156:[C++]:
157 Namespace: ndn
158
159.. code-block:: c++
160
161 class SignedBlob : public Blob
162
163A SignedBlob extends Blob to keep the offsets of a signed portion (e.g., the bytes of Data packet). This inherits from Blob, including Blob.size and Blob.buf.
164
165SignedBlob.signedSize Method
166----------------------------
167
168Return the length of the signed portion of the immutable byte array.
169
170:[C++]:
171
172 .. code-block:: c++
173
174 size_t signedSize() const;
175
176:[JavaScript]:
177
178 .. code-block:: javascript
179
180 // Returns number
181 SignedBlob.prototype.signedSize = function()
182
183:Returns:
184
185 The length of the signed portion. If the pointer to the array is null, return 0.
186
187SignedBlob.signedBuf Method
188---------------------------
189
190Return a pointer to the first byte of the signed portion of the immutable byte array.
191
192:[C++]:
193
194 .. code-block:: c++
195
196 const uint8_t* signedBuf() const;
197
198:[JavaScript]:
199
200 .. code-block:: javascript
201
202 // Returns Buffer
203 SignedBlob.prototype.signedBuf = function()
204
205:Returns:
206
207 A pointer to the first byte of the signed portion. If the pointer to the array is null, return null.
208
209SignedBlob.getSignedPortionBeginOffset Method
210---------------------------------------------
211
212Return the offset in the array of the beginning of the signed portion.
213
214:[C++]:
215
216 .. code-block:: c++
217
218 size_t getSignedPortionBeginOffset() const;
219
220:[JavaScript]:
221
222 .. code-block:: javascript
223
224 // Returns number
225 SignedBlob.prototype.getSignedPortionBeginOffset = function()
226
227:Returns:
228
229 The offset that was given to the constructor.
230
231SignedBlob.getSignedPortionEndOffset Method
232-------------------------------------------
233
234Return the offset in the array of the end of the signed portion.
235
236:[C++]:
237
238 .. code-block:: c++
239
240 size_t getSignedPortionEndOffset() const;
241
242:[JavaScript]:
243
244 .. code-block:: javascript
245
246 // Returns number
247 SignedBlob.prototype.getSignedPortionEndOffset = function()
248
249:Returns:
250
251 The offset that was given to the constructor.