encode(value1[, ...]) -> bytes

        Encodes the given values to a sequence of bytes according to this
        Array's underlying element type
512152
def encode(self, *args):
        
        if len(args) != self.nelems:
            msg = 'ArrayType %s encode() requires %d values, but received %d.'
            raise ValueError(msg % (self.name, self.nelems, len(args)))

        return bytearray().join(self.type.encode(arg) for arg in args)
1195536
def encode(self, value):
        
        if self.decode_responses and isinstance(value, bytes):
            value = value.decode(self.encoding)
        elif not self.decode_responses and isinstance(value, str):
            value = value.encode(self.encoding)
        return value
1000362
def encode (self):
    """"""
    byte = self.default

    for bit, name, value0, value1, default in SeqCmdAttrs.Table:
      if name in self.attrs:
        value = self.attrs[name]
        byte  = setBit(byte, bit, value == value1)

    return struct.pack('B', byte)
198034
private void encodeThis() throws IOException {
        if (require == -1 && inhibit == -1) {
            this.extensionValue = null;
            return;
        }
        DerOutputStream tagged = new DerOutputStream();
        DerOutputStream seq = new DerOutputStream();

        if (require != -1) {
            DerOutputStream tmp = new DerOutputStream();
            tmp.putInteger(require);
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                         false, TAG_REQUIRE), tmp);
        }
        if (inhibit != -1) {
            DerOutputStream tmp = new DerOutputStream();
            tmp.putInteger(inhibit);
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                         false, TAG_INHIBIT), tmp);
        }
        seq.write(DerValue.tag_Sequence, tagged);
        this.extensionValue = seq.toByteArray();
    }
413779
function encode(position_array){

  if(!_.isArray(position_array) || position_array.length<=0){
    throw new Error('Array of tree positions required');
  } 
  
  var left_position_array = _.map(position_array, function(v){return v;});
  var right_position_array = _.map(position_array, function(v){return v;});

  // lets modify the last position in the right hand sequence so it is one more than the left
  var last_position = right_position_array.pop();
  
  last_position++;

  right_position_array.push(last_position);

  return {
    left:calculate_encoding_from_tree_position(left_position_array),
    right:calculate_encoding_from_tree_position(right_position_array)
  }
}
884136
function encode(key, value, stringify) {
  var space = ' ', val = [], i, type = this.type;

  function coerce(type, val) {
    var out
      , enumerable = Array.isArray(type);
    if(enumerable) {
      if(!~type.indexOf(val)) {
        throw new TypeDefError(
          util.format('enum error on key \'%s\', got \'%s\' expected one of %s',
            key, val, type.join(', ')));
      }

      return '' + val;
    }
    switch(type) {
      case ByteSize:
        if(typeof val !== 'number') {
          throw new TypeDefError(
            util.format(
              'byte size number expected for \'%s\', got %s', key, val));
        }
        out = ByteSize.humanize(val);
        break;
      case Boolean:
        if(typeof val !== 'boolean') {
          throw new TypeDefError(
            util.format('boolean expected for \'%s\', got %s', key, val));
        }
        out = val === true ? YES : NO;
        break;
      case String:
        // strings must be quoted to allow the empty string
        out = '"' + val + '"';
        break;
      case Number:
        if(typeof val !== 'number') {
          throw new TypeDefError(
            util.format('number expected for \'%s\', got %s', key, val));
        }
        // just coerce numbers to strings
        out = '' + val;
        break;
    }
    return out;
  }

  // simple types
  if(!Array.isArray(this.type)) {
    return (!stringify ? key + space : '') + coerce(this.type, value);
  }

  if(stringify && this.repeats) {
    value.forEach(function(item) {
      item.forEach(function(entry, i) {
        val.push(coerce(type[i], entry));
      })
    });
    return val.join(space);
  }

  for(i = 0;i < this.type.length;i++) {
    if(this.arity > 1) {
      // expecting value to be an array
      val.push(coerce(this.type[i], value[i]));
    }else{
      val.push(coerce(this.type[i], value));
    }
  }

  return key + space + val.join(space);
}
751290
public static void encode(int value, byte[] dst, int dstOffset) {
        value ^= 0x80000000;
        dst[dstOffset    ] = (byte)(value >> 24);
        dst[dstOffset + 1] = (byte)(value >> 16);
        dst[dstOffset + 2] = (byte)(value >> 8);
        dst[dstOffset + 3] = (byte)value;
    }
417439
def _encode(self, value):
        ""
        if isinstance(value, bytes):
            return value
        elif isinstance(value, (int, long)):
            value = str(value).encode('utf-8')
        elif isinstance(value, float):
            value = repr(value).encode('utf-8')
        elif not isinstance(value, basestring):
            value = str(value).encode('utf-8')
        else:
            value = value.encode('utf-8', 'strict')
        return value
