Decode the given ``datavalue`` using the configured
        :attr:`datavalue_decoder`.

        .. versionadded:: 0.3.0
508165
def decode_datavalue(self,
                         datatype: str,
                         datavalue: Mapping[str, object]) -> object:
        
        decode = cast(Callable[[Client, str, Mapping[str, object]], object],
                      self.datavalue_decoder)
        return decode(self, datatype, datavalue)
293705
def decode(self, bytes):
        
        value = self.type.decode(bytes)
        if self._enum is not None:
            for name, val in self._enum.items():
                if value == val:
                    value = name
                    break
        return value
460844
def _decode(self, value):
        
        if isinstance(value, list):
            return [self._decode(v) for v in value]
        elif isinstance(value, dict):
            return {self._decode(k): self._decode(v)
                    for k, v in value.items()}
        elif isinstance(value, bytes):
            return value.decode('utf-8')
        return value
801398
def try_utf8_decode(value):
    
    if not value or not is_string(value):
        return value
    elif PYTHON3 and not isinstance(value, bytes):
        return value
    elif not PYTHON3 and not isinstance(value, unicode):
        return value

    try:
        return value.decode('utf-8')
    except UnicodeDecodeError:
        pass

    return value
123765
def decode(data_url):
    
    metadata, data = data_url.rsplit(',', 1)
    _, metadata = metadata.split('data:', 1)
    parts = metadata.split(';')
    if parts[-1] == 'base64':
        data = b64decode(data)
    else:
        data = unquote(data)

    for part in parts:
        if part.startswith("charset="):
            data = data.decode(part[8:])
    return data
739016
def data(self, value):
        
        if value is not None and not isinstance(value, unicode):
            value = value.decode('utf-8')
        self._data = value
833031
def _FloatDecoder():
  

  local_unpack = struct.unpack

  def InnerDecode(buffer, pos):
    # We expect a 32-bit value in little-endian byte order.  Bit 1 is the sign
    # bit, bits 2-9 represent the exponent, and bits 10-32 are the significand.
    new_pos = pos + 4
    float_bytes = buffer[pos:new_pos]

    # If this value has all its exponent bits set, then it's non-finite.
    # In Python 2.4, struct.unpack will convert it to a finite 64-bit value.
    # To avoid that, we parse it specially.
    if (float_bytes[3:4] in b'\x7F\xFF' and float_bytes[2:3] >= b'\x80'):
      # If at least one significand bit is set...
      if float_bytes[0:3] != b'\x00\x00\x80':
        return (_NAN, new_pos)
      # If sign bit is set...
      if float_bytes[3:4] == b'\xFF':
        return (_NEG_INF, new_pos)
      return (_POS_INF, new_pos)

    # Note that we expect someone up-stack to catch struct.error and convert
    # it to _DecodeError -- this way we don't have to set up exception-
    # handling blocks every time we parse one value.
    result = local_unpack('<f', float_bytes)[0]
    return (result, new_pos)
  return _SimpleDecoder(wire_format.WIRETYPE_FIXED32, InnerDecode)
897660
def decode_field(self, field, value):
    
    # Override BytesField handling.  Client libraries typically use a url-safe
    # encoding.  b64decode doesn't handle these gracefully.  urlsafe_b64decode
    # handles both cases safely.  Also add padding if the padding is incorrect.
    if isinstance(field, messages.BytesField):
      try:
        # Need to call str(value) because ProtoRPC likes to pass values
        # as unicode, and urlsafe_b64decode can only handle bytes.
        padded_value = self.__pad_value(str(value), 4, '=')
        return base64.urlsafe_b64decode(padded_value)
      except (TypeError, UnicodeEncodeError), err:
        raise messages.DecodeError('Base64 decoding error: %s' % err)

    return super(EndpointsProtoJson, self).decode_field(field, value)
775544
def decode_struct_tree(self, data_type, obj):
        
        subtype = self.determine_struct_tree_subtype(data_type, obj)
        return self.decode_struct(subtype, obj)
