add fmt and scan versions of uint*

master
leitner 5 years ago
parent adea4281a7
commit 94ebb21f87

@ -2,7 +2,8 @@
#ifndef UINT16_H
#define UINT16_H
#include <inttypes.h>
#include <inttypes.h> // uint16_t, int16_t
#include <stddef.h> // size_t
#ifdef __cplusplus
extern "C" {
@ -58,6 +59,28 @@ uint16 uint16_read_big(const char *in);
#endif
static inline size_t fmt_uint16(char* out, uint16 in) {
if (out) uint16_pack(out,in);
return 2;
}
static inline size_t fmt_uint16_big(char* out, uint16 in) {
if (out) uint16_pack_big(out,in);
return 2;
}
static inline size_t scan_uint16(const char* in, size_t len, uint16_t* b) {
if (len<2) return 0;
*b = uint16_read(in);
return 2;
}
static inline size_t scan_uint16_big(const char* in, size_t len, uint16_t* b) {
if (len<2) return 0;
*b = uint16_read_big(in);
return 2;
}
#ifdef __cplusplus
}
#endif

@ -2,7 +2,8 @@
#ifndef UINT32_H
#define UINT32_H
#include <inttypes.h>
#include <inttypes.h> // uint32_t, int32_t
#include <stddef.h> // size_t
#ifdef __cplusplus
extern "C" {
@ -58,6 +59,28 @@ uint32 uint32_read_big(const char *in);
#endif
static inline size_t fmt_uint32(char* out, uint32 in) {
if (out) uint32_pack(out,in);
return 4;
}
static inline size_t fmt_uint32_big(char* out, uint32 in) {
if (out) uint32_pack_big(out,in);
return 4;
}
static inline size_t scan_uint32(const char* in, size_t len, uint32_t* b) {
if (len<4) return 0;
*b = uint32_read(in);
return 4;
}
static inline size_t scan_uint32_big(const char* in, size_t len, uint32_t* b) {
if (len<4) return 0;
*b = uint32_read_big(in);
return 4;
}
#ifdef __cplusplus
}
#endif

@ -2,7 +2,8 @@
#ifndef UINT64_H
#define UINT64_H
#include <inttypes.h>
#include <inttypes.h> // uint64_t, int64_t
#include <stddef.h> // size_t
#ifdef __cplusplus
extern "C" {
@ -29,6 +30,28 @@ uint64 uint64_read_big(const char *in);
#endif
static inline size_t fmt_uint64(char* out, uint64 in) {
if (out) uint64_pack(out,in);
return 8;
}
static inline size_t fmt_uint64_big(char* out, uint64 in) {
if (out) uint64_pack_big(out,in);
return 8;
}
static inline size_t scan_uint64(const char* in, size_t len, uint64_t* b) {
if (len<8) return 0;
*b = uint64_read(in);
return 8;
}
static inline size_t scan_uint64_big(const char* in, size_t len, uint64_t* b) {
if (len<8) return 0;
*b = uint64_read_big(in);
return 8;
}
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save