Encode a mapping type.
170615
def _encode_mapping(name, value, check_keys, opts):
    """"""
    data = b"".join([_element_to_bson(key, val, check_keys, opts)
                     for key, val in iteritems(value)])
    return b"\x03" + name + _PACK_INT(len(data) + 5) + data + b"\x00"
41245
private byte[] encodeParameters(Map<String, String> params, String paramsEncoding) {
        StringBuilder encodedParams = new StringBuilder();
        try {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
                encodedParams.append('=');
                encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
                encodedParams.append('&');
            }
            return encodedParams.toString().getBytes(paramsEncoding);
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
        }
    }
607670
public <T extends Mapping> T getMapping(MappingType type)
    {
        return (T) mappings.get(type);
    }
371367
public static TypeCode toTypeCode(Class<?> type) {
		if (type == null)
			return TypeCode.Unknown;
		else if (type.isArray())
			return TypeCode.Array;
		else if (type.isEnum())
			return TypeCode.Enum;
		else if (type.isPrimitive()) {
			if (_booleanType.isAssignableFrom(type))
				return TypeCode.Boolean;
			if (_doubleType.isAssignableFrom(type))
				return TypeCode.Double;
			if (_floatType.isAssignableFrom(type))
				return TypeCode.Float;
			if (_longType.isAssignableFrom(type))
				return TypeCode.Long;
			if (_integerType.isAssignableFrom(type))
				return TypeCode.Integer;
		} else {
			if (_booleanType.isAssignableFrom(type))
				return TypeCode.Boolean;
			if (_doubleType.isAssignableFrom(type))
				return TypeCode.Double;
			if (_floatType.isAssignableFrom(type))
				return TypeCode.Float;
			if (_longType.isAssignableFrom(type))
				return TypeCode.Long;
			if (_integerType.isAssignableFrom(type))
				return TypeCode.Integer;
			if (_stringType.isAssignableFrom(type))
				return TypeCode.String;
			if (_dateTimeType.isAssignableFrom(type))
				return TypeCode.DateTime;
			if (_durationType.isAssignableFrom(type))
				return TypeCode.Duration;
			if (_mapType.isAssignableFrom(type))
				return TypeCode.Map;
			if (_listType.isAssignableFrom(type))
				return TypeCode.Array;
			if (_enumType.isAssignableFrom(type))
				return TypeCode.Enum;
		}

		return TypeCode.Object;
	}
