system/src/sc/binf/BinfOutStream.java
public void writeUInt(int v) {
      if (v < 0)
         throw new IllegalArgumentException("Negative value passed to writeUInt!");
      try {
         if (v < 0x80) {
            out.writeByte(v);
         }
         else {
            int v1 = v >> 7;
            int next = (v & 0x7f) | 0x80;
            out.writeByte(next);

            if (v1 < 0x80) {
               out.writeByte(v1);
            }
            else {
               int v2 = v1 >> 7;
               next = (v1 & 0x7f) | 0x80;
               out.writeByte(next);

               if (v2 < 0x80) {
                  out.writeByte(v2);
               }
               else {
                  int v3 = v2 >> 7;
                  next = (v2 & 0x7f) | 0x80;
                  out.writeByte(next);

                  if (v3 < 0x80) {
                     out.writeByte(v3);
                  }
                  else {
                     int v4 = v3 >> 7;
                     next = (v3 & 0x7f) | 0x80;
                     out.writeByte(next);

                     if (v4 < 0x80) {
                        out.writeByte(v4);
                     }
                     else {
                        throw new IllegalArgumentException("writeUInt- value too large: " + v); // Should not be possible since we wrote 5*7 bits!
                     }
                  }
               }
            }
         }
      }
      catch (IOException exc) {
         throw new UncheckedIOException(exc);
      }
   }
/**
    *
    * To handle parseletId, and size - writes 1-5 bytes depending upon the value using the MSB of each byte as a flag
    * to indicate whether there's another byte
    * TODO: need to handle negative numbers or at least -1 here?  This should catch all of the common cases - size, parseletId etc. and we have read/writeInt for those others
    */
To handle parseletId, and size - writes 1-5 bytes depending upon the value using the MSB of each byte as a flag
to indicate whether there's another byte
TODO: need to handle negative numbers or at least -1 here.  This should catch all of the common cases - size, parseletId etc. and we have read/writeInt for those others
To handle parseletId and size - writes 1 - 5 bytes depending upon the value using the MSB of each byte as a flag to indicate whether there ' s another byte TODO : need to handle negative numbers or at least - 1 here . This should catch all of the common cases - size parseletId etc . and we have read / writeInt for those others
public void writeUInt(int v) {
      if (v < 0)
         throw new IllegalArgumentException("Negative value passed to writeUInt!");
      try {
         if (v < 0x80) {
            out.writeByte(v);
         }
         else {
            int v1 = v >> 7;
            int next = (v & 0x7f) | 0x80;
            out.writeByte(next);
            if (v1 < 0x80) {
               out.writeByte(v1);
            }
            else {
               int v2 = v1 >> 7;
               next = (v1 & 0x7f) | 0x80;
               out.writeByte(next);
               if (v2 < 0x80) {
                  out.writeByte(v2);
               }
               else {
                  int v3 = v2 >> 7;
                  next = (v2 & 0x7f) | 0x80;
                  out.writeByte(next);
                  if (v3 < 0x80) {
                     out.writeByte(v3);
                  }
                  else {
                     int v4 = v3 >> 7;
                     next = (v3 & 0x7f) | 0x80;
                     out.writeByte(next);
                     if (v4 < 0x80) {
                        out.writeByte(v4);
                     }
                     else {
                        throw new IllegalArgumentException("writeUInt- value too large: " + v); 
                     }
                  }
               }
            }
         }
      }
      catch (IOException exc) {
         throw new UncheckedIOException(exc);
      }
   }
public void writeUInt ( int v ) { if ( v < 0 ) throw new IllegalArgumentException ( "Negative value passed to writeUInt!" ) ; try { if ( v < 0x80 ) { out . writeByte ( v ) ; } else { int v1 = v >> 7 ; int next = ( v & 0x7f ) | 0x80 ; out . writeByte ( next ) ; if ( v1 < 0x80 ) { out . writeByte ( v1 ) ; } else { int v2 = v1 >> 7 ; next = ( v1 & 0x7f ) | 0x80 ; out . writeByte ( next ) ; if ( v2 < 0x80 ) { out . writeByte ( v2 ) ; } else { int v3 = v2 >> 7 ; next = ( v2 & 0x7f ) | 0x80 ; out . writeByte ( next ) ; if ( v3 < 0x80 ) { out . writeByte ( v3 ) ; } else { int v4 = v3 >> 7 ; next = ( v3 & 0x7f ) | 0x80 ; out . writeByte ( next ) ; if ( v4 < 0x80 ) { out . writeByte ( v4 ) ; } else { throw new IllegalArgumentException ( "writeUInt- value too large: " + v ) ; } } } } } } catch ( IOException exc ) { throw new UncheckedIOException ( exc ) ; } }
To handle parseletId, and size - writes 1-5 bytes depending upon the value using the MSB of each byte as a flag
 to indicate whether there's another byte
 TODO: need to handle negative numbers or at least -1 here?
To handle parseletId and size - writes 1 - 5 bytes depending upon the value using the MSB of each byte as a flag to indicate whether there ' s another byte TODO : need to handle negative numbers or at least - 1 here?
// Should not be possible since we wrote 5*7 bits!