502538
def __decode_ext_desc(self, value_type, value):
        
        if value_type == 0:  # Unicode string
            return self.__decode_string(value)
        elif value_type == 1:  # BYTE array
            return value
        elif 1 < value_type < 6:  # DWORD / QWORD / WORD
            return _bytes_to_int_le(value)
58280
def decode_data(self, data):
        
        assert self.get_empty() is False
        assert self._data_encoded is True
        if self._block_allowed:
            data = self._decode_transfer_block_data(data)
        else:
            data = self._decode_transfer_data(data)
        return data
203348
def parse_value(proto):
    
    if proto.HasField('floatValue'):
        return proto.floatValue
    elif proto.HasField('doubleValue'):
        return proto.doubleValue
    elif proto.HasField('sint32Value'):
        return proto.sint32Value
    elif proto.HasField('uint32Value'):
        return proto.uint32Value
    elif proto.HasField('binaryValue'):
        return proto.binaryValue
    elif proto.HasField('timestampValue'):
        # Don't use the actual 'timestampValue' field, it contains a number
        # that is difficult to interpret on the client. Instead parse from
        # the ISO String also set by Yamcs.
        return parse_isostring(proto.stringValue)
    elif proto.HasField('stringValue'):
        return proto.stringValue
    elif proto.HasField('uint64Value'):
        return proto.uint64Value
    elif proto.HasField('sint64Value'):
        return proto.sint64Value
    elif proto.HasField('booleanValue'):
        return proto.booleanValue
    elif proto.HasField('arrayValue'):
        return [parse_value(v) for v in proto.arrayValue]
    elif proto.HasField('aggregateValue'):
        return OrderedDict(zip(proto.aggregateValue.name, proto.aggregateValue.value))
    else:
        logging.warn('Unrecognized value type for update %s', proto)
        return None
599491
def _decode_surrogatepass(data, codec):
    

    try:
        return data.decode(codec, _surrogatepass)
    except UnicodeDecodeError:
        if not _codec_can_decode_with_surrogatepass(codec):
            if _normalize_codec(codec) == "utf-16-be":
                data = _swap_bytes(data)
                codec = "utf-16-le"
            if _normalize_codec(codec) == "utf-16-le":
                buffer_ = ctypes.create_string_buffer(data + b"\x00\x00")
                value = ctypes.wstring_at(buffer_, len(data) // 2)
                if value.encode("utf-16-le", _surrogatepass) != data:
                    raise
                return value
            else:
                raise
        else:
            raise
255390
def decode_safely(self, encoded_data):
        

        decoder = self.base_decoder
        result = settings.null

        try:
            result = pickle.loads(decoder(encoded_data))
        except:
            warnings.warn("Could not load and deserialize the data.", RuntimeWarning)
        return result
794870
def _decode(value):
        
        if value.isdigit():
            return int(value)
        if isinstance(value, bytes):
            return value.decode('utf-8')
        else:
            return value
1028141
def decode_union(self, data_type, obj):
        
        val = None
        if isinstance(obj, six.string_types):
            # Handles the shorthand format where the union is serialized as only
            # the string of the tag.
            tag = obj
            if data_type.definition._is_tag_present(tag, self.caller_permissions):
                val_data_type = data_type.definition._get_val_data_type(
                    tag, self.caller_permissions)
                if not isinstance(val_data_type, (bv.Void, bv.Nullable)):
                    raise bv.ValidationError(
                        "expected object for '%s', got symbol" % tag)
                if tag == data_type.definition._catch_all:
                    raise bv.ValidationError(
                        "unexpected use of the catch-all tag '%s'" % tag)
            elif not self.strict and data_type.definition._catch_all:
                tag = data_type.definition._catch_all
            else:
                raise bv.ValidationError("unknown tag '%s'" % tag)
        elif isinstance(obj, dict):
            tag, val = self.decode_union_dict(
                data_type, obj)
        else:
            raise bv.ValidationError("expected string or object, got %s" %
                                     bv.generic_type_name(obj))
        return data_type.definition(tag, val)
600120
def _decode(self, obj, context):
        
        cls = self._get_class(obj.classID)
        return cls.from_construct(obj, context)