Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
jed
2012-11-24 11:21:36 -08:00
4 changed files with 14 additions and 130 deletions

View File

@@ -2,23 +2,23 @@
// appropriate #define statements.
// types (common)
TYPE("Int16", UINT16, 1)
TYPE("Int32", UINT32, 2)
TYPE("Int64", UINT64, 3)
TYPE("Hash128", HASH128, 4)
TYPE("Hash256", HASH256, 5)
TYPE("Amount", AMOUNT, 6)
TYPE("VariableLength", VL, 7)
TYPE("Account", ACCOUNT, 8)
TYPE(Int16, UINT16, 1)
TYPE(Int32, UINT32, 2)
TYPE(Int64, UINT64, 3)
TYPE(Hash128, HASH128, 4)
TYPE(Hash256, HASH256, 5)
TYPE(Amount, AMOUNT, 6)
TYPE(VariableLength, VL, 7)
TYPE(Account, ACCOUNT, 8)
// 9-13 are reserved
TYPE("Object", OBJECT, 14)
TYPE("Array", ARRAY, 15)
TYPE(Object, OBJECT, 14)
TYPE(Array, ARRAY, 15)
// types (uncommon)
TYPE("Int8", UINT8, 16)
TYPE("Hash160", HASH160, 17)
TYPE("PathSet", PATHSET, 18)
TYPE("Vector256", VECTOR256, 19)
TYPE(Int8, UINT8, 16)
TYPE(Hash160, HASH160, 17)
TYPE(PathSet, PATHSET, 18)
TYPE(Vector256, VECTOR256, 19)

View File

@@ -116,7 +116,6 @@ public:
RippleAddress getFieldAccount(SField::ref field) const;
uint160 getFieldAccount160(SField::ref field) const;
std::vector<unsigned char> getFieldVL(SField::ref field) const;
std::vector<TaggedListItem> getFieldTL(SField::ref field) const;
STAmount getFieldAmount(SField::ref field) const;
STPathSet getFieldPathSet(SField::ref field) const;
STVector256 getFieldV256(SField::ref field) const;
@@ -129,7 +128,6 @@ public:
void setFieldH160(SField::ref field, const uint160&);
void setFieldH256(SField::ref field, const uint256&);
void setFieldVL(SField::ref field, const std::vector<unsigned char>&);
void setFieldTL(SField::ref field, const std::vector<TaggedListItem>&);
void setFieldAccount(SField::ref field, const uint160&);
void setFieldAccount(SField::ref field, const RippleAddress& addr)
{ setFieldAccount(field, addr.getAccountID()); }

View File

@@ -380,64 +380,6 @@ int Serializer::addVL(const std::string& string)
return ret;
}
int Serializer::addTaggedList(const std::list<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = add8(size);
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
{
add8(it.first);
addVL(it.second);
}
}
return ret;
}
int Serializer::addTaggedList(const std::vector<TaggedListItem>& list)
{
int size = list.size();
if (size > 255) return -1;
int ret = add8(size);
if (size != 0)
{
BOOST_FOREACH(const TaggedListItem& it, list)
{
add8(it.first);
addVL(it.second);
}
}
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)
{
BOOST_FOREACH(const TaggedListItem& it, list)
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)
{
BOOST_FOREACH(const TaggedListItem& it, list)
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
{
int b1;
@@ -503,44 +445,6 @@ bool Serializer::getVLLength(int& length, int offset) const
return true;
}
bool Serializer::getTaggedList(std::list<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;
}
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)
{
unsigned char lenBytes[4];
@@ -692,15 +596,6 @@ std::vector<unsigned char> SerializerIterator::getVL()
return vl;
}
std::vector<TaggedListItem> SerializerIterator::getTaggedList()
{
int length;
std::vector<TaggedListItem> tl;
if (!mSerializer.getTaggedList(tl, mPos, length)) throw std::runtime_error("invalid serializer getTL");
mPos += length;
return tl;
}
std::vector<unsigned char> SerializerIterator::getRaw(int iLength)
{
int iPos = mPos;

View File

@@ -11,8 +11,6 @@
#include "uint256.h"
#include "FieldNames.h"
typedef std::pair<int, std::vector<unsigned char> > TaggedListItem;
class Serializer
{
public:
@@ -46,10 +44,6 @@ public:
int addVL(const std::vector<unsigned char> &vector);
int addVL(const std::string& string);
int addVL(const void *ptr, int len);
int addTaggedList(const std::list<TaggedListItem>&);
int addTaggedList(const std::vector<TaggedListItem>&);
static int getTaggedListLength(const std::list<TaggedListItem>&);
static int getTaggedListLength(const std::vector<TaggedListItem>&);
// disassemble functions
bool get8(int&, int offset) const;
@@ -66,8 +60,6 @@ public:
bool getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const;
bool getVLLength(int& length, int offset) const;
bool getTaggedList(std::list<TaggedListItem>&, int offset, int& length) const;
bool getTaggedList(std::vector<TaggedListItem>&, int offset, int& length) const;
bool getFieldID(int& type, int& name, int offset) const;
int addFieldID(int type, int name);
@@ -171,7 +163,6 @@ public:
std::vector<unsigned char> getRaw(int iLength);
std::vector<unsigned char> getVL();
std::vector<TaggedListItem> getTaggedList();
};
#endif