mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Some helper functions to help adapt between vectors and strings.
This commit is contained in:
1
SHAMap.h
1
SHAMap.h
@@ -70,6 +70,7 @@ public:
|
|||||||
|
|
||||||
// Convert to/from wire format (256-bit nodeID, 1-byte depth)
|
// Convert to/from wire format (256-bit nodeID, 1-byte depth)
|
||||||
void addIDRaw(Serializer &s) const;
|
void addIDRaw(Serializer &s) const;
|
||||||
|
std::string getRawString() const;
|
||||||
static int getRawIDLength(void) { return 33; }
|
static int getRawIDLength(void) { return 33; }
|
||||||
SHAMapNode(const void *ptr, int len);
|
SHAMapNode(const void *ptr, int len);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -111,6 +111,13 @@ void SHAMapNode::addIDRaw(Serializer &s) const
|
|||||||
s.add8(mDepth);
|
s.add8(mDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SHAMapNode::getRawString() const
|
||||||
|
{
|
||||||
|
Serializer s(33);
|
||||||
|
addIDRaw(s);
|
||||||
|
return s.getString();
|
||||||
|
}
|
||||||
|
|
||||||
SHAMapNode SHAMapNode::getChildNodeID(int m) const
|
SHAMapNode SHAMapNode::getChildNodeID(int m) const
|
||||||
{ // This can be optimized to avoid the << if needed
|
{ // This can be optimized to avoid the << if needed
|
||||||
assert((m>=0) && (m<16));
|
assert((m>=0) && (m<16));
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class Serializer
|
|||||||
void* getDataPtr() { return &mData.front(); }
|
void* getDataPtr() { return &mData.front(); }
|
||||||
const std::vector<unsigned char>& peekData() const { return mData; }
|
const std::vector<unsigned char>& peekData() const { return mData; }
|
||||||
std::vector<unsigned char> getData() const { return mData; }
|
std::vector<unsigned char> getData() const { return mData; }
|
||||||
|
std::string getString() const { return std::string(reinterpret_cast<const char *>(getDataPtr()), getLength()); }
|
||||||
void secureErase() { memset(&(mData.front()), 0, mData.size()); erase(); }
|
void secureErase() { memset(&(mData.front()), 0, mData.size()); erase(); }
|
||||||
void erase() { mData.clear(); }
|
void erase() { mData.clear(); }
|
||||||
int removeLastByte();
|
int removeLastByte();
|
||||||
|
|||||||
Reference in New Issue
Block a user