# Path: pnet/utils.py
# class HWAddress(object):
#     """Represent and manipulate MAC addresses."""
#     def __init__(self, address):
#         """
#         Args:
#             address: A string or integer representing the MAC
#         """
# 
#         if isinstance(address, bytes) and len(address) == 6:
#             self.packed = address
#         elif isinstance(address, HWAddress):
#             self.packed = address.packed
#         else:
#             self.packed = unhexlify(address.replace(':', ''))
#             assert len(self.packed) == 6
# 
#     def __str__(self):
#         return ':'.join([format(ord(x), 'x') for x in self.packed])
# 
#     def __repr__(self):
#         return "HWAddress('{}')".format(self)


import struct
from ipaddress import IPv4Address
from .utils import HWAddress


class ParseError(RuntimeError):
    """Failed to unpack structure."""


TYPES = {
    'uint8': 'B',
    'uint16': 'H',
    'be16': '>H',
    'ip4addr': {
        'format': '4s',
        'decode': IPv4Address,
        'encode': lambda addr: addr.packed
    },
    'l2addr': {
        'format': '6s',

# Path: pnet/utils.py
# class HWAddress(object):
#     """Represent and manipulate MAC addresses."""
#     def __init__(self, address):
#         """
#         Args:
#             address: A string or integer representing the MAC
#         """
# 
#         if isinstance(address, bytes) and len(address) == 6:
#             self.packed = address
#         elif isinstance(address, HWAddress):
#             self.packed = address.packed
#         else:
#             self.packed = unhexlify(address.replace(':', ''))
#             assert len(self.packed) == 6
# 
#     def __str__(self):
#         return ':'.join([format(ord(x), 'x') for x in self.packed])
# 
#     def __repr__(self):
#         return "HWAddress('{}')".format(self)


# Path: pnet/msg.py
import struct
from ipaddress import IPv4Address
from .utils import HWAddress



class ParseError(RuntimeError):
    """Failed to unpack structure."""


TYPES = {
    'uint8': 'B',
    'uint16': 'H',
    'be16': '>H',
    'ip4addr': {
        'format': '4s',
        'decode': IPv4Address,
        'encode': lambda addr: addr.packed
    },
    'l2addr': {
        'format': '6s',

        'decode': HWAddress,