code: public void writeLength(long length) {
      if (length < 251) {
        buf[position++] = (byte) length;
      } else if (length < 65536) {
        buf[position++] = (byte) 0xfc;
        buf[position++] = (byte) length;
        buf[position++] = (byte) (length >>> 8);
      } else if (length < 16777216) {
        buf[position++] = (byte) 0xfd;
        buf[position++] = (byte) length;
        buf[position++] = (byte) (length >>> 8);
        buf[position++] = (byte) (length >>> 16);
      } else {
        buf[position++] = (byte) 0xfe;
        buf[position++] = (byte) length;
        buf[position++] = (byte) (length >>> 8);
        buf[position++] = (byte) (length >>> 16);
        buf[position++] = (byte) (length >>> 24);
        buf[position++] = (byte) (length >>> 32);
        buf[position++] = (byte) (length >>> 40);
        buf[position++] = (byte) (length >>> 48);
        buf[position++] = (byte) (length >>> 54);
      }
    }
docs: Write length.
  
  @param length length