857051
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.ssCode == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": ssCode required.");

        if (this.callBarringFeatureList == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": callBarringFeatureList required.");

        if (this.callBarringFeatureList.size() < 1 || this.callBarringFeatureList.size() > 32) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + ": Parameter callBarringFeatureList size must be from 1 to 32, found: "
                    + this.callBarringFeatureList.size());
        }

        try {

            ((SSCodeImpl) this.ssCode).encodeAll(asnOs);

            asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
            int pos = asnOs.StartContentDefiniteLength();
            for (ExtCallBarringFeature featureItem : this.callBarringFeatureList) {
                ((ExtCallBarringFeatureImpl) featureItem).encodeAll(asnOs);
            }
            asnOs.FinalizeContent(pos);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
171825
private void encodeThis() throws IOException {
        if (maps == null || maps.isEmpty()) {
            this.extensionValue = null;
            return;
        }
        DerOutputStream os = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream();

        for (CertificatePolicyMap map : maps) {
            map.encode(tmp);
        }

        os.write(DerValue.tag_Sequence, tmp);
        this.extensionValue = os.toByteArray();
    }
668292
def cql_encode_all_types(self, val, as_text_type=False):
        
        encoded = self.mapping.get(type(val), self.cql_encode_object)(val)
        if as_text_type and not isinstance(encoded, six.text_type):
            return encoded.decode('utf-8')
        return encoded
756000
def encode_raw(item):
    """"""
    if isinstance(item, Atomic):
        if len(item) == 1 and item[0] < 128:
            return item
        payload = item
        prefix_offset = 128  # string
    elif not isinstance(item, str) and isinstance(item, collections.Sequence):
        payload = b''.join(encode_raw(x) for x in item)
        prefix_offset = 192  # list
    else:
        msg = 'Cannot encode object of type {0}'.format(type(item).__name__)
        raise EncodingError(msg, item)

    try:
        prefix = length_prefix(len(payload), prefix_offset)
    except ValueError:
        raise EncodingError('Item too big to encode', item)

    return prefix + payload
1214086
def set_encode_key_value(self, value, store_type=PUBLIC_KEY_STORE_TYPE_BASE64):
        """"""
        if store_type == PUBLIC_KEY_STORE_TYPE_PEM:
            PublicKeyBase.set_encode_key_value(self, value.exportKey('PEM').decode(), store_type)
        else:
            PublicKeyBase.set_encode_key_value(self, value.exportKey('DER'), store_type)
1075669
def encode (self, s):
        """"""
        assert isinstance(s, unicode)
        return s.encode(self.output_encoding, self.codec_errors)
1296409
def mapped(cls, key='id', **kwargs):
    """"""
    kwargs.setdefault('metadata', {})
    kwargs['metadata']['jsonldPredicate'] = {'mapSubject': key}
    kwargs.setdefault('default', attr.Factory(list))

    def converter(value):
        """Convert mapping to a list of instances."""
        if isinstance(value, dict):
            result = []
            for k, v in iteritems(value):
                if not hasattr(cls, 'from_cwl'):
                    vv = dict(v)
                    vv[key] = k
                else:
                    vv = attr.evolve(cls.from_cwl(v), **{key: k})
                result.append(vv)
        else:
            result = value

        def fix_keys(data):
            """Fix names of keys."""
            for a in fields(cls):
                a_name = a.name.rstrip('_')
                if a_name in data:
                    yield a.name, data[a_name]

        return [
            cls(**{kk: vv
                   for kk, vv in fix_keys(v)}) if not isinstance(v, cls) else v
            for v in result
        ]

    kwargs['converter'] = converter
    return attr.ib(**kwargs)
1192106
private EsRequest fieldMapping( PropertyType type ) {
        EsRequest mappings = new EsRequest();
        switch (type) {
            case BINARY:
                mappings.put("type", "binary");
                break;
            case BOOLEAN:
                mappings.put("type", "boolean");
                break;
            case DATE:
                mappings.put("type", "long");
                break;
            case LONG:
            case DECIMAL:
                mappings.put("type", "long");
                break;
            case DOUBLE:
                mappings.put("type", "double");
                break;
            default:
                mappings.put("type", "string");
                mappings.put("analyzer", "whitespace");
        }
        return mappings;
    }
648451
def encode_abi(types, args)
      parsed_types = types.map {|t| Type.parse(t) }

      head_size = (0...args.size)
        .map {|i| parsed_types[i].size || 32 }
        .reduce(0, &:+)

      head, tail = '', ''
      args.each_with_index do |arg, i|
        if parsed_types[i].dynamic?
          head += encode_type(Type.size_type, head_size + tail.size)
          tail += encode_type(parsed_types[i], arg)
        else
          head += encode_type(parsed_types[i], arg)
        end
      end

      "#{head}#{tail}"
    end
1273727
@SuppressWarnings({"unchecked", "rawtypes"})
    public U encode(Object value) {
        requireNonNull(value, "Value for encoding can not be null");

        TypeEncoder encoder = classMapping.get(value.getClass());
        if (encoder != null)
            return (U) encoder.encode(value);

        throw new TypeEncodingException("An unknown type [" + value.getClass() + "] was encountered");
    }
1050679
private String encodeKeysGet(String keys) {
        try {
            return URLEncoder.encode(keys, "UTF-8");
        } catch(Exception ex) {
            throw new RuntimeException("Could not prepare view argument: " + ex);
        }
    }
708310
static void encode(Environment environment, LocalFunctionRegistry registry, Class returnType, Object result, OutputStream output) throws IOException {
        if (ClassUtils.isJavaLangType(returnType)) {
            if (result instanceof Byte) {
                output.write((Byte) result);
            } else if (result instanceof Boolean) {
                output.write(((Boolean) result) ? 1 : 0);
            } else if (result instanceof byte[]) {
                output.write((byte[]) result);
            } else {
                byte[] bytes = environment
                    .convert(result.toString(), byte[].class)
                    .orElseThrow(() -> new InvocationException("Unable to convert result [" + result + "] for output stream"));
                output.write(bytes);
            }
        }
766625
def p_map_type(self, p):
        ''''''
        p[0] = ast.MapType(key_type=p[3], value_type=p[5], annotations=p[7])