Files
xahaud/Serializer.h
JoelKatz ebb9a9c255 Build enough information into the leaf nodes so that they can be parsed
without knowledge of the objects they contain. This will allow new
transaction or account formats to be added (possibly with larger data sizes)
without breaking the ability to parse the hash trees. It also simplifies
the operation-specific tree code (since it doesn't have to parse the raw
leaf data).
2011-11-28 13:59:34 -08:00

61 lines
1.8 KiB
C++

#ifndef __SERIALIZER__
#define __SERIALIZER__
#include <vector>
#include <boost/shared_ptr.hpp>
#include "key.h"
#include "uint256.h"
class Serializer
{
public:
typedef boost::shared_ptr<Serializer> pointer;
protected:
std::vector<unsigned char> mData;
public:
Serializer(int n=256) { mData.reserve(n); }
Serializer(const std::vector<unsigned char> &data) : mData(data) { ; }
// assemble functions
int add16(uint16);
int add32(uint32); // ledger indexes, account sequence
int add64(uint64); // timestamps, amounts
int add160(const uint160&); // account names, hankos
int add256(const uint256&); // transaction and ledger hashes
int addRaw(const std::vector<unsigned char> &vector);
// disassemble functions
bool get16(uint16&, int offset) const;
bool get32(uint32&, int offset) const;
bool get64(uint64&, int offset) const;
bool get160(uint160&, int offset) const;
bool get256(uint256&, int offset) const;
uint256 get256(int offset) const;
bool getRaw(std::vector<unsigned char>&, int offset, int length) const;
std::vector<unsigned char> getRaw(int offset, int length) const;
// hash functions
uint160 getRIPEMD160(int size=0) const;
uint256 getSHA256(int size=0) const;
uint256 getSHA512Half(int size=0) const;
// totality functions
int getLength() const { return mData.size(); }
const std::vector<unsigned char>& peekData() const { return mData; }
std::vector<unsigned char> getData() const { return mData; }
// signature functions
bool checkSignature(int pubkeyOffset, int signatureOffset) const;
bool checkSignature(const std::vector<unsigned char> &signature, CKey& rkey) const;
bool makeSignature(std::vector<unsigned char> &signature, CKey& rkey) const;
bool addSignature(CKey& rkey);
static void TestSerializer(void);
};
#endif