mirror of
https://github.com/fumiama/base16384.git
synced 2026-06-23 00:38:32 +08:00
feat(coder): add safe encode/decode
This commit is contained in:
18
base16384.h
18
base16384.h
@@ -116,6 +116,15 @@ static inline int base16384_decode_len(int dlen, int offset) {
|
||||
return _base16384_decode_len(dlen, offset) + 16; // 多出 16 字节用于 unsafe 循环覆盖
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief safely encode data and write result into buf
|
||||
* @param data data to encode, no data overread
|
||||
* @param dlen the data length
|
||||
* @param buf the output buffer, whose size can be exactly `_base16384_encode_len`
|
||||
* @return the total length written
|
||||
*/
|
||||
int base16384_encode_safe(const char* data, int dlen, char* buf);
|
||||
|
||||
/**
|
||||
* @brief encode data and write result into buf
|
||||
* @param data data to encode
|
||||
@@ -134,6 +143,15 @@ int base16384_encode(const char* data, int dlen, char* buf);
|
||||
*/
|
||||
int base16384_encode_unsafe(const char* data, int dlen, char* buf);
|
||||
|
||||
/**
|
||||
* @brief safely decode data and write result into buf
|
||||
* @param data data to decode, no data overread
|
||||
* @param dlen the data length
|
||||
* @param buf the output buffer, whose size can be exactly `_base16384_decode_len`
|
||||
* @return the total length written
|
||||
*/
|
||||
int base16384_decode_safe(const char* data, int dlen, char* buf);
|
||||
|
||||
/**
|
||||
* @brief decode data and write result into buf
|
||||
* @param data data to decode
|
||||
|
||||
Reference in New Issue
Block a user