-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.cpp
28 lines (23 loc) · 828 Bytes
/
Reader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*******************************************************************************
* Rohan data serialization library.
*
* © 2016—2024, Sauron
******************************************************************************/
#include "Reader.hpp"
using namespace rohan;
/******************************************************************************/
unsigned long long rohan::readVariableInteger(Reader &stream) {
unsigned long long result=0;
uint8_t byte=0x80;
unsigned shift=0;
while (byte&0x80) {
byte=uint8_t(stream);
result|=((unsigned long long)(byte&0x7f)<<shift);
shift+=7;
}
return result;
}
signed long long rohan::readSignedVariableInteger(Reader &stream) {
unsigned long long tmp=readVariableInteger(stream);
return ((1&tmp)?(tmp^(~0)):tmp)>>1;
}