@@ 506-530 (lines=25) @@ | ||
503 | err) |
|
504 | raise exceptions.PackException(msg) |
|
505 | ||
506 | def unpack(self, buff, offset=0): |
|
507 | """Unpack a binary message into this object's attributes. |
|
508 | ||
509 | Unpack the binary value *buff* and update this object attributes based |
|
510 | on the results. |
|
511 | ||
512 | Args: |
|
513 | buff (bytes): Binary data package to be unpacked. |
|
514 | offset (int): Where to begin unpacking. |
|
515 | ||
516 | Raises: |
|
517 | Exception: If there is a struct unpacking error. |
|
518 | ||
519 | """ |
|
520 | def _int2hex(number): |
|
521 | return "{0:0{1}x}".format(number, 2) |
|
522 | ||
523 | try: |
|
524 | unpacked_data = struct.unpack('!6B', buff[offset:offset+6]) |
|
525 | except struct.error as exception: |
|
526 | raise exceptions.UnpackException('%s; %s: %s' % (exception, |
|
527 | offset, buff)) |
|
528 | ||
529 | transformed_data = ':'.join([_int2hex(x) for x in unpacked_data]) |
|
530 | self._value = transformed_data |
|
531 | ||
532 | def get_size(self, value=None): |
|
533 | """Return the address size in bytes. |
|
@@ 416-440 (lines=25) @@ | ||
413 | err) |
|
414 | raise exceptions.PackException(msg) |
|
415 | ||
416 | def unpack(self, buff, offset=0): |
|
417 | """Unpack a binary message into this object's attributes. |
|
418 | ||
419 | Unpack the binary value *buff* and update this object attributes based |
|
420 | on the results. |
|
421 | ||
422 | Args: |
|
423 | buff (bytes): Binary data package to be unpacked. |
|
424 | offset (int): Where to begin unpacking. |
|
425 | ||
426 | Raises: |
|
427 | Exception: If there is a struct unpacking error. |
|
428 | ||
429 | """ |
|
430 | def _int2hex(number): |
|
431 | return "{0:0{1}x}".format(number, 4) |
|
432 | ||
433 | try: |
|
434 | unpacked_data = struct.unpack('!8H', buff[offset:offset+16]) |
|
435 | except struct.error as exception: |
|
436 | raise exceptions.UnpackException('%s; %s: %s' % (exception, |
|
437 | offset, buff)) |
|
438 | ||
439 | transformed_data = ':'.join([_int2hex(x) for x in unpacked_data]) |
|
440 | self._value = transformed_data |
|
441 | ||
442 | def get_size(self, value=None): |
|
443 | """Return the IPv6 address size in bytes. |