Use buffer in STBlob

This commit is contained in:
seelabs
2015-03-12 11:54:15 -07:00
committed by Tom Ritchford
parent 8ca9fa1c26
commit 803f5b5613
10 changed files with 102 additions and 77 deletions

View File

@@ -37,12 +37,12 @@ std::string STAccount::getText () const
STAccount*
STAccount::construct (SerialIter& u, SField::ref name)
{
return new STAccount (name, u.getVL ());
return new STAccount (name, u.getVLBuffer ());
}
STAccount::STAccount (SField::ref n, Account const& v) : STBlob (n)
STAccount::STAccount (SField::ref n, Account const& v)
: STBlob (n, v.data (), v.size ())
{
peekValue ().insert (peekValue ().end (), v.begin (), v.end ());
}
bool STAccount::isValueH160 () const

View File

@@ -25,21 +25,21 @@ namespace ripple {
STBlob::STBlob (SerialIter& st, SField::ref name)
: STBase (name)
, value_ (st.getVLBuffer ())
{
value = st.getVL ();
}
std::string
STBlob::getText () const
{
return strHex (value);
return strHex (value_.data (), value_.size ());
}
bool
STBlob::isEquivalent (const STBase& t) const
{
const STBlob* v = dynamic_cast<const STBlob*> (&t);
return v && (value == v->value);
return v && (value_ == v->value_);
}
} // ripple

View File

@@ -735,7 +735,9 @@ Account STObject::getFieldAccount160 (SField::ref field) const
Blob STObject::getFieldVL (SField::ref field) const
{
return getFieldByValue <STBlob> (field);
STBlob empty;
STBlob const& b = getFieldByConstRef <STBlob> (field, empty);
return Blob (b.data (), b.data () + b.size ());
}
STAmount const& STObject::getFieldAmount (SField::ref field) const
@@ -835,7 +837,8 @@ void STObject::setFieldAccount (SField::ref field, Account const& v)
void STObject::setFieldVL (SField::ref field, Blob const& v)
{
setFieldUsingSetValue <STBlob> (field, v);
setFieldUsingSetValue <STBlob>
(field, Buffer(v.data (), v.size ()));
}
void STObject::setFieldAmount (SField::ref field, STAmount const& v)

View File

@@ -418,7 +418,8 @@ static std::unique_ptr <STBase> parseLeaf (
if (!vBlob.second)
throw std::invalid_argument ("invalid data");
ret = std::make_unique <STBlob> (field, vBlob.first);
ret = std::make_unique <STBlob> (field, vBlob.first.data (),
vBlob.first.size ());
}
catch (...)
{

View File

@@ -662,24 +662,31 @@ SerialIter::getFieldID (int& type, int& name)
}
}
// VFALCO DEPRECATED Returns a copy
Blob
SerialIter::getRaw (int size)
// getRaw for blob or buffer
template<class T>
T SerialIter::getRawHelper (int size)
{
static_assert(std::is_same<T, Blob>::value ||
std::is_same<T, Buffer>::value, "");
if (remain_ < size)
throw std::runtime_error(
"invalid SerialIter getRaw");
Blob b (p_, p_ + size);
T result (size);
memcpy(result.data (), p_, size);
p_ += size;
used_ += size;
remain_ -= size;
return b;
return result;
}
// VFALCO DEPRECATED Returns a copy
Blob
SerialIter::getVL()
SerialIter::getRaw (int size)
{
return getRawHelper<Blob> (size);
}
int SerialIter::getVLDataLength ()
{
int b1 = get8();
int datLen;
@@ -700,7 +707,20 @@ SerialIter::getVL()
int b3 = get8();
datLen = Serializer::decodeVLLength (b1, b2, b3);
}
return getRaw(datLen);
return datLen;
}
// VFALCO DEPRECATED Returns a copy
Blob
SerialIter::getVL()
{
return getRaw(getVLDataLength ());
}
Buffer
SerialIter::getVLBuffer()
{
return getRawHelper<Buffer> (getVLDataLength ());
}