/
BirdLeon
/
ROBLOX2016
Обзор
Документация
Войти
/
BirdLeon
/
ROBLOX2016
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
App/util/Base64BinaryInputStream.cpp
54 строки
1 KB
PatoFlamejanteTV
full source code
19 дек 2024, 19:11
19 дек 2024, 19:11
05db15d
Код
Авторство
О чём код?
#include "stdafx.h" #include "Util/Base64BinaryInputStream.h" #include "Rbx/Debug.h" namespace RBX { unsigned char Base64BinaryInputStream::decode(unsigned char charFromString) { if (charFromString >= 'A' && charFromString <= 'Z') { return charFromString - 'A'; } if (charFromString >= 'a' && charFromString <= 'z') { return 26 + (charFromString - 'a'); } if (charFromString >= '0' && charFromString <= '9') { return 52 + (charFromString - '0'); } if (charFromString == '+') { return 62; } if (charFromString == '/') { return 63; } RBXASSERT(false); return 0; } Base64BinaryInputStream::Base64BinaryInputStream(const char* source) : source(source), buffer(0), readableBitsInBuffer(0) {} void Base64BinaryInputStream::ReadBits(unsigned char* output, size_t numBitsToRead) { RBXASSERT(numBitsToRead <= 8); RBXASSERT(numBitsToRead >= 1); while (numBitsToRead > readableBitsInBuffer) { boost::uint16_t nextValue = decode(*source); source++; // decode produced a 6 bit number. Shift that to the head (16 - 6 = 10), // leaving room for the readableBits nextValue <<= (10 - readableBitsInBuffer); buffer |= nextValue; readableBitsInBuffer += 6; } RBXASSERT(numBitsToRead <= readableBitsInBuffer); unsigned char tmp = buffer >> (16 - numBitsToRead); (*output) = tmp; buffer <<= numBitsToRead; readableBitsInBuffer -= numBitsToRead; } }