code: def read_chunk(cls, sock, return_bytes=False):
      
      try:
        # Read the chunk header from the socket.
        header = cls._read_until(sock, cls.HEADER_BYTES)
      except cls.TruncatedRead as e:
        raise cls.TruncatedHeaderError('Failed to read nailgun chunk header ({!r}).'.format(e))
  
      # Unpack the chunk header.
      payload_len, chunk_type = struct.unpack(cls.HEADER_FMT, header)
  
      try:
        # Read the chunk payload.
        payload = cls._read_until(sock, payload_len)
      except cls.TruncatedRead as e:
        raise cls.TruncatedPayloadError('Failed to read nailgun chunk payload ({!r}).'.format(e))
  
      # In the case we get an otherwise well-formed chunk, check the chunk_type for validity _after_
      # we've drained the payload from the socket to avoid subsequent reads of a stale payload.
      if chunk_type not in ChunkType.VALID_TYPES:
        raise cls.ProtocolError('invalid chunk type: {}'.format(chunk_type))
      if not return_bytes:
        payload = payload.decode('utf-8')
  
      return chunk_type, payload
docs: Read a single chunk from the connected client.
  
       A "chunk" is a variable-length block of data beginning with a 5-byte chunk header and followed
       by an optional payload. The chunk header consists of:
  
            1) The length of the chunk's payload (not including the header) as a four-byte big-endian
               unsigned long. The high-order byte is header[0] and the low-order byte is header[3].
  
            2) A single byte identifying the type of chunk.