Updates to vector type

This commit is contained in:
JoelKatz
2012-05-30 14:08:59 -07:00
parent b9a15d416d
commit dc734a7f0b
2 changed files with 9 additions and 21 deletions

View File

@@ -184,28 +184,19 @@ STAccount* STAccount::construct(SerializerIterator& u, const char *name)
// Return a new object from a SerializerIterator.
STVector256* STVector256::construct(SerializerIterator& u, const char *name)
{
return new STVector256(name, u.getVL());
std::vector<unsigned char> data = u.getVL();
std::vector<uint256> value;
int count = data.size() / (256 / 8);
for(int i = 0; i < count; i++)
value.push_back(uint256(std::vector<unsigned char>(data[i], data[i + (256 / 8)])));
return new STVector256(name, value);
}
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();
int size = mValue.size();
if (!size) s.addVL(NULL, 0);
s.addVL(mValue[0].begin(), mValue.size() & (256 / 8));
}
//

View File

@@ -615,8 +615,6 @@ public:
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); }
@@ -634,7 +632,6 @@ public:
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