def read_msg(self, data, offset):
        msg_headers = self.read_msg_header(data, offset)

        msg_header = msg_headers[0]
        msg_offset = msg_headers[1]

        msg = Message(msg_header[0])

        for idx, field_name in enumerate(msg_header):
            if idx > 0:
                sigs = self.read_signature(data, msg_offset)
                sig = sigs[0]
                msg_offset = sigs[1]

                if sig == self.packet_type.INTEGER:
                    rtn_ints = self.read_int(data, msg_offset)
                    rtn_int = rtn_ints[0]
                    msg_offset = rtn_ints[1]

                    msg.set_int(field_name, rtn_int)

                elif sig == self.packet_type.FLOAT:
                    rtn_floats = self.read_float(data, msg_offset)
                    rtn_float = rtn_floats[0]
                    msg_offset = rtn_floats[1]

                    msg.set_float(field_name, rtn_float)
                elif sig == self.packet_type.LONG:
                    rtn_longs = self.read_long(data, msg_offset)
                    rtn_long = rtn_longs[0]
                    msg_offset = rtn_longs[1]

                    msg.set_long(field_name, rtn_long)
                elif sig == self.packet_type.STRING:
                    rtn_strs = self.read_str(data, msg_offset)
                    rtn_str = rtn_strs[0]
                    msg_offset = rtn_strs[1]

                    msg.set_str(field_name, rtn_str)
                elif sig == self.packet_type.BYTES:
                    rtn_bins = self.read_bytes(data, msg_offset)
                    rtn_bin = rtn_bins[0]
                    msg_offset = rtn_bins[1]

                    msg.set_bytes(field_name, rtn_bin)
                elif sig == self.packet_type.COMPLEX:
                    rtn_msgs = self.read_msg(data, msg_offset)
                    rtn_msg = rtn_msgs[0]
                    msg_offset = rtn_msgs[1]

                    msg.set_msg(field_name, rtn_msg)
                elif sig == self.packet_type.ARRAY:
                    rtn_arrays = self.read_array(data, msg_offset)
                    rtn_array = rtn_arrays[0]
                    msg_offset = rtn_arrays[1]

                    msg.set_array(field_name, rtn_array)

        return (msg, msg_offset)
Beispiel #2
0
import copy

import struct

from insoft.openmanager.message.message import Message
from insoft.openmanager.message.packet import Packet
from insoft.openmanager.message.packet_reader import PacketReader
from insoft.openmanager.message.packet_writer import PacketWriter

msg = Message("MESSAGE_TEST")

msg.set_int("integer", 1)
msg.set_float("float", 2.0)
msg.set_long("long", 3)
msg.set_str("str", "message_test")
msg.set_bytes("byte", bytes("message", "utf-8"))
msg.set_msg("msg", Message("NEW_MESSAGE"))
msg.set_array("array", ["A", "B", "C"])

print(msg)