mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
Core: Refine utility string/hex
This commit is contained in:
parent
66aaad7805
commit
deb54b8866
2 changed files with 25 additions and 4 deletions
|
@ -1078,6 +1078,22 @@ char* srs_data_to_hex(char* des, const u_int8_t* src, int len)
|
|||
return des;
|
||||
}
|
||||
|
||||
char* srs_data_to_hex_lowercase(char* des, const u_int8_t* src, int len)
|
||||
{
|
||||
if(src == NULL || len == 0 || des == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *hex_table = "0123456789abcdef";
|
||||
|
||||
for (int i=0; i<len; i++) {
|
||||
des[i * 2] = hex_table[src[i] >> 4];
|
||||
des[i * 2 + 1] = hex_table[src[i] & 0x0F];
|
||||
}
|
||||
|
||||
return des;
|
||||
}
|
||||
|
||||
int srs_hex_to_data(uint8_t* data, const char* p, int size)
|
||||
{
|
||||
if (size <= 0 || (size%2) == 1) {
|
||||
|
|
|
@ -145,12 +145,17 @@ extern srs_error_t srs_av_base64_decode(std::string cipher, std::string& plainte
|
|||
// Calculate the output size needed to base64-encode x bytes to a null-terminated string.
|
||||
#define SRS_AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
|
||||
|
||||
// Convert hex string to data, for example, p=config='139056E5A0'
|
||||
// The output data in hex {0x13, 0x90, 0x56, 0xe5, 0xa0} as such.
|
||||
// Covert hex string to uint8 data, for example:
|
||||
// srs_hex_to_data(data, string("139056E5A0"))
|
||||
// which outputs the data in hex {0x13, 0x90, 0x56, 0xe5, 0xa0}.
|
||||
extern int srs_hex_to_data(uint8_t* data, const char* p, int size);
|
||||
|
||||
// Convert data string to hex.
|
||||
extern char *srs_data_to_hex(char *des, const uint8_t *src, int len);
|
||||
// Convert data string to hex, for example:
|
||||
// srs_data_to_hex(des, {0xf3, 0x3f}, 2)
|
||||
// which outputs the des is string("F33F").
|
||||
extern char* srs_data_to_hex(char* des, const uint8_t* src, int len);
|
||||
// Output in lowercase, such as string("f33f").
|
||||
extern char* srs_data_to_hex_lowercase(char* des, const uint8_t* src, int len);
|
||||
|
||||
// Generate the c0 chunk header for msg.
|
||||
// @param cache, the cache to write header.
|
||||
|
|
Loading…
Reference in a new issue