encode text payload @returns an array of bytes
486279
function encode(text, lang, encoding) {

    // ISO/IANA language code, but we're not enforcing
    if (!lang) { lang = 'en'; }

    var encoded = util.stringToBytes(lang + text);
    encoded.unshift(lang.length);

    return encoded;
}
291735
public byte[] encode() throws IOException {
        final ByteBuffer buf = ByteBuffer.allocate(totalSize());
        log.debug("Tag: " + this);
        buf.put(id.encode());
        buf.put(size.encode());
        putValue(buf);
        buf.flip();
        return buf.array();
    }
1051733
public byte[] encode(String s) throws IOException {
    if (s == null) {
      return null;
    }

    return s.getBytes(encoding);
  }
407987
public static byte[] encode(byte[] data)
	{
		int sourceChunks = data.length / 3;
		int len = (data.length + 2) / 3 * 4;
		byte[] result = new byte[len];
		int extraBytes = data.length - sourceChunks * 3;
		// Each 4 bytes of input (encoded) we end up with 3 bytes of output
		int dataIndex = 0;
		int resultIndex = 0;
		int allBits = 0;
		for (int i = 0; i < sourceChunks; i++)
		{
			allBits = 0;
			// Loop 3 times gathering input bits (3 * 8 = 24)
			for (int j = 0; j < 3; j++)
			{
				allBits = allBits << 8 | data[dataIndex++] & 0xff;
			}
			// Loop 4 times generating output bits (4 * 6 = 24)
			for (int j = resultIndex + 3; j >= resultIndex; j--)
			{
				result[j] = (byte) digits[allBits & 0x3f]; // Bottom
				// 6
				// bits
				allBits = allBits >>> 6;
			}
			resultIndex += 4; // processed 4 result bytes
		}
		// Now we do the extra bytes in case the original (non-encoded) data
		// is not multiple of 4 bytes
		switch (extraBytes)
		{
			case 1:
				allBits = data[dataIndex++]; // actual byte
				allBits = allBits << 8; // 8 bits of zeroes
				allBits = allBits << 8; // 8 bits of zeroes
				// Loop 4 times generating output bits (4 * 6 = 24)
				for (int j = resultIndex + 3; j >= resultIndex; j--)
				{
					result[j] = (byte) digits[allBits & 0x3f]; // Bottom
					// 6
					// bits
					allBits = allBits >>> 6;
				}
				// 2 pad tags
				result[result.length - 1] = equalSign;
				result[result.length - 2] = equalSign;
				break;
			case 2:
				allBits = data[dataIndex++]; // actual byte
				allBits = allBits << 8 | data[dataIndex++] & 0xff; // actual
				// byte
				allBits = allBits << 8; // 8 bits of zeroes
				// Loop 4 times generating output bits (4 * 6 = 24)
				for (int j = resultIndex + 3; j >= resultIndex; j--)
				{
					result[j] = (byte) digits[allBits & 0x3f]; // Bottom
					// 6
					// bits
					allBits = allBits >>> 6;
				}
				// 1 pad tag
				result[result.length - 1] = equalSign;
				break;
		}
		return result;
	}
