Class Base46

java.lang.Object
org.teavm.classlib.impl.Base46

public final class Base46 extends Object

Base47 encoding is best fit for encoding varible length numbers in JavaScript strings.

47 = (int)(93 / 2), where 94 is the number of ASCII characters representable in JavaScript string without escaping. These characters are encoded by one byte in UTF-8 charset. All other character require either escaping or two or more bytes in UTF-8.

We divide 93 by 2 for the following trick. Representing integers takes 5 bytes in Base93. However, we often need smaller integers that might be represented by one or two bytes. By each Base93 digit we can encode both part of the number and a flag indicating whether the number contains one more digit.

Author:
Alexey Andreev
  • Method Details

    • encodeUnsigned

      public static void encodeUnsigned(StringBuilder sb, int number)
    • encode

      public static void encode(StringBuilder sb, int number)
    • encodeUnsigned

      public static void encodeUnsigned(StringBuilder sb, long number)
    • encode

      public static void encode(StringBuilder sb, long number)
    • decodeUnsigned

      public static int decodeUnsigned(CharFlow seq)
    • decode

      public static int decode(CharFlow seq)
    • decodeUnsignedLong

      public static long decodeUnsignedLong(CharFlow seq)
    • decodeLong

      public static long decodeLong(CharFlow seq)
    • encodeDigit

      public static char encodeDigit(int digit)
    • decodeDigit

      public static int decodeDigit(char c)