feat(big): add SBigFromUnsigned, SBigNew, and SBigToBinaryBuffer

This commit is contained in:
fallenoak 2023-01-29 11:48:18 -06:00 committed by GitHub
parent 630e6dbb1f
commit 7d5a157162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 211 additions and 0 deletions

View file

@ -19,6 +19,26 @@ uint32_t ExtractLowPartSx(uint64_t& value) {
return low;
}
void FromUnsigned(BigBuffer& buffer, uint32_t value) {
buffer[0] = value;
buffer.SetCount(1);
}
uint64_t MakeLarge(uint32_t low, uint32_t high) {
return low + (static_cast<uint64_t>(high) << 32);
}
void ToBinaryAppend(TSGrowableArray<uint8_t>& output, const BigBuffer& buffer) {
for (uint32_t i = 0; i < buffer.Count() * 4; i++) {
auto byte = buffer[i / 4] >> (8 * (i & 3));
if (byte || (i / 4) + 1 < buffer.Count()) {
*output.New() = byte;
}
}
}
void ToBinary(TSGrowableArray<uint8_t>& output, const BigBuffer& buffer) {
output.SetCount(0);
ToBinaryAppend(output, buffer);
}