blob: 8867d3d60222a974331b9687702c2a962106ff51 [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
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080015Blob Constructors
16-----------------
17
18Blob Constructor (from existing byte array)
19^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev11225012013-11-21 23:11:10 -080020
21Create a new Blob to point to an existing byte array.
22
23IMPORTANT: 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.
24
25:[C++]:
26
27 .. code-block:: c++
28
29 Blob(
30
31 [const ptr_lib::shared_ptr<std::vector<uint8_t> > &value]
32
33 );
34
35 Blob(
36
37 [const ptr_lib::shared_ptr<const std::vector<uint8_t> > &value]
38
39 );
40
41:[JavaScript]:
42
43 .. code-block:: c++
44
45 var Blob = function Blob(
46
47 [value // Blob]
48
49 )
50
51:Parameters:
52
53 - `value`
54 (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.
55
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080056Blob Constructor (from immutable ``uint8_t *`` array) (C++ only)
57^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev11225012013-11-21 23:11:10 -080058
59(C++ only) Create a new Blob with an immutable copy of the given array.
60
61:[C++]:
62
63 .. code-block:: c++
64
65 Blob(
66
67 const uint8_t* value,
68 size_t valueLength
69
70 );
71
72:Parameters:
73
74 - `value`
75 A pointer to the byte array which is copied.
76
77 - `valueLength`
78 The length of value.
79
80Blob Constructor (copy byte array)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080081^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev11225012013-11-21 23:11:10 -080082
83Create 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.
84
85:[C++]:
86
87 .. code-block:: c++
88
89 Blob(
90
91 const std::vector<uint8_t> &value
92
93 );
94
95:[JavaScript]:
96
97 .. code-block:: javascript
98
99 var Blob = function Blob(
100
101 [value // Buffer|Array<number>]
102
103 )
104
105:Parameters:
106
107 - `value`
108 A reference to a vector which is copied.
109
110Blob.size Method
111----------------
112
113Return the length of the immutable byte array.
114
115:[C++]:
116
117 .. code-block:: c++
118
119 size_t size() const;
120
121:[JavaScript]:
122
123 .. code-block:: javascript
124
125 // Returns number
126 Blob.prototype.size = function()
127
128:Returns:
129
130 The length of the array. If the pointer to the array is null, return 0.
131
132Blob.buf Method
133---------------
134
135Return a pointer to the immutable byte array. DO NOT change the contents of the array. If you need to change it, make a copy.
136
137:[C++]:
138
139 .. code-block:: c++
140
141 const uint8_t* buf() const;
142
143:[JavaScript]:
144
145 .. code-block:: javascript
146
147 // Returns Buffer
148 Blob.prototype.buf = function()
149
150:Returns:
151
152 A pointer to the immutable byte array. If the pointer to the array is null, return null.
153
154.. _SignedBlob:
155
156SignedBlob Class
157================
158
159:[C++]:
160 Namespace: ndn
161
162.. code-block:: c++
163
164 class SignedBlob : public Blob
165
166A 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.
167
168SignedBlob.signedSize Method
169----------------------------
170
171Return the length of the signed portion of the immutable byte array.
172
173:[C++]:
174
175 .. code-block:: c++
176
177 size_t signedSize() const;
178
179:[JavaScript]:
180
181 .. code-block:: javascript
182
183 // Returns number
184 SignedBlob.prototype.signedSize = function()
185
186:Returns:
187
188 The length of the signed portion. If the pointer to the array is null, return 0.
189
190SignedBlob.signedBuf Method
191---------------------------
192
193Return a pointer to the first byte of the signed portion of the immutable byte array.
194
195:[C++]:
196
197 .. code-block:: c++
198
199 const uint8_t* signedBuf() const;
200
201:[JavaScript]:
202
203 .. code-block:: javascript
204
205 // Returns Buffer
206 SignedBlob.prototype.signedBuf = function()
207
208:Returns:
209
210 A pointer to the first byte of the signed portion. If the pointer to the array is null, return null.
211
212SignedBlob.getSignedPortionBeginOffset Method
213---------------------------------------------
214
215Return the offset in the array of the beginning of the signed portion.
216
217:[C++]:
218
219 .. code-block:: c++
220
221 size_t getSignedPortionBeginOffset() const;
222
223:[JavaScript]:
224
225 .. code-block:: javascript
226
227 // Returns number
228 SignedBlob.prototype.getSignedPortionBeginOffset = function()
229
230:Returns:
231
232 The offset that was given to the constructor.
233
234SignedBlob.getSignedPortionEndOffset Method
235-------------------------------------------
236
237Return the offset in the array of the end of the signed portion.
238
239:[C++]:
240
241 .. code-block:: c++
242
243 size_t getSignedPortionEndOffset() const;
244
245:[JavaScript]:
246
247 .. code-block:: javascript
248
249 // Returns number
250 SignedBlob.prototype.getSignedPortionEndOffset = function()
251
252:Returns:
253
254 The offset that was given to the constructor.