code: private int readRawVarint32(ByteBuffer bytes) {
      byte tmp = bytes.get();
      if (tmp >= 0) {
        return tmp;
      }
      int result = tmp & 0x7f;
      if ((tmp = bytes.get()) >= 0) {
        result |= tmp << 7;
      } else {
        result |= (tmp & 0x7f) << 7;
        if ((tmp = bytes.get()) >= 0) {
          result |= tmp << 14;
        } else {
          result |= (tmp & 0x7f) << 14;
          if ((tmp = bytes.get()) >= 0) {
            result |= tmp << 21;
          } else {
            result |= (tmp & 0x7f) << 21;
            result |= (tmp = bytes.get()) << 28;
            if (tmp < 0) {
              // Discard upper 32 bits.
              for (int i = 0; i < 5; i++) {
                if (bytes.get() >= 0) {
                  return result;
                }
              }
              connectionHandler.onException(new ScopeException("Error while reading raw int"));
            }
          }
        }
      }
      return result;
    }
docs: explained: http://code.google.com/apis/protocolbuffers/docs/encoding.html#varints