<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def packto(self, namedstruct, stream):
 """ Pack a struct to a stream """

        if hasattr(namedstruct, self.name):
            return _tostream(self.basetypeparser, getattr(namedstruct, self.name), stream, True)
        else:
            return 0