Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java:
- public static void writeVarInt(int value) {
- do {
- byte temp = (byte)(value & 0b01111111);
- // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
- value >>>= 7;
- if (value != 0) {
- temp |= 0b10000000;
- }
- writeByte(temp);
- } while (value != 0);
- }
- c++:
- void PacketWriterNoCopy::writeVarInt(std::int32_t v)
- {
- writeVarInt(*reinterpret_cast<std::uint32_t*>(std::addressof(v)));
- }
- void PacketWriterNoCopy::writeVarInt(std::uint32_t v)
- {
- do
- {
- std::int8_t temp = static_cast<std::uint8_t>(v & 0b01111111);
- v >>= 7;
- if (v != 0)
- {
- temp |= 0b10000000;
- }
- writeByte(temp);
- } while (v != 0);
- }
- http://wiki.vg/Protocol#VarInt_and_VarLong
Advertisement
Add Comment
Please, Sign In to add comment