def buffer_to_value(self, obj, buffer, offset, default_endianness=DEFAULT_ENDIANNESS):
        if isinstance(self.length, Field):
            length = getattr(obj, self.length._name)
        else:
            length = len(buffer) - offset
        k = getattr(obj, self.determinant._name)
        try:
            return self.contents[k].parse(buffer[offset:offset+length], default_endianness=default_endianness)
        except __HOLE__:
            if not self.accept_missing:
                raise PacketDecodeError("{}: unrecognised value for union: {}".format(self.type, k))
            else:
                return None, length
dataset/ETHPy150Open pebble/libpebble2/libpebble2/protocol/base/types.py/Union.buffer_to_value