238 part = self._readpart() |
238 part = self._readpart() |
239 self.ui.debug('end of bundle2 stream\n') |
239 self.ui.debug('end of bundle2 stream\n') |
240 |
240 |
241 def _readpart(self): |
241 def _readpart(self): |
242 """return None when an end of stream markers is reach""" |
242 """return None when an end of stream markers is reach""" |
243 headersize = self._readexact(2) |
243 |
244 assert headersize == '\0\0' |
244 headersize = self._unpack(_fpartheadersize)[0] |
245 return None |
245 self.ui.debug('part header size: %i\n' % headersize) |
|
246 if not headersize: |
|
247 return None |
|
248 headerblock = self._readexact(headersize) |
|
249 # some utility to help reading from the header block |
|
250 self._offset = 0 # layer violation to have something easy to understand |
|
251 def fromheader(size): |
|
252 """return the next <size> byte from the header""" |
|
253 offset = self._offset |
|
254 data = headerblock[offset:(offset + size)] |
|
255 self._offset = offset + size |
|
256 return data |
|
257 typesize = _unpack(_fparttypesize, fromheader(1))[0] |
|
258 parttype = fromheader(typesize) |
|
259 self.ui.debug('part type: "%s"\n' % parttype) |
|
260 current = part(parttype) |
|
261 assert fromheader(2) == '\0\0' # no option for now |
|
262 del self._offset # clean up layer, nobody saw anything. |
|
263 self.ui.debug('part parameters: 0\n') |
|
264 assert self._readexact(4) == '\0\0\0\0' #empty payload |
|
265 self.ui.debug('payload chunk size: 0\n') |
|
266 return current |
|
267 |
246 |
268 |
247 class part(object): |
269 class part(object): |
248 """A bundle2 part contains application level payload |
270 """A bundle2 part contains application level payload |
249 |
271 |
250 The part `type` is used to route the part to the application level |
272 The part `type` is used to route the part to the application level |
251 handler. |
273 handler. |
252 """ |
274 """ |
253 |
275 |
254 def __init__(self, parttype): |
276 def __init__(self, parttype, data=''): |
255 self.type = parttype |
277 self.type = parttype |
|
278 self.data = data |
256 |
279 |
257 def getchunks(self): |
280 def getchunks(self): |
258 ### header |
281 ### header |
259 header = [_pack(_fparttypesize, len(self.type)), |
282 header = [_pack(_fparttypesize, len(self.type)), |
260 self.type, |
283 self.type, |