xTachyon

Untitled

Feb 10th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. java:
  2.  
  3. public static void writeVarInt(int value) {
  4.     do {
  5.         byte temp = (byte)(value & 0b01111111);
  6.         // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
  7.         value >>>= 7;
  8.         if (value != 0) {
  9.             temp |= 0b10000000;
  10.         }
  11.         writeByte(temp);
  12.     } while (value != 0);
  13. }
  14.  
  15. c++:
  16.  
  17. void PacketWriterNoCopy::writeVarInt(std::int32_t v)
  18. {
  19.   writeVarInt(*reinterpret_cast<std::uint32_t*>(std::addressof(v)));
  20. }
  21.  
  22. void PacketWriterNoCopy::writeVarInt(std::uint32_t v)
  23. {
  24.   do
  25.   {
  26.     std::int8_t temp = static_cast<std::uint8_t>(v & 0b01111111);
  27.     v >>= 7;
  28.     if (v != 0)
  29.     {
  30.       temp |= 0b10000000;
  31.     }
  32.     writeByte(temp);
  33.   } while (v != 0);
  34. }
  35.  
  36. http://wiki.vg/Protocol#VarInt_and_VarLong
Advertisement
Add Comment
Please, Sign In to add comment