def encode(self, message, header_params):
     header_params = header_params.copy()
     header = Header(self.name)
     self._encode_fields(header, header_params, little_endian=self.little_endian)
     if self.pdu_length:
         self.pdu_length.find_length_and_set_if_necessary(header, len(message._get_raw_bytes()), little_endian=self.little_endian)
     return header
Example #2
0
 def read(self, stream, timeout=None):
     #TODO: use all data if length cannot be obtained. Return amount of data
     #used to stream
     data = stream.read(self.header_length(), timeout=timeout)
     header = Header(self.name)
     unused_data = self._extract_values_from_data(data, header, self._fields.values())
     stream.return_data(unused_data)
     pdu_bytes = None
     if self.pdu:
         length_param = header[self.pdu_length.field].int
         pdu_bytes = stream.read(self.pdu_length.calc_value(length_param))
     return header, pdu_bytes
Example #3
0
 def read(self, stream, timeout=None):
     # TODO: use all data if length cannot be obtained. Return amount of data
     # used to stream
     data = stream.read(self.header_length(), timeout=timeout)
     header = Header(self.name)
     unused_data = self._extract_values_from_data(
         data, header, list(self._fields.values()))
     stream.return_data(unused_data)
     pdu_bytes = None
     if self.pdu:
         if self.pdu_length.static:
             length = self.pdu_length.value
         else:
             length = self.pdu_length.calc_value(
                 header[self.pdu_length.field].int)
         # TODO: we need a timeout?
         pdu_bytes = stream.read(length)
     return header, pdu_bytes