only works for 8-bit chars
550015
function toByteArray(obj) {
  var uint = new Uint8Array(obj.length);
  for (var i = 0, l = obj.length; i < l; i++){
    uint[i] = obj.charCodeAt(i);
  }

  return new Uint8Array(uint);
}
619811
function readUInt64BE(buffer, start) {
  var data = buffer.slice(start, start + 8);
  return data.readUInt32BE(4, 8);
}
524840
def write_uint8(self, value, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%sB' % endian, value)
946377
function _atob (s) {
   if (s) {
      return new Uint8Array(atob(s).split("").map(function(c) { return c.charCodeAt(0); }));
   } else {
      return null;
   }
}
1369158
public static char eatUtf8(String a, int[] n) {
    if (a.length() == 0) {
      n[0] = 0;
      return ((char) 0);
    }
    n[0] = Utf8Length(a.charAt(0));
    if (a.length() >= n[0]) {
      switch (n[0]) {
        case 1:
          return (a.charAt(0));
        case 2:
          if ((a.charAt(1) & 0xC0) != 0x80) break;
          return ((char) (((a.charAt(0) & 0x1F) << 6) + (a.charAt(1) & 0x3F)));
        case 3:
          if ((a.charAt(1) & 0xC0) != 0x80 || (a.charAt(2) & 0xC0) != 0x80) break;
          return ((char) (((a.charAt(0) & 0x0F) << 12) + ((a.charAt(1) & 0x3F) << 6) + ((a.charAt(2) & 0x3F))));
        case 4:
          if ((a.charAt(1) & 0xC0) != 0x80 || (a.charAt(2) & 0xC0) != 0x80 || (a.charAt(3) & 0xC0) != 0x80) break;
          return ((char) (((a.charAt(0) & 0x07) << 18) + ((a.charAt(1) & 0x3F) << 12) + ((a.charAt(2) & 0x3F) << 6) + ((a.charAt(3) & 0x3F))));
      }
    }
    n[0] = -1;
    return ((char) 0);
  }
1294427
function _Char_toCode(char)
{
	var code = char.charCodeAt(0);
	if (0xD800 <= code && code <= 0xDBFF)
	{
		return (code - 0xD800) * 0x400 + char.charCodeAt(1) - 0xDC00 + 0x10000
	}
	return code;
}
992750
private static boolean isUTF8Value(Class<?> clazz)
    {
        return (clazz.isAssignableFrom(BigDecimal.class))
                || (clazz.isAssignableFrom(BigInteger.class) || (clazz.isAssignableFrom(String.class))
                        || (clazz.isAssignableFrom(char.class)) || (clazz.isAssignableFrom(Character.class)));
    }
947655
private static char[] chars(byte[] bytes) {
        char[] chars = new char[bytes.length];
        for (int i = 0; i < bytes.length; i++) {
            int pos = bytes[i] & 0xff;
            chars[i] = (char) pos;
        }
        return chars;
    }
272990
def utf8_char_length_in_bytes(first_byte)
      if first_byte.hex < 'C0'.hex
        1
      elsif first_byte.hex < 'DF'.hex
        2
      elsif first_byte.hex < 'EF'.hex
        3
      else
        4
      end
    end
1126303
public static byte[] toBigEndianUtf16Bytes(char[] chars, int offset, int length) {
        byte[] result = new byte[length * 2];
        int end = offset + length;
        int resultIndex = 0;
        for (int i = offset; i < end; ++i) {
            char ch = chars[i];
            result[resultIndex++] = (byte) (ch >> 8);
            result[resultIndex++] = (byte) ch;
        }
        return result;
    }
314115
public void write(ByteAppendable os, char ch)
    throws IOException
  {
    if (ch < 0x80)
      os.write(ch);
    else {
      os.write('\\');
      os.write('u');

      int b = (ch >> 12) & 0xf;
      os.write(b < 10 ? b + '0' : b + 'a' - 10);
      b = (ch >> 8) & 0xf;
      os.write(b < 10 ? b + '0' : b + 'a' - 10);
      b = (ch >> 4) & 0xf;
      os.write(b < 10 ? b + '0' : b + 'a' - 10);
      b = ch & 0xf;
      os.write(b < 10 ? b + '0' : b + 'a' - 10);
    }
  }
1236696
function(charCode) {
   	   for (var i=0, length=numKeyCodes.length; i < length; i++) {
   	      if (charCode == numKeyCodes[i]) return true;
   	   }
   	   return false;       
	   }
254417
function _charToUtf8(&$char)
	{
		$c = (int)$this->ascMap[$this->charset][$char];
		if ($c < 0x80)
			$char = \chr($c);
		else if($c<0x800) /* 2 bytes */
			$char = (\chr(0xC0 | $c>>6) . \chr(0x80 | $c & 0x3F));
		else if($c<0x10000) /* 3 bytes */
			$char = (\chr(0xE0 | $c>>12) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
		else if($c<0x200000) /* 4 bytes */
			$char = (\chr(0xF0 | $c>>18) . \chr(0x80 | $c>>12 & 0x3F) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
	}
355252
public static final void writeUTF(OutputStream out,
                                      char[] chars, int offset, int length)
        throws IOException
    {
        for (int i=0; i<length; i++) {
            int c = chars[i + offset];
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out.write(c);
            }
            else if (c > 0x07FF) {
                out.write(0xe0 | ((c >> 12) & 0x0f));
                out.write(0x80 | ((c >> 6) & 0x3f));
                out.write(0x80 | (c & 0x3f));
            }
            else {
                out.write(0xc0 | ((c >> 6) & 0x1f));
                out.write(0x80 | (c & 0x3f));
            }
        }
    }
626741
public static function utf8ToCodepoint( $char ) {
		# Find the length
		$z = ord( $char[0] );
		if ( $z & 0x80 ) {
			$length = 0;
			while ( $z & 0x80 ) {
				$length++;
				$z <<= 1;
			}
		} else {
			$length = 1;
		}

		if ( $length != strlen( $char ) ) {
			return false;
		}

		if ( $length == 1 ) {
			return ord( $char );
		}

		# Mask off the length-determining bits and shift back to the original location
		$z &= 0xff;
		$z >>= $length;

		# Add in the free bits from subsequent bytes
		for ( $i = 1; $i < $length; $i++ ) {
			$z <<= 6;
			$z |= ord( $char[$i] ) & 0x3f;
		}

		return $z;
	}
271867
private long readLong(ByteBuf chars, int length) {
        long result = 0;
        for (int i = chars.readerIndex(); i < chars.readerIndex() + length; i++) {
            int digit = ((int)chars.getByte(i) & 0xF);
            for (int j = 0; j < chars.readerIndex() + length-1-i; j++) {
                digit *= 10;
            }
            result += digit;
        }
        chars.readerIndex(chars.readerIndex() + length);
        return result;
    }
311953
def write_int8(self, value, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%sb' % endian, value)