Java Code Examples for cn.nukkit.utils.VarInt#writeVarLong()

The following examples show how to use cn.nukkit.utils.VarInt#writeVarLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NBTOutputStream.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeLong(long v) throws IOException {
    if (network) {
        VarInt.writeVarLong(this.stream, v);
    } else {
        if (endianness == ByteOrder.LITTLE_ENDIAN) {
            v = Long.reverseBytes(v);
        }
        this.stream.writeLong(v);
    }
}
 
Example 2
Source File: NBTOutputStream.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeLong(long v) throws IOException {
    if (network) {
        VarInt.writeVarLong(this.stream, v);
    } else {
        if (endianness == ByteOrder.LITTLE_ENDIAN) {
            v = Long.reverseBytes(v);
        }
        this.stream.writeLong(v);
    }
}
 
Example 3
Source File: VarIntTest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@DisplayName("Writing")
@Test
void testWrite() throws IOException {
	BinaryStream bs = new BinaryStream();
	VarInt.writeUnsignedVarInt(bs, 237356812);
	VarInt.writeVarInt(bs, 0xea3eca71);
	VarInt.writeUnsignedVarLong(bs, 0x1234567812345678L);
	VarInt.writeVarLong(bs, 0xea3eca710becececL);
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(bs)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(bs)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(bs)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(bs))
	);
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	VarInt.writeUnsignedVarInt(os, 237356812);
	VarInt.writeVarInt(os, 0xea3eca71);
	VarInt.writeUnsignedVarLong(os, 0x1234567812345678L);
	VarInt.writeVarLong(os, 0xea3eca710becececL);
	VarInt.writeVarInt(os, 0x7FFFFFFF);
	VarInt.writeVarInt(os, -1);
	ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(is)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(is)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(is)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(is)),
			() -> assertEquals(0x7FFFFFFF, VarInt.readVarInt(is)),
			() -> assertEquals(-1, VarInt.readVarInt(is))
	);
}
 
Example 4
Source File: NBTOutputStream.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeLong(long v) throws IOException {
    if (network) {
        VarInt.writeVarLong(this.stream, v);
    } else {
        if (endianness == ByteOrder.LITTLE_ENDIAN) {
            v = Long.reverseBytes(v);
        }
        this.stream.writeLong(v);
    }
}
 
Example 5
Source File: VarIntTest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@DisplayName("Writing")
@Test
void testWrite() throws IOException {
	BinaryStream bs = new BinaryStream();
	VarInt.writeUnsignedVarInt(bs, 237356812);
	VarInt.writeVarInt(bs, 0xea3eca71);
	VarInt.writeUnsignedVarLong(bs, 0x1234567812345678L);
	VarInt.writeVarLong(bs, 0xea3eca710becececL);
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(bs)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(bs)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(bs)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(bs))
	);
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	VarInt.writeUnsignedVarInt(os, 237356812);
	VarInt.writeVarInt(os, 0xea3eca71);
	VarInt.writeUnsignedVarLong(os, 0x1234567812345678L);
	VarInt.writeVarLong(os, 0xea3eca710becececL);
	ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(is)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(is)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(is)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(is))
	);
}