code: private static void encodeInteger(ByteBuf out, int mask, int n, long i) {
          assert n >= 0 && n <= 8 : "N: " + n;
          int nbits = 0xFF >>> (8 - n);
          if (i < nbits) {
              out.writeByte((int) (mask | i));
          } else {
              out.writeByte(mask | nbits);
              long length = i - nbits;
              for (; (length & ~0x7F) != 0; length >>>= 7) {
                  out.writeByte((int) ((length & 0x7F) | 0x80));
              }
              out.writeByte((int) length);
          }
      }
docs: Encode integer according to <a href="https://tools.ietf.org/html/rfc7541#section-5.1">Section 5.1</a>.