Commit 47d42d56 authored by Aurel's avatar Aurel

do not hardcode the value everywhere, use a global variable instead


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@302 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6fa4ebc3
...@@ -27,7 +27,7 @@ PROTOCOL_VERSION = (4, 0) ...@@ -27,7 +27,7 @@ PROTOCOL_VERSION = (4, 0)
# Size restrictions. # Size restrictions.
MIN_PACKET_SIZE = 10 MIN_PACKET_SIZE = 10
MAX_PACKET_SIZE = 0x100000 MAX_PACKET_SIZE = 0x100000
PACKET_HEADER_SIZE = 10
# Message types. # Message types.
# Error is a special type of message, because this can be sent against any other message, # Error is a special type of message, because this can be sent against any other message,
...@@ -252,7 +252,7 @@ class Packet(object): ...@@ -252,7 +252,7 @@ class Packet(object):
# logging.debug('parsing %s', dump(msg)) # logging.debug('parsing %s', dump(msg))
if len(msg) < MIN_PACKET_SIZE: if len(msg) < MIN_PACKET_SIZE:
return None return None
msg_id, msg_type, msg_len = unpack('!LHL', msg[:10]) msg_id, msg_type, msg_len = unpack('!LHL', msg[:PACKET_HEADER_SIZE])
if msg_len > MAX_PACKET_SIZE: if msg_len > MAX_PACKET_SIZE:
raise ProtocolError(cls(msg_id, msg_type), raise ProtocolError(cls(msg_id, msg_type),
'message too big (%d)' % msg_len) 'message too big (%d)' % msg_len)
...@@ -262,7 +262,7 @@ class Packet(object): ...@@ -262,7 +262,7 @@ class Packet(object):
if len(msg) < msg_len: if len(msg) < msg_len:
# Not enough. # Not enough.
return None return None
return cls(msg_id, msg_type, msg[10:msg_len]) return cls(msg_id, msg_type, msg[PACKET_HEADER_SIZE:msg_len])
def __init__(self, msg_id = None, msg_type = None, body = None): def __init__(self, msg_id = None, msg_type = None, body = None):
self._id = msg_id self._id = msg_id
...@@ -276,11 +276,11 @@ class Packet(object): ...@@ -276,11 +276,11 @@ class Packet(object):
return self._type return self._type
def __len__(self): def __len__(self):
return 10 + len(self._body) return PACKET_HEADER_SIZE + len(self._body)
# Encoders. # Encoders.
def encode(self): def encode(self):
msg = pack('!LHL', self._id, self._type, 10 + len(self._body)) + self._body msg = pack('!LHL', self._id, self._type, PACKET_HEADER_SIZE + len(self._body)) + self._body
logging.debug('encoding %d:%x', self._id, self._type) logging.debug('encoding %d:%x', self._id, self._type)
if len(msg) > MAX_PACKET_SIZE: if len(msg) > MAX_PACKET_SIZE:
raise RuntimeError('message too big (%d)' % len(msg)) raise RuntimeError('message too big (%d)' % len(msg))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment