@@ 74-104 (lines=31) @@ | ||
71 | self.flags = flags |
|
72 | self.body = body |
|
73 | ||
74 | def pack(self, value=None): |
|
75 | """Pack a MultipartRequest using the object's attributes. |
|
76 | ||
77 | This method will pack the attribute body and multipart_type before pack |
|
78 | the MultipartRequest object, then will return this struct as a |
|
79 | binary data. |
|
80 | ||
81 | Args: |
|
82 | value (:class:`~MultipartRequest`): Object to be packed. |
|
83 | ||
84 | Returns: |
|
85 | bytes: Binary data with MultipartRequest packed. |
|
86 | ||
87 | """ |
|
88 | buff = self.body |
|
89 | if not value: |
|
90 | value = self.body |
|
91 | ||
92 | if value: |
|
93 | if isinstance(value, (list, FixedTypeList)): |
|
94 | obj = self._get_body_instance() |
|
95 | obj.extend(value) |
|
96 | elif hasattr(value, 'pack'): |
|
97 | obj = value |
|
98 | ||
99 | self.body = obj.pack() |
|
100 | ||
101 | multipart_packed = super().pack() |
|
102 | self.body = buff |
|
103 | ||
104 | return multipart_packed |
|
105 | ||
106 | def unpack(self, buff, offset=0): |
|
107 | """Unpack a binary message into this object's attributes. |
@@ 88-114 (lines=27) @@ | ||
85 | self.flags = flags |
|
86 | self.body = body |
|
87 | ||
88 | def pack(self, value=None): |
|
89 | """Pack a StatsReply using the object's attributes. |
|
90 | ||
91 | This method will pack the attribute body and multipart_type before pack |
|
92 | the StatsReply object, then will return this struct as a binary data. |
|
93 | ||
94 | Returns: |
|
95 | stats_reply_packed (bytes): Binary data with StatsReply packed. |
|
96 | ||
97 | """ |
|
98 | buff = self.body |
|
99 | if not value: |
|
100 | value = self.body |
|
101 | ||
102 | if value: |
|
103 | if isinstance(value, (list, FixedTypeList)): |
|
104 | obj = self._get_body_instance() |
|
105 | obj.extend(value) |
|
106 | elif hasattr(value, 'pack'): |
|
107 | obj = value |
|
108 | ||
109 | self.body = obj.pack() |
|
110 | ||
111 | multipart_packed = super().pack() |
|
112 | self.body = buff |
|
113 | ||
114 | return multipart_packed |
|
115 | ||
116 | def unpack(self, buff, offset=0): |
|
117 | """Unpack a binary message into this object's attributes. |