From db1b95a42e6abc9f4ed980d3bf819e534374fcdb Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 17 May 2021 18:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3writenum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protobuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protobuf.c b/protobuf.c index e7a5ec8..4b24046 100644 --- a/protobuf.c +++ b/protobuf.c @@ -22,11 +22,10 @@ static int write_num(FILE* fp, uint64_t n) { while(n > 0) { #ifdef WORDS_BIGENDIAN int ch = c[7] & 0x7f; - if(c[6]) ch |= 0x80; #else int ch = *c & 0x7f; - if(c[1]) ch |= 0x80; #endif + if((n >> 7) > 0) ch |= 0x80; fputc(ch, fp); n >>= 7; i++; @@ -66,6 +65,9 @@ int set_pb(FILE* fp, uint8_t* items_type, uint64_t struct_len, void* target) { uint32_t i = 0; char* p = (char*)target; write_num(fp, struct_len); + #ifdef DEBUG + printf("struct_len: %llu bytes.\n", struct_len); + #endif while(offset < struct_len) { uint8_t type = items_type[i++]; uint64_t data_len = 1u << type;