diff --git a/src/Rammbock/core.py b/src/Rammbock/core.py index a1edf4c..4a79e82 100644 --- a/src/Rammbock/core.py +++ b/src/Rammbock/core.py @@ -193,6 +193,14 @@ def _start_client(self, client_class, ip=None, port=None, name=None, timeout=Non client.set_own_ip_and_port(ip=ip, port=port) return self._clients.add(client, name) + def _is_client(self, client_name): + client_exist = True + try: + self._clients.get_with_name(client_name) + except KeyError: + client_exist = False + return client_exist + def _get_protocol(self, protocol): try: protocol = self._protocols[protocol] if protocol else None @@ -206,6 +214,19 @@ def get_client_protocol(self, name=None): """ return self._clients.get(name).protocol_name or '' + def update_client_protocol(self, protocol, client=None): + """Updates client protocol. If client is not + given then update the latest client. + + Examples: + | Update client protocol | protocol_name | + | Update client protocol | protocol_name | client_name | + """ + protocol = self._get_protocol(protocol) + client = self._clients.get(client) + client.set_protocol(protocol) + client.update_message_stream() + def accept_connection(self, name=None, alias=None): """Accepts a connection to server identified by `name` or the latest server if `name` is empty. diff --git a/src/Rammbock/networking.py b/src/Rammbock/networking.py index 2fe28e3..53d5740 100644 --- a/src/Rammbock/networking.py +++ b/src/Rammbock/networking.py @@ -306,6 +306,12 @@ def connect_to(self, server_ip, server_port): self._is_connected = True return self + def set_protocol(self, protocol): + self._protocol = protocol + + def update_message_stream(self): + self._message_stream = self._get_message_stream() + class UDPClient(_Client, _UDPNode): pass diff --git a/src/Rammbock/templates/primitives.py b/src/Rammbock/templates/primitives.py index b7c2e1a..5a6351c 100644 --- a/src/Rammbock/templates/primitives.py +++ b/src/Rammbock/templates/primitives.py @@ -137,7 +137,7 @@ def __init__(self, length, name, default_value=None, align=None): self.length = Length(length, align) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) length, aligned_length = self.length.decode_lengths(message) binary = to_bin_of_length(length, value) binary = binary[::-1] if little_endian else binary @@ -162,7 +162,7 @@ def _get_int_value(self, message, value): return to_twos_comp(value, bin_len) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) value = self._get_int_value(message, value) return UInt._encode_value(self, value, message, little_endian) @@ -202,7 +202,7 @@ def __init__(self, length, name, default_value=None): raise AssertionError('Binary field length must be static. Length: %s' % length) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) minimum_binary = to_bin(value) length, aligned = self.length.decode_lengths(message, len(minimum_binary)) binary = to_bin_of_length(self._byte_length(length), value)