mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-30 18:40:28 +00:00
Add support for STVector256.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "SerializedTypes.h"
|
||||
@@ -173,15 +174,44 @@ std::string STAccount::getText() const
|
||||
|
||||
STAccount* STAccount::construct(SerializerIterator& u, const char *name)
|
||||
{
|
||||
STAccount *ret = new STAccount(name, u.getVL());
|
||||
if (!ret->isValueH160())
|
||||
{
|
||||
delete ret;
|
||||
throw std::runtime_error("invalid account in transaction");
|
||||
}
|
||||
return ret;
|
||||
return new STAccount(name, u.getVL());
|
||||
}
|
||||
|
||||
//
|
||||
// STVector256
|
||||
//
|
||||
|
||||
// Return a new object from a SerializerIterator.
|
||||
STVector256* STVector256::construct(SerializerIterator& u, const char *name)
|
||||
{
|
||||
return new STVector256(name, u.getVL());
|
||||
}
|
||||
|
||||
void STVector256::add(Serializer& s) const
|
||||
{
|
||||
s.add32(mValue.size());
|
||||
BOOST_FOREACH(const uint256& v, mValue)
|
||||
{
|
||||
s.add256(v);
|
||||
}
|
||||
}
|
||||
|
||||
void STVector256::setValue(const std::vector<unsigned char>& vucData)
|
||||
{
|
||||
Serializer s(vucData);
|
||||
SerializerIterator it(s);
|
||||
uint64 uSize = it.get32();
|
||||
uint64 uIndex = 0;
|
||||
|
||||
mValue.resize(uSize);
|
||||
while (uSize--)
|
||||
mValue[uIndex++] = it.get256();
|
||||
}
|
||||
|
||||
//
|
||||
// STAccount
|
||||
//
|
||||
|
||||
bool STAccount::isValueH160() const
|
||||
{
|
||||
return peekValue().size() == (160/8);
|
||||
|
||||
@@ -12,15 +12,28 @@
|
||||
enum SerializedTypeID
|
||||
{
|
||||
// special types
|
||||
STI_DONE=-1, STI_NOTPRESENT=0,
|
||||
STI_DONE = -1,
|
||||
STI_NOTPRESENT = 0,
|
||||
|
||||
// standard types
|
||||
STI_OBJECT=1, STI_UINT8=2, STI_UINT16=3, STI_UINT32=4, STI_UINT64=5,
|
||||
STI_HASH128=6, STI_HASH160=7, STI_HASH256=8, STI_VL=9, STI_TL=10,
|
||||
STI_AMOUNT=11, STI_PATHSET=12,
|
||||
STI_OBJECT = 1,
|
||||
STI_UINT8 = 2,
|
||||
STI_UINT16 = 3,
|
||||
STI_UINT32 = 4,
|
||||
STI_UINT64 = 5,
|
||||
STI_HASH128 = 6,
|
||||
STI_HASH160 = 7,
|
||||
STI_HASH256 = 8,
|
||||
STI_VL = 9,
|
||||
STI_TL = 10,
|
||||
STI_AMOUNT = 11,
|
||||
STI_PATHSET = 12,
|
||||
STI_VECTOR256 = 13,
|
||||
|
||||
// high level types
|
||||
STI_ACCOUNT=100, STI_TRANSACTION=101, STI_LEDGERENTRY=102
|
||||
STI_ACCOUNT = 100,
|
||||
STI_TRANSACTION = 101,
|
||||
STI_LEDGERENTRY = 102
|
||||
};
|
||||
|
||||
class SerializedType
|
||||
@@ -561,5 +574,40 @@ public:
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
class STVector256 : public SerializedType
|
||||
{
|
||||
protected:
|
||||
std::vector<uint256> mValue;
|
||||
|
||||
STVector256* duplicate() const { return new STVector256(name, mValue); }
|
||||
static STVector256* construct(SerializerIterator&, const char* name = NULL);
|
||||
|
||||
public:
|
||||
STVector256() { ; }
|
||||
STVector256(const char* n) : SerializedType(n) { ; }
|
||||
STVector256(const char* n, const std::vector<uint256>& v) : SerializedType(n), mValue(v) { ; }
|
||||
STVector256(const std::vector<uint256>& vector) : mValue(vector) { ; }
|
||||
STVector256(const char* n, const std::vector<unsigned char>& vucSerial) : SerializedType(n)
|
||||
{ setValue(vucSerial); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_VECTOR256; }
|
||||
int getLength() const { return mValue.size()*(256/8)+(64/8); }
|
||||
void add(Serializer& s) const;
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
|
||||
const std::vector<uint256>& peekValue() const { return mValue; }
|
||||
std::vector<uint256>& peekValue() { return mValue; }
|
||||
|
||||
std::vector<uint256> getValue() const { return mValue; }
|
||||
|
||||
bool isEmpty() const { return mValue.empty(); }
|
||||
|
||||
void setValue(const STVector256& v) { mValue = v.mValue; }
|
||||
void setValue(const std::vector<uint256>& v) { mValue = v; }
|
||||
void setValue(const std::vector<unsigned char>& vucData);
|
||||
};
|
||||
|
||||
#endif
|
||||
// vim:ts=4
|
||||
|
||||
@@ -14,13 +14,13 @@ typedef std::pair<int, std::vector<unsigned char> > TaggedListItem;
|
||||
|
||||
class Serializer
|
||||
{
|
||||
public:
|
||||
public:
|
||||
typedef boost::shared_ptr<Serializer> pointer;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::vector<unsigned char> mData;
|
||||
|
||||
public:
|
||||
public:
|
||||
Serializer(int n=256) { mData.reserve(n); }
|
||||
Serializer(const std::vector<unsigned char> &data) : mData(data) { ; }
|
||||
Serializer(const std::string& data) : mData(data.data(), (data.data()) + data.size()) { ; }
|
||||
|
||||
Reference in New Issue
Block a user