1346238
@Deprecated
    public static byte[] encodeToBytes(byte[] bytes)
    {
        try {
            char[] chars = Base64.encode(bytes);
            String string = new String(chars);
            return string.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
791616
String encodeBinary(byte[] data){
        if (data == null) return null;
        return Base64.encodeToString(data,Base64.URL_SAFE|Base64.NO_WRAP);
    }
158103
public function encode()
    {
        $reserved = [
            '!%21!ui' => "!",
            '!%23!ui' => "#",
            '!%24!ui' => "$",
            '!%26!ui' => "&",
            '!%27!ui' => "'",
            '!%28!ui' => "(",
            '!%29!ui' => ")",
            '!%2A!ui' => "*",
            '!%2B!ui' => "+",
            '!%2C!ui' => ",",
            '!%2F!ui' => "/",
            '!%3A!ui' => ":",
            '!%3B!ui' => ";",
            '!%3D!ui' => "=",
            '!%3F!ui' => "?",
            '!%40!ui' => "@",
            '!%5B!ui' => "[",
            '!%5D!ui' => "]",
            '!%25!ui' => "%",
        ];
        // The % character must be the last in the $reserved array.
        // This makes sure that the already encoded values are not lost or encoded again.
        $this->uri = preg_replace(array_keys($reserved), array_values($reserved), rawurlencode($this->uri));
        return $this->baseToLowercase();
    }
728773
@Override
    public String encode( String text ) {
        try {
            byte[] hash = SecureHash.getHash(algorithm, text.getBytes());
            String result = Base64.encodeBytes(hash);
            return result.length() < maxLength ? result : result.substring(0, maxLength);
        } catch (NoSuchAlgorithmException e) {
            return text;
        }
    }
551037
@Override
	public String encodeAsString() throws IOException {
		ByteArray byteArray = encodeAsByteArray();
		if(byteArray.size == 0) return "";
		return new String(Base64Coder.encode(byteArray.array, byteArray.size));
	}
1097057
@Override
   public String encode() {
       ReadableByteArrayOutputStream out = new ReadableByteArrayOutputStream();
       encode(out);
       return out.toString();
   }
142347
private String encodeBytes(byte[] cipherText) {
        StringBuffer cipherStringBuffer = new StringBuffer();
        for (int i = 0; i < cipherText.length; i++) {
            byte b = cipherText[i];
            cipherStringBuffer.append(Byte.toString(b) + ":");
        }
        return cipherStringBuffer.toString();
    }
673474
@Benchmark
  @BenchmarkMode(Mode.AverageTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public byte[] encodeSpanBinary(Data data) {
    return data.propagation.getBinaryFormat().toByteArray(data.spanToEncode.getContext());
  }
735312
def encode(self):
        """"""

        reading = self.visible_readings[0]
        data = struct.pack("<BBHLLLL", 0, 0, reading.stream, self.origin,
                           self.sent_timestamp, reading.raw_time, reading.value)

        return bytearray(data)
1273895
function encodeWrap(nodeText) {
        if (!nodeText) {
            return '';
        }
        var textArr = [],
            WRAP_TEXT = ['\\', 'n'];
        for (var i = 0, j = 0, l = nodeText.length; i < l; i++) {
            if (nodeText[i] === '\n' || nodeText[i] === '\r') {
                textArr.push('\\n');
                j = 0;
                continue;
            }
            if (nodeText[i] === WRAP_TEXT[j]) {
                j++;
                if (j === 2) {
                    j = 0;
                    textArr.push('\\\\n');
                }
                continue;
            }
            switch (j) {
                case 0: {
                    textArr.push(nodeText[i]);
                    break;
                }
                case 1: {
                    textArr.push(nodeText[i-1], nodeText[i]);
                }
            }
            j = 0;
        }
        return textArr.join('');
    }
1183414
function __encode_utf8(text) {

        // Fill buffer with UTF-8
        for (var i=0; i<text.length; i++) {
            var codepoint = text.charCodeAt(i);
            __append_utf8(codepoint);
        }

        // Flush buffer
        if (length > 0) {
            var out_buffer = buffer.subarray(0, length);
            length = 0;
            return out_buffer;
        }

    }
577578
function stringToByteArray(str) {
	const byteArray = [];
	for (let i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) <= 0x7F) {
			byteArray.push(str.charCodeAt(i));
		} else {
			const h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
			for (let j = 0; j < h.length; j++) {
				byteArray.push(parseInt(h[j], 16));
			}
		}
	}

	return byteArray;
}
380254
public static ByteBuffer encode(String text, Charset charset) {
		return encode(text.getBytes(charset));
	}