forked from APrioriInvestments/typed_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializationContext.hpp
More file actions
48 lines (36 loc) · 1.23 KB
/
Copy pathSerializationContext.hpp
File metadata and controls
48 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
class SerializationBuffer;
class DeserializationBuffer;
//models a contiguous range of bytes. Underlying could be python data
//or c++ data.
class ByteBuffer {
public:
ByteBuffer() {};
virtual ~ByteBuffer() {} ;
virtual std::pair<uint8_t*, uint8_t*> range() = 0;
size_t size() {
return range().second - range().first;
}
};
//a contiguous range of bytes that are guaranteed to live for the duration
//of the object, held as a begin/end pointer pair
class RangeByteBuffer : public ByteBuffer {
public:
RangeByteBuffer(uint8_t* low, uint8_t* high) : m_low(low), m_high(high) {
}
virtual ~RangeByteBuffer() { }
virtual std::pair<uint8_t*, uint8_t*> range() {
return std::make_pair(m_low, m_high);
}
private:
uint8_t* m_low;
uint8_t* m_high;
};
class SerializationContext {
public:
virtual ~SerializationContext() {};
virtual void serializePythonObject(PyObject* o, SerializationBuffer& b) const = 0;
virtual PyObject* deserializePythonObject(DeserializationBuffer& b) const = 0;
virtual std::shared_ptr<ByteBuffer> compress(uint8_t* begin, uint8_t* end) const = 0;
virtual std::shared_ptr<ByteBuffer> decompress(uint8_t* begin, uint8_t* end) const = 0;
};