code: def from_bytearray(self, stream):
          
          fmt = '>HHHBB'
          size_header = struct.calcsize(fmt)
          if len(stream) < size_header:
              raise EOFError
  
          (
              self.transaction_id,
              self.protocol_id,
              self.length,
              self.unit_id,
              self.fcode
          ) = struct.unpack(fmt, bytes(stream[:size_header]))
  
          size_total = size_header + self.length - 2
          if len(stream) < size_total:
              raise EOFError
  
          self.data = stream[size_header:size_total]
          del stream[:size_total]
docs: Constructs this frame from input data stream, consuming as many bytes as necessary from
          the beginning of the stream.
  
          If stream does not contain enough data to construct a complete modbus frame, an EOFError
          is raised and no data is consumed.
  
          :param stream: bytearray to consume data from to construct this frame.
          :except EOFError: Not enough data for complete frame; no data consumed.