本文整理汇总了Java中cn.nukkit.utils.VarInt类的典型用法代码示例。如果您正苦于以下问题:Java VarInt类的具体用法?Java VarInt怎么用?Java VarInt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VarInt类属于cn.nukkit.utils包,在下文中一共展示了VarInt类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writeInt
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@Override
public void writeInt(int v) throws IOException {
if (network) {
VarInt.writeVarInt(this.stream, v);
} else {
if (endianness == ByteOrder.LITTLE_ENDIAN) {
v = Integer.reverseBytes(v);
}
this.stream.writeInt(v);
}
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:12,代码来源:NBTOutputStream.java
示例2: writeLong
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@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);
}
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:12,代码来源:NBTOutputStream.java
示例3: writeUTF
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@Override
public void writeUTF(String s) throws IOException {
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
if (network) {
VarInt.writeUnsignedVarInt(stream, bytes.length);
} else {
this.writeShort(bytes.length);
}
this.stream.write(bytes);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:11,代码来源:NBTOutputStream.java
示例4: readInt
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@Override
public int readInt() throws IOException {
if (network) {
return VarInt.readVarInt(this.stream);
}
int i = this.stream.readInt();
if (endianness == ByteOrder.LITTLE_ENDIAN) {
i = Integer.reverseBytes(i);
}
return i;
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:12,代码来源:NBTInputStream.java
示例5: readLong
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@Override
public long readLong() throws IOException {
if (network) {
return VarInt.readVarLong(this.stream);
}
long l = this.stream.readLong();
if (endianness == ByteOrder.LITTLE_ENDIAN) {
l = Long.reverseBytes(l);
}
return l;
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:12,代码来源:NBTInputStream.java
示例6: readUTF
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@Override
public String readUTF() throws IOException {
int length = (int) (network ? VarInt.readUnsignedVarInt(stream) : this.readUnsignedShort());
byte[] bytes = new byte[length];
this.stream.read(bytes);
return new String(bytes, StandardCharsets.UTF_8);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:8,代码来源:NBTInputStream.java
示例7: testZigZag
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@DisplayName("ZigZag")
@Test
void testZigZag() {
assertAll(
() -> assertEquals(0x2468acf0, VarInt.encodeZigZag32(0x12345678)),
() -> assertEquals(0x2b826b1d, VarInt.encodeZigZag32(0xea3eca71)),
() -> assertEquals(0x12345678, VarInt.decodeZigZag32(0x2468acf0)),
() -> assertEquals(0xea3eca71, VarInt.decodeZigZag32(0x2b826b1d)),
() -> assertEquals(2623536930346282224L, VarInt.encodeZigZag64(0x1234567812345678L)),
() -> assertEquals(3135186066796324391L, VarInt.encodeZigZag64(0xea3eca710becececL)),
() -> assertEquals(0x1234567812345678L, VarInt.decodeZigZag64(2623536930346282224L)),
() -> assertEquals(0xea3eca710becececL, VarInt.decodeZigZag64(3135186066796324391L))
);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:VarIntTest.java
示例8: testWrite
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@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))
);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:28,代码来源:VarIntTest.java
示例9: testRead
import cn.nukkit.utils.VarInt; //导入依赖的package包/类
@DisplayName("Reading")
@Test
void testRead() {
assertAll(
() -> assertEquals(2412, VarInt.readUnsignedVarInt(wrapBinaryStream("EC123EC456"))),
() -> assertEquals(583868, VarInt.readUnsignedVarInt(wrapBinaryStream("BCD123EFA0"))),
() -> assertEquals(1206, VarInt.readVarInt(wrapBinaryStream("EC123EC456"))),
() -> assertEquals(291934, VarInt.readVarInt(wrapBinaryStream("BCD123EFA0"))),
() -> assertEquals(6015, VarInt.readUnsignedVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
() -> assertEquals(3694, VarInt.readUnsignedVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD"))),
() -> assertEquals(-3008, VarInt.readVarLong(wrapBinaryStream("FF2EC456EC789EC012EC"))),
() -> assertEquals(1847, VarInt.readVarLong(wrapBinaryStream("EE1CD34BCD56BCD78BCD")))
);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:VarIntTest.java
注:本文中的cn.nukkit.utils.VarInt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论