mirror of
https://github.com/fumiama/simple-protobuf.git
synced 2026-06-10 03:28:08 +08:00
修正writenum
This commit is contained in:
@@ -22,11 +22,10 @@ static int write_num(FILE* fp, uint64_t n) {
|
|||||||
while(n > 0) {
|
while(n > 0) {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
int ch = c[7] & 0x7f;
|
int ch = c[7] & 0x7f;
|
||||||
if(c[6]) ch |= 0x80;
|
|
||||||
#else
|
#else
|
||||||
int ch = *c & 0x7f;
|
int ch = *c & 0x7f;
|
||||||
if(c[1]) ch |= 0x80;
|
|
||||||
#endif
|
#endif
|
||||||
|
if((n >> 7) > 0) ch |= 0x80;
|
||||||
fputc(ch, fp);
|
fputc(ch, fp);
|
||||||
n >>= 7;
|
n >>= 7;
|
||||||
i++;
|
i++;
|
||||||
@@ -66,6 +65,9 @@ int set_pb(FILE* fp, uint8_t* items_type, uint64_t struct_len, void* target) {
|
|||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
char* p = (char*)target;
|
char* p = (char*)target;
|
||||||
write_num(fp, struct_len);
|
write_num(fp, struct_len);
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("struct_len: %llu bytes.\n", struct_len);
|
||||||
|
#endif
|
||||||
while(offset < struct_len) {
|
while(offset < struct_len) {
|
||||||
uint8_t type = items_type[i++];
|
uint8_t type = items_type[i++];
|
||||||
uint64_t data_len = 1u << type;
|
uint64_t data_len = 1u << type;
|
||||||
|
|||||||
Reference in New Issue
Block a user