<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode(self, packet):
 """ Pushes a packet to the writer, encoding it on the internal buffer. """


        id = identifier.get_packet_id(packet)
        if id is None:
            raise EncoderException('unknown packet')

        self._write_variunt(id)
        self._write(packet.SerializeToString())

        return bytes(self.buffer)