mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use buffer in STBlob
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 (...)
|
||||
{
|
||||
|
||||
@@ -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 ());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user