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)
|
include(TestBigEndian)
|
||||||
test_big_endian(isBigEndian)
|
test_big_endian(isBigEndian)
|
||||||
if (${isBigEndian})
|
if (${isBigEndian})
|
||||||
add_library(spb SHARED protobuf_be.c)
|
add_definitions(-DWORDS_BIGENDIAN)
|
||||||
else()
|
|
||||||
add_library(spb SHARED protobuf_le.c)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_library(spb SHARED protobuf.c)
|
||||||
add_executable(test test.c)
|
add_executable(test test.c)
|
||||||
target_link_libraries(test spb)
|
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) {
|
static int write_num(FILE* fp, uint64_t n) {
|
||||||
char* c = (char*)(&n);
|
char* c = (char*)(&n);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(*c) {
|
while(n > 0) {
|
||||||
int ch = *c & 0x7f;
|
#ifdef WORDS_BIGENDIAN
|
||||||
if(c[1]) ch |= 0x80;
|
int ch = c[7] & 0x7f;
|
||||||
|
if(c[6]) ch |= 0x80;
|
||||||
|
#else
|
||||||
|
int ch = *c & 0x7f;
|
||||||
|
if(c[1]) ch |= 0x80;
|
||||||
|
#endif
|
||||||
fputc(ch, fp);
|
fputc(ch, fp);
|
||||||
n >>= 7;
|
n >>= 7;
|
||||||
i++;
|
i++;
|
||||||
Reference in New Issue
Block a user