|
1
|
|
|
# |
|
2
|
|
|
# A port of the Java DynamicSerializeManager. Should be used to read/write |
|
3
|
|
|
# DynamicSerialize binary data. |
|
4
|
|
|
# |
|
5
|
|
|
# |
|
6
|
|
|
# SOFTWARE HISTORY |
|
7
|
|
|
# |
|
8
|
|
|
# Date Ticket# Engineer Description |
|
9
|
|
|
# ------------ ---------- ----------- -------------------------- |
|
10
|
|
|
# 06/09/10 njensen Initial Creation. |
|
11
|
|
|
# |
|
12
|
|
|
|
|
13
|
|
|
from thrift.transport import TTransport |
|
14
|
|
|
from . import SelfDescribingBinaryProtocol, ThriftSerializationContext |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
class DynamicSerializationManager: |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def __init__(self): |
|
20
|
|
|
self.transport = None |
|
21
|
|
|
|
|
22
|
|
|
def _deserialize(self, ctx): |
|
23
|
|
|
return ctx.deserializeMessage() |
|
24
|
|
|
|
|
25
|
|
|
def deserializeBytes(self, sbytes): |
|
26
|
|
|
ctx = self._buildSerializationContext(sbytes) |
|
27
|
|
|
ctx.readMessageStart() |
|
28
|
|
|
obj = self._deserialize(ctx) |
|
29
|
|
|
ctx.readMessageEnd() |
|
30
|
|
|
return obj |
|
31
|
|
|
|
|
32
|
|
|
def _buildSerializationContext(self, sbytes=None): |
|
33
|
|
|
self.transport = TTransport.TMemoryBuffer(sbytes) |
|
34
|
|
|
protocol = SelfDescribingBinaryProtocol.SelfDescribingBinaryProtocol(self.transport) |
|
35
|
|
|
return ThriftSerializationContext.ThriftSerializationContext(self, protocol) |
|
36
|
|
|
|
|
37
|
|
|
def serializeObject(self, obj): |
|
38
|
|
|
ctx = self._buildSerializationContext() |
|
39
|
|
|
ctx.writeMessageStart("dynamicSerialize") |
|
40
|
|
|
self._serialize(ctx, obj) |
|
41
|
|
|
ctx.writeMessageEnd() |
|
42
|
|
|
return self.transport.getvalue() |
|
43
|
|
|
|
|
44
|
|
|
def _serialize(self, ctx, obj): |
|
45
|
|
|
ctx.serializeMessage(obj) |
|
46
|
|
|
|