Blob Class¶
A Blob holds a pointer to an immutable byte array. 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.
[C++]: | #include <ndn-cpp/util/blob.hpp> Namespace:
ndn class Blob : public ptr_lib::shared_ptr<const std::vector<uint8_t> >
|
---|---|
[Python]: | Module: |
[Java]: | Package: |
Blob Constructors¶
Blob Constructor (from another Blob)¶
Create a new Blob and take another pointer to the given blob’s array without copying.
[C++]: | Blob(
[const Blob& blob]
);
|
---|---|
[Python]: | def __init__(self
[, blob # Blob]
)
|
[JavaScript]: | var Blob = function Blob(
[blob // Blob]
)
|
[Java]: | public Blob(
[Blob blob]
)
|
Parameters: |
|
Blob Constructor (maybe point to an existing byte array)¶
Create a new Blob with the option to to point to an existing byte array or to copy it.
IMPORTANT: If copy is false, 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.
[C++]: | Blob(
const ptr_lib::shared_ptr<std::vector<uint8_t> > &value,
bool copy
);
Blob(
const ptr_lib::shared_ptr<const std::vector<uint8_t> > &value,
bool copy
);
|
---|---|
[Python]: | def __init__(self,
value, # bytearray, memoryview or other array of int
copy # bool
)
|
[JavaScript]: | var Blob = function Blob(
value, // Buffer
copy // boolean
)
|
[Java]: | public Blob(
ByteBuffer value,
boolean copy
)
|
Parameters: |
|
Blob Constructor (copy an array)¶
Create a new Blob with a copy of the given array. This constructor always copies because the given array is not the right type to store internally in the Blob.
[C++]: | Blob(
const std::vector<uint8_t> &value
);
Blob(
const uint8_t* value,
size_t valueLength
);
|
---|---|
[JavaScript]: | var Blob = function Blob(
value // Array<number>
)
|
[Java]: | public Blob(
byte[] value
)
public Blob(
int[] value
)
|
Parameters: |
|
Blob Constructor (from Unicode string)¶
Create a new Blob from the UTF8 encoding of the Unicode string.
[Python]: | def __init__(self,
value # unicode (Python 2) or str (Python 3)
)
|
---|---|
[JavaScript]: | var Blob = function Blob(
value // string
)
|
[Java]: | public Blob(
String value
)
|
Parameters: |
|
Blob.buf Method¶
Return a pointer to the immutable byte array. DO NOT change the contents of the array. If you need to change it, make a copy.
[C++]: | const uint8_t* buf() const;
|
---|---|
[Python]: | # Returns an array type with int elements, such as bytearray.
def buf(self)
|
[JavaScript]: | // Returns Buffer
Blob.prototype.buf = function()
|
[Java]: | public final ByteBuffer buf()
|
Returns: | A pointer to the immutable byte array. If the pointer to the array is null, return null. |
Blob.equals Method¶
Check if the value of this Blob equals the other blob.
[C++]: | bool equals(
const Blob& other
) const;
|
---|---|
[Python]: | # Returns bool.
def equals(self,
other # Blob
)
|
[JavaScript]: | // Returns boolean
Blob.prototype.equals = function(
other // Blob
)
|
[Java]: | public final boolean equals(
Blob other
)
|
Parameters: |
|
Returns: | True if this isNull and other isNull or if the bytes of this blob equal the bytes of the other. |
Blob.isNull Method¶
Check if the array pointer is null.
[C++]: | bool isNull() const;
|
---|---|
[Python]: | # Returns bool.
def isNull(self)
|
[JavaScript]: | // Returns boolean
Blob.prototype.isNull = function()
|
[Java]: | public final boolean isNull()
|
Returns: | True if the array pointer is null, otherwise false. |
Blob.size Method¶
Return the length of the immutable byte array.
[C++]: | size_t size() const;
|
---|---|
[Python]: | # Returns int
def size(self)
|
[JavaScript]: | // Returns number
Blob.prototype.size = function()
|
[Java]: | public final int size()
|
Returns: | The length of the array. If the pointer to the array is null, return 0. |
SignedBlob Class¶
A 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.
[C++]: | #include <ndn-cpp/util/signed-blob.hpp> Namespace:
ndn class SignedBlob : public Blob
|
---|---|
[Python]: | Module: class SignedBlob(Blob)
|
[Java]: | Package: public class SignedBlob extends Blob
|
SignedBlob.getSignedPortionBeginOffset Method¶
Return the offset in the array of the beginning of the signed portion.
[C++]: | size_t getSignedPortionBeginOffset() const;
|
---|---|
[Python]: | # Returns int
def getSignedPortionBeginOffset(self)
|
[JavaScript]: | // Returns number
SignedBlob.prototype.getSignedPortionBeginOffset = function()
|
[Java]: | public final int getSignedPortionBeginOffset()
|
Returns: | The offset of the beginning of the signed portion that was given to the constructor. |
SignedBlob.getSignedPortionEndOffset Method¶
Return the offset in the array of the end of the signed portion.
[C++]: | size_t getSignedPortionEndOffset() const;
|
---|---|
[Python]: | # Returns int
def getSignedPortionEndOffset(self)
|
[JavaScript]: | // Returns number
SignedBlob.prototype.getSignedPortionEndOffset = function()
|
[Java]: | public final int getSignedPortionEndOffset()
|
Returns: | The offset of the end of the signed portion that was given to the constructor. |
SignedBlob.signedBuf Method¶
Return a pointer to the first byte of the signed portion of the immutable byte array.
[C++]: | const uint8_t* signedBuf() const;
|
---|---|
[Python]: | # Returns an array type with int elements, such as bytearray.
def signedBuf(self)
|
[JavaScript]: | // Returns Buffer
SignedBlob.prototype.signedBuf = function()
|
[Java]: | public final ByteBuffer signedBuf()
|
Returns: | A pointer to the first byte of the signed portion. If the pointer to the array is null, return null. |
SignedBlob.signedSize Method¶
Return the length of the signed portion of the immutable byte array.
[C++]: | size_t signedSize() const;
|
---|---|
[Python]: | # Returns int
def signedSize(self)
|
[JavaScript]: | // Returns number
SignedBlob.prototype.signedSize = function()
|
[Java]: | public final int signedSize()
|
Returns: | The length of the signed portion. If the pointer to the array is null, return 0. |