<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_shortstr(self, s):
 """ Write a string up to 255 bytes long after encoding. If passed a unicode string, encode as UTF-8. """

        if isinstance(s, unicode):
            s = s.encode('utf-8')
        self.write_octet(len(s))
        self.write(s)
        return self