docs: public static LinkedBuffer sencode(final byte[] input, int inOffset, int inLen,
              final WriteSession session,
              final LinkedBuffer lb) throws IOException
      {
          int outputSize = ((inLen + 2) / 3) * 4;
          session.size += outputSize;
  
          int available = lb.buffer.length - lb.offset;
          if (outputSize > available)
          {
              final byte[] buffer = lb.buffer;
              int offset = lb.offset, remaining = inLen % 3, chunks = available / 4;
              byte b0, b1, b2;
  
              for (int stop = inOffset + (inLen - remaining); inOffset < stop; chunks--)
              {
                  if (chunks == 0)
                  {
                      // available size is less than 4
                      // flush and reset
                      offset = session.flush(buffer, lb.start, offset - lb.start);
                      // available = buffer.length - offset;
                      chunks = (buffer.length - offset) / 4;
                  }
  
                  b0 = input[inOffset++];
                  b1 = input[inOffset++];
                  b2 = input[inOffset++];
                  buffer[offset++] = nibble2code[(b0 >>> 2) & 0x3f];
                  buffer[offset++] = nibble2code[(b0 << 4) & 0x3f | (b1 >>> 4) & 0x0f];
                  buffer[offset++] = nibble2code[(b1 << 2) & 0x3f | (b2 >>> 6) & 0x03];
                  buffer[offset++] = nibble2code[b2 & 077];
              }
  
              switch (remaining)
              {
                  case 0:
                      break;
                  case 1:
                      if (chunks == 0)
                          offset = session.flush(buffer, lb.start, offset - lb.start);
  
                      b0 = input[inOffset++];
                      buffer[offset++] = nibble2code[(b0 >>> 2) & 0x3f];
                      buffer[offset++] = nibble2code[(b0 << 4) & 0x3f];
                      buffer[offset++] = pad;
                      buffer[offset++] = pad;
                      break;
                  case 2:
                      if (chunks == 0)
                          offset = session.flush(buffer, lb.start, offset - lb.start);
  
                      b0 = input[inOffset++];
                      b1 = input[inOffset++];
                      buffer[offset++] = nibble2code[(b0 >>> 2) & 0x3f];
                      buffer[offset++] = nibble2code[(b0 << 4) & 0x3f | (b1 >>> 4) & 0x0f];
                      buffer[offset++] = nibble2code[(b1 << 2) & 0x3f];
                      buffer[offset++] = pad;
                      break;
  
                  default:
                      throw new IllegalStateException("should not happen");
              }
  
              lb.offset = offset;
              return lb;
          }
  
          encode(input, inOffset, inLen, lb.buffer, lb.offset);
          lb.offset += outputSize;
  
          return lb;
      }