edits
[iotcloud.git] / version2 / src / C / TransactionPart.h
index b89b57c..5e2d84a 100644 (file)
-
-
-class TransactionPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       public static final int MAX_NON_HEADER_SIZE = 512;
-
-       private int64_t sequenceNumber = -1;
-       private int64_t machineId = -1;
-       private int64_t arbitratorId = -1;
-       private int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
-       private int partNumber = -1;    // Parts position in the
-       private bool isLastPart = false;
-
-       private Pair<int64_t, int64_t> transactionId = NULL;
-       private Pair<int64_t int32_t> partId = NULL;
-
-       private char[] data = NULL;
-
-       public TransactionPart(Slot s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               arbitratorId = _arbitratorId;
-               clientLocalSequenceNumber = _clientLocalSequenceNumber;
-               partNumber = _partNumber;
-               data = _data;
-               isLastPart = _isLastPart;
-
-               transactionId = new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber);
-               partId = new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber);
-
-       }
-
-       public int getSize() {
-               if (data == NULL) {
-                       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       public void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       public Pair<int64_t, int64_t> getTransactionId() {
-               return transactionId;
-       }
-
-       public int64_t getArbitratorId() {
-               return arbitratorId;
-       }
-
-       public Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
-
-       public int getPartNumber() {
-               return partNumber;
-       }
-
-       public int getDataSize() {
-               return data.length;
-       }
-
-       public char[] getData() {
-               return data;
-       }
-
-       public bool isLastPart() {
-               return isLastPart;
-       }
-
-       public int64_t getMachineId() {
-               return machineId;
-       }
-
-       public int64_t getClientLocalSequenceNumber() {
-               return clientLocalSequenceNumber;
-       }
-
-
-       public int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
-
-       public void setSequenceNumber(int64_t _sequenceNumber) {
-               sequenceNumber = _sequenceNumber;
-       }
-
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t sequenceNumber = bb->getLong();
-               int64_t machineId = bb->getLong();
-               int64_t arbitratorId = bb->getLong();
-               int64_t clientLocalSequenceNumber = bb->getLong();
-               int partNumber = bb->getInt();
-               int dataSize = bb->getInt();
-               bool isLastPart = (bb->get() == 1);
-               // Get the data
-               char[] data = new char[dataSize];
-               bb->get(data);
-
-               TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               returnTransactionPart.setSequenceNumber(sequenceNumber);
-
-               return returnTransactionPart;
-       }
-
-       public void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeTransactionPart);
-               bb->putLong(sequenceNumber);
-               bb->putLong(machineId);
-               bb->putLong(arbitratorId);
-               bb->putLong(clientLocalSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
+#ifndef TRANSACTIONPART_H
+#define TRANSACTIONPART_H
+#include "common.h"
+#include "Entry.h"
+
+// Max size of the part excluding the fixed size header
+#define TransactionPart_MAX_NON_HEADER_SIZE 512
+
+class TransactionPart : public Entry {
+ private:
+       int64_t sequenceNumber = -1;
+       int64_t machineId = -1;
+       int64_t arbitratorId = -1;
+       int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
+       int partNumber = -1;    // Parts position in the
+       bool isLastPart = false;
+       
+       Pair<int64_t, int64_t> * transactionId = NULL;
+       Pair<int64_t int32_t> * partId = NULL;
+       
+       Array<char> * data = NULL;
+
+ public:
+ TransactionPart(Slot *s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, Array<char>* _data, bool _isLastPart) : Entry(s),
+               sequenceNumber(-1),
+               machineId( _machineId),
+               arbitratorId(_arbitratorId),
+               clientLocalSequenceNumber(_clientLocalSequenceNumber),
+               partNumber(_partNumber),
+               isLastPart(_isLastPart)
+               transactionId(new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber)),
+               partId(new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber)),
+               data(_data) {
                }
-
-               bb->put(data);
-       }
-
-       public char getType() {
-               return Entry.TypeTransactionPart;
-       }
-
-       public Entry getCopy(Slot s) {
-
-               TransactionPart copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               copyTransaction.setSequenceNumber(sequenceNumber);
-
-               return copyTransaction;
-       }
-}
+       
+       int getSize();
+       void setSlot(Slot s);
+       Pair<int64_t, int64_t> * getTransactionId();
+       int64_t getArbitratorId();
+       Pair<int64_t int32_t>* getPartId();
+       int getPartNumber();
+       int getDataSize();
+       Array<char>* getData();
+       bool isLastPart();
+       int64_t getMachineId();
+       int64_t getClientLocalSequenceNumber();
+       int64_t getSequenceNumber();
+       void setSequenceNumber(int64_t _sequenceNumber);
+       void encode(ByteBuffer *bb);
+       char getType();
+       Entry* getCopy(Slot *s);
+};
+
+Entry * TransactionPart_decode(Slot* s, ByteBuffer* bb);
+#endif