mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Bugfixes and missing functionality.
STUVL::getLength, STUTL::getLength, list->vector, getTaggedListLength
This commit is contained in:
@@ -37,9 +37,9 @@ public:
|
|||||||
SerializedTypeID getType() const { return STI_OBJECT; }
|
SerializedTypeID getType() const { return STI_OBJECT; }
|
||||||
STUObject* duplicate() const { return new STUObject(*this); }
|
STUObject* duplicate() const { return new STUObject(*this); }
|
||||||
|
|
||||||
std::vector<unsigned char> serialize() const;
|
void add(Serializer& s) const;
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
std::string getSQL() const;
|
|
||||||
|
|
||||||
void addObject(const SerializedType& t) { data.push_back(t.duplicate()); }
|
void addObject(const SerializedType& t) { data.push_back(t.duplicate()); }
|
||||||
void giveObject(SerializedType* t) { data.push_back(t); }
|
void giveObject(SerializedType* t) { data.push_back(t); }
|
||||||
|
|||||||
@@ -83,10 +83,15 @@ STUVariableLength* STUVariableLength::construct(SerializerIterator& u)
|
|||||||
return new STUVariableLength(u.getVL());
|
return new STUVariableLength(u.getVL());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int STUVariableLength::getLength() const
|
||||||
|
{
|
||||||
|
return Serializer::encodeLengthLength(value.size()) + value.size();
|
||||||
|
}
|
||||||
|
|
||||||
std::string STUTaggedList::getText() const
|
std::string STUTaggedList::getText() const
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for(std::list<TaggedListItem>::const_iterator it=value.begin(); it!=value.end(); ++it)
|
for(std::vector<TaggedListItem>::const_iterator it=value.begin(); it!=value.end(); ++it)
|
||||||
{
|
{
|
||||||
ret+=boost::lexical_cast<std::string>(it->first);
|
ret+=boost::lexical_cast<std::string>(it->first);
|
||||||
ret+=",";
|
ret+=",";
|
||||||
@@ -99,3 +104,10 @@ STUTaggedList* STUTaggedList::construct(SerializerIterator& u)
|
|||||||
{
|
{
|
||||||
return new STUTaggedList(u.getTaggedList());
|
return new STUTaggedList(u.getTaggedList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int STUTaggedList::getLength() const
|
||||||
|
{
|
||||||
|
int ret=Serializer::getTaggedListLength(value);
|
||||||
|
if(ret<0) throw(0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@@ -202,11 +202,11 @@ public:
|
|||||||
class STUTaggedList
|
class STUTaggedList
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::list<TaggedListItem> value;
|
std::vector<TaggedListItem> value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STUTaggedList(const std::list<TaggedListItem>& v) : value(v) { ; }
|
STUTaggedList(const std::vector<TaggedListItem>& v) : value(v) { ; }
|
||||||
STUTaggedList() { ; }
|
STUTaggedList() { ; }
|
||||||
static STUTaggedList* construct(SerializerIterator&);
|
static STUTaggedList* construct(SerializerIterator&);
|
||||||
|
|
||||||
@@ -214,13 +214,13 @@ public:
|
|||||||
SerializedTypeID getType() const { return STI_TL; }
|
SerializedTypeID getType() const { return STI_TL; }
|
||||||
STUTaggedList *duplicate() const { return new STUTaggedList(value); }
|
STUTaggedList *duplicate() const { return new STUTaggedList(value); }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
virtual void add(Serializer& s) const { s.addTaggedList(value); }
|
virtual void add(Serializer& s) const { if(s.addTaggedList(value)<0) throw(0); }
|
||||||
|
|
||||||
const std::list<TaggedListItem>& peekValue() const { return value; }
|
const std::vector<TaggedListItem>& peekValue() const { return value; }
|
||||||
std::list<TaggedListItem>& peekValue() { return value; }
|
std::vector<TaggedListItem>& peekValue() { return value; }
|
||||||
std::list<TaggedListItem> getValue() const { return value; }
|
std::vector<TaggedListItem> getValue() const { return value; }
|
||||||
|
|
||||||
void setValue(std::list<TaggedListItem>& v) { value=v; }
|
void setValue(std::vector<TaggedListItem>& v) { value=v; }
|
||||||
|
|
||||||
int getItemCount() const { return value.size(); }
|
int getItemCount() const { return value.size(); }
|
||||||
bool isEmpty() const { return value.empty(); }
|
bool isEmpty() const { return value.empty(); }
|
||||||
@@ -228,8 +228,8 @@ public:
|
|||||||
void clear() { value.erase(value.begin(), value.end()); }
|
void clear() { value.erase(value.begin(), value.end()); }
|
||||||
void addItem(const TaggedListItem& v) { value.push_back(v); }
|
void addItem(const TaggedListItem& v) { value.push_back(v); }
|
||||||
|
|
||||||
operator std::list<TaggedListItem>() const { return value; }
|
operator std::vector<TaggedListItem>() const { return value; }
|
||||||
STUTaggedList& operator=(const std::list<TaggedListItem>& v) { value=v; return *this; }
|
STUTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -271,6 +271,28 @@ int Serializer::addTaggedList(const std::vector<TaggedListItem>& list)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Serializer::getTaggedListLength(const std::list<TaggedListItem>& list)
|
||||||
|
{
|
||||||
|
int size=list.size();
|
||||||
|
if(size>255) return -1;
|
||||||
|
int ret=1;
|
||||||
|
if(size!=0)
|
||||||
|
for(std::list<TaggedListItem>::const_iterator it=list.begin(); it!=list.end(); ++it)
|
||||||
|
ret+=1 + it->second.size() + Serializer::encodeLengthLength(it->second.size());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Serializer::getTaggedListLength(const std::vector<TaggedListItem>& list)
|
||||||
|
{
|
||||||
|
int size=list.size();
|
||||||
|
if(size>255) return -1;
|
||||||
|
int ret=1;
|
||||||
|
if(size!=0)
|
||||||
|
for(std::vector<TaggedListItem>::const_iterator it=list.begin(); it!=list.end(); ++it)
|
||||||
|
ret+=1 + it->second.size() + Serializer::encodeLengthLength(it->second.size());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const
|
bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const
|
||||||
{
|
{
|
||||||
int b1;
|
int b1;
|
||||||
@@ -355,6 +377,25 @@ bool Serializer::getTaggedList(std::list<TaggedListItem>& list, int offset, int&
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Serializer::getTaggedList(std::vector<TaggedListItem>& list, int offset, int& length) const
|
||||||
|
{
|
||||||
|
list.clear();
|
||||||
|
int startOffset=offset;
|
||||||
|
int numElem;
|
||||||
|
if(!get8(numElem, offset++)) return false;
|
||||||
|
for(int i=0; i<numElem; i++)
|
||||||
|
{
|
||||||
|
int tag, len;
|
||||||
|
std::vector<unsigned char> data;
|
||||||
|
if(!get8(tag, offset++)) return false;
|
||||||
|
if(!getVL(data, offset, len)) return false;
|
||||||
|
offset+=len;
|
||||||
|
list.push_back(std::make_pair(tag, data));
|
||||||
|
}
|
||||||
|
length=offset-startOffset;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> Serializer::encodeVL(int length) throw()
|
std::vector<unsigned char> Serializer::encodeVL(int length) throw()
|
||||||
{
|
{
|
||||||
unsigned char lenBytes[4];
|
unsigned char lenBytes[4];
|
||||||
@@ -381,7 +422,7 @@ std::vector<unsigned char> Serializer::encodeVL(int length) throw()
|
|||||||
else throw(std::overflow_error("lenlen"));
|
else throw(std::overflow_error("lenlen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int encodeLengthLength(int length) throw()
|
int Serializer::encodeLengthLength(int length) throw()
|
||||||
{
|
{
|
||||||
if(length<0) throw(std::overflow_error("len<0"));
|
if(length<0) throw(std::overflow_error("len<0"));
|
||||||
if(length<=192) return 1;
|
if(length<=192) return 1;
|
||||||
@@ -487,10 +528,10 @@ std::vector<unsigned char> SerializerIterator::getVL() throw()
|
|||||||
return vl;
|
return vl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<TaggedListItem> SerializerIterator::getTaggedList() throw()
|
std::vector<TaggedListItem> SerializerIterator::getTaggedList() throw()
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
std::list<TaggedListItem> tl;
|
std::vector<TaggedListItem> tl;
|
||||||
if(!mSerializer.getTaggedList(tl, mPos, length)) throw(0);
|
if(!mSerializer.getTaggedList(tl, mPos, length)) throw(0);
|
||||||
mPos+=length;
|
mPos+=length;
|
||||||
return tl;
|
return tl;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class Serializer
|
|||||||
int addVL(const void *ptr, int len);
|
int addVL(const void *ptr, int len);
|
||||||
int addTaggedList(const std::list<TaggedListItem>&);
|
int addTaggedList(const std::list<TaggedListItem>&);
|
||||||
int addTaggedList(const std::vector<TaggedListItem>&);
|
int addTaggedList(const std::vector<TaggedListItem>&);
|
||||||
|
static int getTaggedListLength(const std::list<TaggedListItem>&);
|
||||||
|
static int getTaggedListLength(const std::vector<TaggedListItem>&);
|
||||||
|
|
||||||
// disassemble functions
|
// disassemble functions
|
||||||
bool get8(int&, int offset) const;
|
bool get8(int&, int offset) const;
|
||||||
@@ -54,7 +56,8 @@ class Serializer
|
|||||||
|
|
||||||
bool getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const;
|
bool getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const;
|
||||||
bool getVLLength(int& length, int offset) const;
|
bool getVLLength(int& length, int offset) const;
|
||||||
bool getTaggedList(std::list<TaggedListItem>&, int offset, int& legnth) const;
|
bool getTaggedList(std::list<TaggedListItem>&, int offset, int& length) const;
|
||||||
|
bool getTaggedList(std::vector<TaggedListItem>&, int offset, int& length) const;
|
||||||
|
|
||||||
|
|
||||||
// hash functions
|
// hash functions
|
||||||
@@ -84,7 +87,7 @@ class Serializer
|
|||||||
|
|
||||||
// low-level VL length encode/decode functions
|
// low-level VL length encode/decode functions
|
||||||
static std::vector<unsigned char> encodeVL(int length) throw();
|
static std::vector<unsigned char> encodeVL(int length) throw();
|
||||||
static int encodeLengthLength(int length) throw();
|
static int encodeLengthLength(int length) throw(); // length to encode length
|
||||||
static int decodeLengthLength(int b1) throw();
|
static int decodeLengthLength(int b1) throw();
|
||||||
static int decodeVLLength(int b1) throw();
|
static int decodeVLLength(int b1) throw();
|
||||||
static int decodeVLLength(int b1, int b2) throw();
|
static int decodeVLLength(int b1, int b2) throw();
|
||||||
@@ -117,7 +120,7 @@ public:
|
|||||||
uint256 get256() throw();
|
uint256 get256() throw();
|
||||||
|
|
||||||
std::vector<unsigned char> getVL() throw();
|
std::vector<unsigned char> getVL() throw();
|
||||||
std::list<TaggedListItem> getTaggedList() throw();
|
std::vector<TaggedListItem> getTaggedList() throw();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user