Encode and write a varint.  {@code value} is treated as
unsigned, so it won't be sign-extended if negative.
322929
public void writeRawVarint32(int value) throws IOException {
    while (true) {
      if ((value & ~0x7F) == 0) {
        writeRawByte(value);
        return;
      } else {
        writeRawByte((value & 0x7F) | 0x80);
        value >>>= 7;
      }
    }
  }
524085
def WriteUInt256(self, value):
        
        if type(value) is UInt256:
            value.Serialize(self)
        else:
            raise Exception("Cannot write value that is not UInt256")
317323
public static void writeUnpaddedInteger(Writer out, long value)
        throws IOException
    {
        int intValue = (int)value;
        if (intValue == value) {
            writeUnpaddedInteger(out, intValue);
        } else {
            out.write(Long.toString(value));
        }
    }
407420
public void writeVInt(int value) {
        if(value < 0) {
            writeByte((byte)0x80);
            return;
        }

        if(value > 0x0FFFFFFF) writeByte((byte)(0x80 | ((value >>> 28))));
        if(value > 0x1FFFFF)   writeByte((byte)(0x80 | ((value >>> 21) & 0x7F)));
        if(value > 0x3FFF)     writeByte((byte)(0x80 | ((value >>> 14) & 0x7F)));
        if(value > 0x7F)       writeByte((byte)(0x80 | ((value >>>  7) & 0x7F)));

        writeByte((byte)(value & 0x7F));
    }
683937
private static byte[] writeInt(int value) throws IOException {
        byte[] b = new byte[4];

        b[0] = (byte) (value & 0x000000FF);
        b[1] = (byte) ((value & 0x0000FF00) >> 8);
        b[2] = (byte) ((value & 0x00FF0000) >> 16);
        b[3] = (byte) ((value & 0xFF000000) >> 24);

        return b;
    }
1239757
public static byte[] getVariableByteUnsigned(int value) {
        if (value < 0) {
            throw new InvalidParameterException("negative value not allowed: " + value);
        } else if (value < 128) { // 2^7
            // encode the number in a single byte
            return new byte[]{(byte) value};
        } else if (value < 16384) { // 2^14
            // encode the number in two bytes
            return new byte[]{(byte) (value | 0x80), (byte) (value >> 7)};
        } else if (value < 2097152) { // 2^21
            // encode the number in three bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) (value >> 14)};
        } else if (value < 268435456) { // 2^28
            // encode the number in four bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) (value >> 21)};
        } else {
            // encode the number in five bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) ((value >> 21) | 0x80), (byte) (value >> 28)};
        }
    }
468901
private static String unsignedToString(final long value) {
    if (value >= 0) {
      return Long.toString(value);
    } else {
      // Pull off the most-significant bit so that BigInteger doesn't think
      // the number is negative, then set it again using setBit().
      return BigInteger.valueOf(value & 0x7FFFFFFFFFFFFFFFL)
                       .setBit(63).toString();
    }
  }
134648
public void writeVarShort(final short value, int optimal) throws IOException {
    if (value < 0) throw new IllegalArgumentException();
    int[] varShortDepths = {optimal, 16};
    final int bitLength = new Bits(value).bitLength;
    int type = Arrays.binarySearch(varShortDepths, bitLength);
    if (type < 0) {
      type = -type - 1;
    }
    this.write(new Bits(type, 1));
    this.write(new Bits(value, varShortDepths[type]));
  }
788182
public void writeIntLenenc(final long value) {
        if (value < 0xfb) {
            byteBuf.writeByte((int) value);
            return;
        }
        if (value < Math.pow(2, 16)) {
            byteBuf.writeByte(0xfc);
            byteBuf.writeShortLE((int) value);
            return;
        }
        if (value < Math.pow(2, 24)) {
            byteBuf.writeByte(0xfd);
            byteBuf.writeMediumLE((int) value);
            return;
        }
        byteBuf.writeByte(0xfe);
        byteBuf.writeLongLE(value);
    }
1338125
function encodeUInt32(value) {
    let buffer = new ByteBuffer();
    if (value === null) {
        return buffer;
    }
    return buffer.writeVarint32(value);
}
1214165
public void writeInt(int value) throws IOException {
    if (4 > buf.length - pos) {
      //not enough space remaining
      byte[] arr = new byte[4];
      arr[0] = (byte) value;
      arr[1] = (byte) (value >> 8);
      arr[2] = (byte) (value >> 16);
      arr[3] = (byte) (value >> 24);
      write(arr, 0, 4);
      return;
    }

    buf[pos] = (byte) value;
    buf[pos + 1] = (byte) (value >> 8);
    buf[pos + 2] = (byte) (value >> 16);
    buf[pos + 3] = (byte) (value >> 24);
    pos += 4;
  }
261208
public final static void writeMediumInt(ByteBuffer out, int value) {
        out.put((byte) ((value >>> 16) & 0xff));
        out.put((byte) ((value >>> 8) & 0xff));
        out.put((byte) (value & 0xff));
    }
434854
public static void writeMediumInt(IoBuffer out, int value) {
        byte[] bytes = new byte[3];
        bytes[0] = (byte) ((value >>> 16) & 0x000000FF);
        bytes[1] = (byte) ((value >>> 8) & 0x000000FF);
        bytes[2] = (byte) (value & 0x00FF);
        out.put(bytes);
    }
1276544
public void writeInt(int value) throws UnsupportedEncodingException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "writeInt", Integer.valueOf(value));
    getBodyList().add(Integer.valueOf(value));
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "writeInt");
  }
318383
public void writeSInt64(final int fieldNumber, final long value)
                          throws IOException {
    writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
    writeSInt64NoTag(value);
  }
1174169
public void writeGeneric( Object value )
    {
        if (value == null)
            write(NULL_VALUE);
        else
        {
            if (value instanceof String)
            {
                writeByte(TYPE_STRING);
                writeUTF((String)value);
            }
            else if (value instanceof Boolean)
            {
                writeByte(TYPE_BOOLEAN);
                writeBoolean(((Boolean)value).booleanValue());
            }
            else if (value instanceof Byte)
            {
                writeByte(TYPE_BYTE);
                writeByte(((Byte)value).byteValue());
            }
            else if (value instanceof Short)
            {
                writeByte(TYPE_SHORT);
                writeShort(((Short)value).shortValue());
            }
            else if (value instanceof Integer)
            {
                writeByte(TYPE_INT);
                writeInt(((Integer)value).intValue());
            }
            else if (value instanceof Long)
            {
                writeByte(TYPE_LONG);
                writeLong(((Long)value).longValue());
            }
            else if (value instanceof Float)
            {
                writeByte(TYPE_FLOAT);
                writeFloat(((Float)value).floatValue());
            }
            else if (value instanceof Double)
            {
                writeByte(TYPE_DOUBLE);
                writeDouble(((Double)value).doubleValue());
            }
            else if (value instanceof byte[])
            {
                writeByte(TYPE_BYTEARRAY);
                writeByteArray((byte[])value);
            }
            else if (value instanceof Character)
            {
                writeByte(TYPE_CHARACTER);
                writeChar(((Character)value).charValue());
            }
            else
                throw new IllegalArgumentException("Unsupported type : "+value.getClass().getName());
        }
383508
function encodeFloat(value) {
    let buffer = new ByteBuffer();
    buffer.littleEndian = true;
    buffer.limit = 8;
    if (value === null) {
        return buffer;
    }
    return buffer.writeFloat(value);
}