Adding accessors for IsBlob and Blob.data (#4398)

This commit is contained in:
Manuel Kroiss
2017-07-27 17:06:02 +01:00
committed by Wouter van Oortmerssen
parent 265e43faf0
commit 360c34467c
2 changed files with 14 additions and 3 deletions

View File

@@ -230,14 +230,15 @@ class String : public Sized {
class Blob : public Sized {
public:
Blob(const uint8_t *data, uint8_t byte_width)
: Sized(data, byte_width) {}
Blob(const uint8_t *data_buf, uint8_t byte_width)
: Sized(data_buf, byte_width) {}
static Blob EmptyBlob() {
static const uint8_t empty_blob[] = { 0/*len*/ };
return Blob(empty_blob + 1, 1);
}
bool IsTheEmptyBlob() const { return data_ == EmptyBlob().data_; }
const uint8_t *data() const { return data_; }
};
class Vector : public Sized {
@@ -360,6 +361,7 @@ class Reference {
bool IsKey() const { return type_ == TYPE_KEY; }
bool IsVector() const { return type_ == TYPE_VECTOR || type_ == TYPE_MAP; }
bool IsMap() const { return type_ == TYPE_MAP; }
bool IsBlob() const { return type_ == TYPE_BLOB; }
// Reads any type as a int64_t. Never fails, does most sensible conversion.
// Truncates floats, strings are attempted to be parsed for a number,