Browse Source

add payload property to messages

pull/202/head
Rossen Georgiev 6 years ago
parent
commit
97087b54ea
  1. 27
      steam/core/msg/__init__.py
  2. 2
      steam/core/msg/headers.py

27
steam/core/msg/__init__.py

@ -42,7 +42,7 @@ def get_cmsg(emsg):
"""Get protobuf for a given EMsg """Get protobuf for a given EMsg
:param emsg: EMsg :param emsg: EMsg
:type emsg: :class:`steam.enums.emsg.EMsg`, :class:`int` :type emsg: :class:`steam.enums.emsg.EMsg`, :class:`int`
:return: protobuf message :return: protobuf message
""" """
if not isinstance(emsg, EMsg): if not isinstance(emsg, EMsg):
@ -60,7 +60,8 @@ def get_cmsg(emsg):
class Msg(object): class Msg(object):
proto = False proto = False
body = '!!! NO BODY !!!' body = '!!! Unknown message body !!!' #: message instance
payload = None #: Will contain body payload, if we fail to find correct message class
def __init__(self, msg, data=None, extended=False): def __init__(self, msg, data=None, extended=False):
self.extended = extended self.extended = extended
@ -74,6 +75,8 @@ class Msg(object):
if deserializer: if deserializer:
self.body = deserializer(data) self.body = deserializer(data)
else:
self.payload = data
@property @property
def msg(self): def msg(self):
@ -124,12 +127,17 @@ class Msg(object):
rows.append("---------------- body --") rows.append("---------------- body --")
rows.append(body if body else "(empty)") rows.append(body if body else "(empty)")
if self.payload:
rows.append("------------- payload --")
rows.append(repr(self.payload))
return '\n'.join(rows) return '\n'.join(rows)
class MsgProto(object): class MsgProto(object):
proto = True proto = True
body = "!!! NO BODY !!!" body = '!!! Unknown message body !!!' #: protobuf message instance
payload = None #: Will contain body payload, if we fail to find correct proto message
def __init__(self, msg, data=None): def __init__(self, msg, data=None):
self._header = MsgHdrProtoBuf(data) self._header = MsgHdrProtoBuf(data)
@ -141,16 +149,19 @@ class MsgProto(object):
if proto: if proto:
self.body = proto() self.body = proto()
else: else:
self.body = '!! Can\'t resolve ServiceMethod: %s !!' % repr(self.header.target_job_name) self.body = '!! Failed to resolve UM for: %s !!' % repr(self.header.target_job_name)
else: else:
proto = get_cmsg(msg) proto = get_cmsg(msg)
if proto: if proto:
self.body = proto() self.body = proto()
if data: if data:
data = data[self._header._fullsize:] data = data[self._header._fullsize:]
if proto:
self.body.ParseFromString(data) self.body.ParseFromString(data)
else:
self.payload = data
@property @property
def msg(self): def msg(self):
@ -193,5 +204,9 @@ class MsgProto(object):
rows.append("---------------- body --") rows.append("---------------- body --")
rows.append(body if body else "(empty)") rows.append(body if body else "(empty)")
if self.payload:
rows.append("------------- payload --")
rows.append(repr(self.payload))
return '\n'.join(rows) return '\n'.join(rows)

2
steam/core/msg/headers.py

@ -83,7 +83,7 @@ class ExtendedMsgHdr:
class MsgHdrProtoBuf: class MsgHdrProtoBuf:
_size = struct.calcsize("<II") _size = _fullsize = struct.calcsize("<II")
msg = EMsg.Invalid msg = EMsg.Invalid
def __init__(self, data=None): def __init__(self, data=None):

Loading…
Cancel
Save