Pack string field
        <field> ::= <int32_varint><data>

        :param value: string to be packed
        :type value: unicode

        :return: packed value
        :rtype: bytes
978353
def pack_unicode(cls, value, charset="utf-8", errors="strict"):
        
        assert isinstance(value, unicode)

        try:
            value = value.encode(charset, errors)
        except UnicodeEncodeError as e:
            raise InvalidData("Error encoding unicode value '%s': %s" % (repr(value), e))

        value_len_packed = cls.pack_int_base128(len(value))
        return struct.pack("<%ds%ds" % (len(value_len_packed), len(value)), value_len_packed,  value)
1383
def value_to_python(self, value):
        
        if not isinstance(value, bytes):
            raise tldap.exceptions.ValidationError("should be a bytes")

        try:
            value = int(value)
        except (TypeError, ValueError):
            raise tldap.exceptions.ValidationError("is invalid integer")

        try:
            value = datetime.date.fromtimestamp(value * 24 * 60 * 60)
        except OverflowError:
            raise tldap.exceptions.ValidationError("is too big a date")

        return value
977206
def encode_varint(v, f):
    
    assert v >= 0
    num_bytes = 0

    while True:
        b = v % 0x80
        v = v // 0x80

        if v > 0:
            b = b | 0x80

        f.write(FIELD_U8.pack(b))

        num_bytes += 1
        if v == 0:
            break

    return num_bytes
963495
def toString(value):
        
        if isinstance(value, basestring):
            return value
        elif type(value) in [np.string_, np.str_]:
            return str(value)
        elif type(value) == np.unicode_:
            return unicode(value)
        else:
            raise TypeError("Could not convert %s to string type" % type(value))
158979
def pack(self, value=None):
        
        # Set the correct IHL based on options size
        if self.options:
            self.ihl += int(len(self.options) / 4)

        # Set the correct packet length based on header length and data
        self.length = int(self.ihl * 4 + len(self.data))

        self._version_ihl = self.version << 4 | self.ihl
        self._dscp_ecn = self.dscp << 2 | self.ecn
        self._flags_offset = self.flags << 13 | self.offset

        # Set the checksum field before packing
        self._update_checksum()

        return super().pack()
33014
def _send_byte(self,value):
        

        # Coerce to int. This will throw a ValueError if the value can't
        # actually be converted.
        if type(value) != int:
            new_value = int(value)

            if self.give_warnings:
                w = "Coercing {} into int ({})".format(value,new_value)
                warnings.warn(w,Warning)
                value = new_value

        # Range check
        if value > 255 or value < 0:
            err = "Value {} exceeds the size of the board's byte.".format(value)
            raise OverflowError(err)

        return struct.pack("B",value)
383828
def to_python(self, value):
        
        if value == "":
            return None

        try:
            if isinstance(value, six.string_types):
                return self.deserializer(value)
            elif isinstance(value, bytes):
                return self.deserializer(value.decode('utf8'))
        except ValueError:
            pass
        return value
544184
def pack(self):
        ''''''
        for i in range(len(self.values)):
            if math.isnan(self.values[i]):
                self.values[i] = 0
        return struct.pack(self.pack_string, *self.values)
217597
def _cast_to_type(self, value):
        
        if isinstance(value, str) or value is None:
            return value
        return str(value)
45911
def write_var_str(self, value, encoding: str = 'utf-8'):
        
        if isinstance(value, str):
            value = value.encode(encoding)
        self.write_var_int(len(value))
        self.write_bytes(value)
407612
def encode(cls, value):
        
        val_encoding = 'utf-8'

        def encode_str(v):
            try:
                v_enc = encode(v, val_encoding)

            except UnicodeDecodeError:
                if PY3:
                    raise
                else:
                    # Suppose bytestring
                    v_enc = v

            prefix = encode('%s:' % len(v_enc), val_encoding)
            return prefix + v_enc

        def encode_(val):
            if isinstance(val, str_type):
                result = encode_str(val)

            elif isinstance(val, int_types):
                result = encode(('i%se' % val), val_encoding)

            elif isinstance(val, (list, set, tuple)):
                result = encode('l', val_encoding)
                for item in val:
                    result += encode_(item)
                result += encode('e', val_encoding)

            elif isinstance(val, dict):
                result = encode('d', val_encoding)

                # Dictionaries are expected to be sorted by key.
                for k, v in OrderedDict(sorted(val.items(), key=itemgetter(0))).items():
                    result += (encode_str(k) + encode_(v))

                result += encode('e', val_encoding)

            elif isinstance(val, byte_types):
                result = encode('%s:' % len(val), val_encoding)
                result += val

            else:
                raise BencodeEncodingError('Unable to encode `%s` %s' % (type(val), val))

            return result

        return encode_(value)
859092
function packValue(value) {
            const result = memoizedMap.get(value);
            if (result == null) {
                if (value >= MIN_DICT_INDEX && value <= MAX_VERBATIM_INTEGER && Number.isInteger(value))
                    return -value;
                
                memoize(value);
                
                if (typeof value === "number")
                    return String(value);
                if (/^[0-9\.]|^~/.test(value))
                    return `~${value}`;
                return value;
            }
            return result;
        }
256551
def write_byte(self, value):
        
        if isinstance(value, bytes):
            self.stream.write(value)
        elif isinstance(value, str):
            self.stream.write(value.encode('utf-8'))
        elif isinstance(value, int):
            self.stream.write(bytes([value]))
60023
def encode_field(self, field, value):
    
    # Override the handling of 64-bit integers, so they're always encoded
    # as strings.
    if (isinstance(field, messages.IntegerField) and
        field.variant in (messages.Variant.INT64,
                          messages.Variant.UINT64,
                          messages.Variant.SINT64)):
      if value not in (None, [], ()):
        # Convert and replace the value.
        if isinstance(value, list):
          value = [str(subvalue) for subvalue in value]
        else:
          value = str(value)
        return value

    return super(EndpointsProtoJson, self).encode_field(field, value)
217541
def encode(cls, value):
        
        coerced = unicode(value)
        if coerced == value:
            return coerced.encode(cls._encoding)

        raise InvalidValue('not text')
616135
def get_prep_value(self, value):
		
		if value is None or value == "":
			return None
		if isinstance(value, six.string_types):
			value = _hex_string_to_unsigned_integer(value)
		if _using_signed_storage():
			value = _unsigned_to_signed_integer(value)
		return value
1028090
def decode(value: str) -> Union[str, None, bool, int, float]:
    

    assert value.isdigit() or value[0] == '-' and value[1:].isdigit()

    if -I32_BOUND <= int(value) < I32_BOUND:  # it's an i32: it is its own encoding
        return int(value)
    elif int(value) == I32_BOUND:
        return None

    (prefix, value) = (int(value[0]), int(value[1:]))
    ival = int(value) - I32_BOUND
    if ival == 0:
        return ''  # special case: empty string encodes as 2**31
    elif ival == 1:
        return False  # sentinel for bool False
    elif ival == 2:
        return True  # sentinel for bool True

    blen = ceil(log(ival, 16)/2)
    ibytes = unhexlify(ival.to_bytes(blen, 'big'))
    return DECODE_PREFIX.get(prefix, str)(ibytes.decode())