502446
function encodeArray( encoder, data ) {
	encoder.log(LOG.PRM, "array, len="+data.length+", peek="+data[0]);
	
	// Check for empty array
	if (data.length === 0) {
		encodeArray_EMPTY( encoder );
		return;
	}

	// Get typed array typed
	var tt = getTypedArrayType(data);

	// Check for numerical array
	if ( tt <= NUMTYPE.NUMERIC ) {
		encodeArray_Numeric( encoder, data, tt );
	} else {
		encodeArray_Primitive( encoder, data );
	}

}
1193854
public static String encode(byte[] bytes) {
	String retorno = "";
	if (bytes == null || bytes.length == 0) {
	    return retorno;
	}
	for (int i = 0; i < bytes.length; i++) {
	    byte valor = bytes[i];
	    int d1 = valor & 0xF;
	    d1 += (d1 < 10) ? 48 : 55;
	    int d2 = (valor & 0xF0) >> 4;
	    d2 += (d2 < 10) ? 48 : 55;
	    retorno = retorno + (char) d2 + (char) d1;
	}
	return retorno;
    }
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
410
private void encodeObject(StringBuffer result, Object value) {
    if (value != null) {
      if (value instanceof byte[]) {
        result.append("[]");
        HexString.binToHex((byte[])value, 0, ((byte[])value).length, result);
      } else
        URLEncode(result, value.toString());
    }
482236
private static byte[] intToByteArray(int value)
    {
        byte[] data = new byte[4];

        // int -> byte[]
        for (int i = 0; i < 4; ++i)
        {
            int shift = i << 3; // i * 8
            data[3 - i] = (byte) ((value & (0xff << shift)) >>> shift);
        }
        return data;
    }
64186
def encode_ber(value, ber_length=0):
    
    if not ber_length:
        if value < 127: # 1 byte case
            return bytearray([value])
        ber_length = 1
        while value >= pow(2, 8*ber_length):
            ber_length += 1
        ber_length += 1


    ber = bytearray(ber_length)
    ber[0] = 127 + ber_length #ber length byte
    for i in range(1, ber_length):
        ber[i] = (value >> (8 * (ber_length - 1 - i))) & 255
    return ber
297507
function encodeArray_Primitive( encoder, data ) {

	// Analyze primitive array and return clusters of values
	// that can be efficiently merged (such as numbers, repeated values,
	// primitives etc.)
	var chunks = analyzePrimitiveArray( encoder, data );
	if (chunks.length === 1) {

		// Just check
		if (chunks[0][1] !== data.length) {
			throw new Errors.AssertError('Primitive array analysis reported single chunk but does not match array length!');
		}

		// Just encode a single chunk as array component
		encodeArray_Chunk( encoder, data, chunks[0] );

	} else {

		// We have more than one chunk, start encoding chunked array
		encodeArray_PRIM_CHUNK( encoder, data, chunks );

	}

}
671907
function encodeSingle (type, arg) {
  var size, num, ret, i

  if (type === 'address') {
    return encodeSingle('uint160', parseNumber(arg))
  } else if (type === 'bool') {
    return encodeSingle('uint8', arg ? 1 : 0)
  } else if (type === 'string') {
    return encodeSingle('bytes', Buffer.from(arg, 'utf8'))
  } else if (isArray(type)) {
    // this part handles fixed-length ([2]) and variable length ([]) arrays
    // NOTE: we catch here all calls to arrays, that simplifies the rest
    if (typeof arg.length === 'undefined') {
      throw new Error('Not an array?')
    }
    size = parseTypeArray(type)
    if (size !== 'dynamic' && size !== 0 && arg.length > size) {
      throw new Error('Elements exceed array size: ' + size)
    }
    ret = []
    type = type.slice(0, type.lastIndexOf('['))
    if (typeof arg === 'string') {
      arg = JSON.parse(arg)
    }
    for (i in arg) {
      ret.push(encodeSingle(type, arg[i]))
    }
    if (size === 'dynamic') {
      var length = encodeSingle('uint256', arg.length)
      ret.unshift(length)
    }
    return Buffer.concat(ret)
  } else if (type === 'bytes') {
    arg = Buffer.from(arg)

    ret = Buffer.concat([ encodeSingle('uint256', arg.length), arg ])

    if ((arg.length % 32) !== 0) {
      ret = Buffer.concat([ ret, utils.zeros(32 - (arg.length % 32)) ])
    }

    return ret
  } else if (type.startsWith('bytes')) {
    size = parseTypeN(type)
    if (size < 1 || size > 32) {
      throw new Error('Invalid bytes<N> width: ' + size)
    }

    return utils.setLengthRight(arg, 32)
  } else if (type.startsWith('uint')) {
    size = parseTypeN(type)
    if ((size % 8) || (size < 8) || (size > 256)) {
      throw new Error('Invalid uint<N> width: ' + size)
    }

    num = parseNumber(arg)
    if (num.bitLength() > size) {
      throw new Error('Supplied uint exceeds width: ' + size + ' vs ' + num.bitLength())
    }

    if (num < 0) {
      throw new Error('Supplied uint is negative')
    }

    return num.toArrayLike(Buffer, 'be', 32)
  } else if (type.startsWith('int')) {
    size = parseTypeN(type)
    if ((size % 8) || (size < 8) || (size > 256)) {
      throw new Error('Invalid int<N> width: ' + size)
    }

    num = parseNumber(arg)
    if (num.bitLength() > size) {
      throw new Error('Supplied int exceeds width: ' + size + ' vs ' + num.bitLength())
    }

    return num.toTwos(256).toArrayLike(Buffer, 'be', 32)
  } else if (type.startsWith('ufixed')) {
    size = parseTypeNxM(type)

    num = parseNumber(arg)

    if (num < 0) {
      throw new Error('Supplied ufixed is negative')
    }

    return encodeSingle('uint256', num.mul(new BN(2).pow(new BN(size[1]))))
  } else if (type.startsWith('fixed')) {
    size = parseTypeNxM(type)

    return encodeSingle('int256', parseNumber(arg).mul(new BN(2).pow(new BN(size[1]))))
  }

  throw new Error('Unsupported or invalid type: ' + type)
}
579400
public void encodeType(byte[] frame, int[] limits) {
    setByte(frame, limits, (byte)ARRAY);
    itemType.encodeType(frame, limits);
  }