1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-05 02:00:31 +08:00

chore: optimize documents

This commit is contained in:
源文雨
2024-04-06 20:55:39 +09:00
parent 4ff107e46f
commit 5defe71ba9
3 changed files with 31 additions and 28 deletions

View File

@@ -30,7 +30,7 @@ typedef union {
int base16384_encode_safe(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -127,7 +127,7 @@ int base16384_encode_safe(const char* data, int dlen, char* buf) {
int base16384_encode(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -202,7 +202,7 @@ int base16384_encode(const char* data, int dlen, char* buf) {
int base16384_encode_unsafe(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -244,7 +244,7 @@ int base16384_decode_safe(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:
@@ -259,7 +259,7 @@ int base16384_decode_safe(const char* data, int dlen, char* buf) {
const uint32_t* vals = (const uint32_t*)data;
uint32_t n = 0;
int32_t i = 0;
for(; i < outlen - 7; i+=7) { // n实际每次自增2
for(; i < outlen - 7; i+=7) { // n += 2 in one loop
register uint32_t sum = 0;
register uint32_t shift = htobe32(vals[n++]) - 0x4e004e00;
shift <<= 2;
@@ -341,7 +341,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:
@@ -356,7 +356,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
const uint32_t* vals = (const uint32_t*)data;
uint32_t n = 0;
int32_t i = 0;
for(; i <= outlen - 7; i+=7) { // n实际每次自增2
for(; i <= outlen - 7; i+=7) { // n += 2 in one loop
register uint32_t sum = 0;
register uint32_t shift = htobe32(vals[n++]) - 0x4e004e00;
shift <<= 2;
@@ -375,7 +375,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
}
if(*(uint8_t*)(&vals[n]) == '=') return outlen;
if(offset--) {
// 这里有读取越界
// here comes a read overlap
#ifdef WORDS_BIGENDIAN
register uint32_t sum = __builtin_bswap32(vals[n++]);
#else
@@ -391,7 +391,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
if(offset--) {
buf[i] = (sum & 0x0f000000) >> 20;
if(*(uint8_t*)(&vals[n]) == '=') return outlen;
// 这里有读取越界
// here comes a read overlap
#ifdef WORDS_BIGENDIAN
sum = __builtin_bswap32(vals[n]);
#else
@@ -418,7 +418,7 @@ int base16384_decode_unsafe(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:
@@ -433,7 +433,7 @@ int base16384_decode_unsafe(const char* data, int dlen, char* buf) {
const uint32_t* vals = (const uint32_t*)data;
uint32_t n = 0;
int32_t i = 0;
for(; i < outlen-7; i+=7) { // n实际每次自增2
for(; i < outlen-7; i+=7) { // n += 2 in one loop
register uint32_t sum = 0;
register uint32_t shift = htobe32(vals[n++]) - 0x4e004e00;
shift <<= 2;

View File

@@ -30,7 +30,7 @@ typedef union {
int base16384_encode_safe(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -112,7 +112,7 @@ int base16384_encode_safe(const char* data, int dlen, char* buf) {
int base16384_encode(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -127,7 +127,7 @@ int base16384_encode(const char* data, int dlen, char* buf) {
int64_t i = 0;
for(; i <= dlen - 7; i += 7) {
register uint64_t sum = 0;
register uint64_t shift = htobe64(*(uint64_t*)(data+i))>>2; // 这里有读取越界
register uint64_t shift = htobe64(*(uint64_t*)(data+i))>>2; // here comes a read overlap
sum |= shift & 0x3fff000000000000;
shift >>= 2;
sum |= shift & 0x00003fff00000000;
@@ -177,7 +177,7 @@ int base16384_encode(const char* data, int dlen, char* buf) {
int base16384_encode_unsafe(const char* data, int dlen, char* buf) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -192,7 +192,7 @@ int base16384_encode_unsafe(const char* data, int dlen, char* buf) {
int64_t i = 0;
for(; i < dlen; i += 7) {
register uint64_t sum = 0;
register uint64_t shift = htobe64(*(uint64_t*)(data+i))>>2; // 这里有读取越界
register uint64_t shift = htobe64(*(uint64_t*)(data+i))>>2; // here comes a read overlap
sum |= shift & 0x3fff000000000000;
shift >>= 2;
sum |= shift & 0x00003fff00000000;
@@ -215,7 +215,7 @@ int base16384_decode_safe(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:
@@ -292,7 +292,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:
@@ -322,7 +322,7 @@ int base16384_decode(const char* data, int dlen, char* buf) {
}
if(*(uint8_t*)(&vals[n]) == '=') return outlen;
if(offset--) {
// 这里有读取越界
// here comes a read overlap
#ifdef WORDS_BIGENDIAN
register uint64_t sum = __builtin_bswap64(vals[n]) - 0x000000000000004e;
#else
@@ -356,7 +356,7 @@ int base16384_decode_unsafe(const char* data, int dlen, char* buf) {
int offset = 0;
if(data[dlen-2] == '=') {
offset = data[dlen-1];
switch(offset) { // 算上偏移标志字符占用的2字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2:

View File

@@ -66,7 +66,7 @@ typedef enum base16384_err_t base16384_err_t;
* @param count read bytes count
* @return the size read
*/
typedef ssize_t(*base16384_reader_t)(const void *client_data, void *buffer, size_t count);
typedef ssize_t (*base16384_reader_t)(const void *client_data, void *buffer, size_t count);
/**
* @brief custom writer function interface
@@ -75,13 +75,16 @@ typedef ssize_t(*base16384_reader_t)(const void *client_data, void *buffer, size
* @param count write bytes count
* @return the size written
*/
typedef ssize_t(*base16384_writer_t)(const void *client_data, const void *buffer, size_t count);
typedef ssize_t (*base16384_writer_t)(const void *client_data, const void *buffer, size_t count);
union base16384_io_function_t {
base16384_reader_t reader;
base16384_writer_t writer;
};
typedef union base16384_io_function_t base16384_io_function_t;
struct base16384_stream_t {
const union {
base16384_reader_t reader;
base16384_writer_t writer;
} f;
const base16384_io_function_t f;
const void *client_data;
};
/**
@@ -97,7 +100,7 @@ typedef struct base16384_stream_t base16384_stream_t;
static inline int _base16384_encode_len(int dlen) {
int outlen = dlen / 7 * 8;
int offset = dlen % 7;
switch(offset) { // 算上偏移标志字符占用的 2 字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen += 4; break;
case 2:
@@ -127,7 +130,7 @@ static inline int base16384_encode_len(int dlen) {
*/
static inline int _base16384_decode_len(int dlen, int offset) {
int outlen = dlen;
switch(offset) { // 算上偏移标志字符占用的 2 字节
switch(offset) { // also count 0x3dxx
case 0: break;
case 1: outlen -= 4; break;
case 2: