Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.h
Show First 20 Lines • Show All 360 Lines • ▼ Show 20 Lines | public: | ||||
static std::vector<uint8_t> serialize(const int64_t &value) { | static std::vector<uint8_t> serialize(const int64_t &value) { | ||||
if (value == 0) { | if (value == 0) { | ||||
return {}; | return {}; | ||||
} | } | ||||
std::vector<uint8_t> result; | std::vector<uint8_t> result; | ||||
const bool neg = value < 0; | const bool neg = value < 0; | ||||
uint64_t absvalue = neg ? -value : value; | uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1 | ||||
: static_cast<uint64_t>(value); | |||||
while (absvalue) { | while (absvalue) { | ||||
result.push_back(absvalue & 0xff); | result.push_back(absvalue & 0xff); | ||||
absvalue >>= 8; | absvalue >>= 8; | ||||
} | } | ||||
// - If the most significant byte is >= 0x80 and the value is positive, | // - If the most significant byte is >= 0x80 and the value is positive, | ||||
// push a new zero-byte to make the significant byte < 0x80 again. | // push a new zero-byte to make the significant byte < 0x80 again. | ||||
▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines |