mirror of
https://github.com/fumiama/simple-protobuf.git
synced 2026-06-05 00:10:24 +08:00
增加BE,修正write num
This commit is contained in:
@@ -4,10 +4,9 @@ project(simple-protobuf)
|
||||
include(TestBigEndian)
|
||||
test_big_endian(isBigEndian)
|
||||
if (${isBigEndian})
|
||||
add_library(spb SHARED protobuf_be.c)
|
||||
else()
|
||||
add_library(spb SHARED protobuf_le.c)
|
||||
add_definitions(-DWORDS_BIGENDIAN)
|
||||
endif()
|
||||
|
||||
add_library(spb SHARED protobuf.c)
|
||||
add_executable(test test.c)
|
||||
target_link_libraries(test spb)
|
||||
@@ -19,9 +19,14 @@ static uint64_t read_num(FILE* fp) {
|
||||
static int write_num(FILE* fp, uint64_t n) {
|
||||
char* c = (char*)(&n);
|
||||
int i = 0;
|
||||
while(*c) {
|
||||
int ch = *c & 0x7f;
|
||||
if(c[1]) ch |= 0x80;
|
||||
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
|
||||
fputc(ch, fp);
|
||||
n >>= 7;
|
||||
i++;
|
||||
Reference in New Issue
Block a user