Issues (227)

dynamicserialize/adapters/GeomDataRespAdapter.py (2 issues)

1
#
2
#    Efficient adapter for GetGeometryDataResponse
3
#
4
#
5
#    SOFTWARE HISTORY
6
#
7
#    Date            Ticket#       Engineer       Description
8
#    ------------    ----------    -----------    --------------------------
9
#    Oct 17, 2016     5919         njensen        Initial creation
10
#
11
#
12
#
13
14
from dynamicserialize.dstypes.com.raytheon.uf.common.dataaccess.response import GeometryResponseData
15
from dynamicserialize.dstypes.com.raytheon.uf.common.dataaccess.response import GetGeometryDataResponse
16
17
ClassAdapter = 'com.raytheon.uf.common.dataaccess.response.GetGeometryDataResponse'
18
19
20 View Code Duplication
def serialize(context, resp):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
21
    wkbs = resp.getGeometryWKBs()
22
    # write list size
23
    context.writeI32(len(wkbs))
24
    # write byte arrays
25
    for b in wkbs:
26
        context.writeBinary(b)
27
28
    geoData = resp.getGeoData()
29
    # write list size
30
    context.writeI32(len(geoData))
31
    # write objects
32
    for geo in geoData:
33
        context.writeI32(geo.getGeometryWKBindex())
34
        context.writeObject(geo.getTime())
35
        context.writeObject(geo.getLevel())
36
        context.writeObject(geo.getLocationName())
37
        context.writeObject(geo.getAttributes())
38
39
        # write data map
40
        params = geo.getDataMap()
41
        context.writeI32(len(params))
42
        for p in params:
43
            context.writeString(p)
44
            value = params[p]
45
            # actual value
46
            context.writeObject(value[0])
47
            # value type as string
48
            context.writeString(str(value[1]))
49
            # unit
50
            context.writeObject(value[2])
51
52
53 View Code Duplication
def deserialize(context):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
54
    size = context.readI32()
55
    wkbs = []
56
    for __ in range(size):
57
        wkb = context.readBinary()
58
        wkbs.append(wkb)
59
60
    geoData = []
61
    size = context.readI32()
62
    for _ in range(size):
63
        data = GeometryResponseData()
64
        # wkb index
65
        wkbIndex = context.readI32()
66
        data.setGeometryWKBindex(wkbIndex)
67
68
        time = context.readObject()
69
        data.setTime(time)
70
        level = context.readObject()
71
        data.setLevel(level)
72
        locName = context.readObject()
73
        data.setLocationName(locName)
74
        attrs = context.readObject()
75
        data.setAttributes(attrs)
76
77
        # parameters
78
        paramSize = context.readI32()
79
        paramMap = {}
80
        for __ in range(paramSize):
81
            paramName = context.readString()
82
            value = context.readObject()
83
            tName = context.readString()
84
            unit = context.readObject()
85
            paramMap[paramName] = [value, tName, unit]
86
        data.setDataMap(paramMap)
87
        geoData.append(data)
88
89
    # make the response object
90
    resp = GetGeometryDataResponse()
91
    resp.setGeometryWKBs(wkbs)
92
    resp.setGeoData(geoData)
93
94
    return resp
95