diff --git a/include/fluent-bit/flb_byteswap.h b/include/fluent-bit/flb_byteswap.h index b166378b53f..08040fec585 100644 --- a/include/fluent-bit/flb_byteswap.h +++ b/include/fluent-bit/flb_byteswap.h @@ -21,6 +21,7 @@ #define FLB_BYTESWAP_H #include +#include #if defined(FLB_HAVE_WIN32_BYTESWAP) #include @@ -102,4 +103,13 @@ static inline uint64_t FLB_BSWAP_64(uint64_t value) #endif +static inline uint32_t FLB_TO_NATIVE_UINT32(uint32_t value) +{ + #if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + return FLB_BSWAP_32(value); + #else + return value; + #endif +} + #endif diff --git a/src/flb_log_event_decoder.c b/src/flb_log_event_decoder.c index 53cf1c63412..fe65f5a6e2d 100644 --- a/src/flb_log_event_decoder.c +++ b/src/flb_log_event_decoder.c @@ -179,8 +179,8 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input, return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE; } - output->tm.tv_sec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[0])); - output->tm.tv_nsec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[4])); + output->tm.tv_sec = (int32_t) FLB_TO_NATIVE_UINT32(*((uint32_t *) &input->via.ext.ptr[0])); + output->tm.tv_nsec = (int32_t) FLB_TO_NATIVE_UINT32(*((uint32_t *) &input->via.ext.ptr[4])); } else { return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE; diff --git a/src/flb_log_event_encoder_primitives.c b/src/flb_log_event_encoder_primitives.c index dbcb4a4b808..71da0475087 100644 --- a/src/flb_log_event_encoder_primitives.c +++ b/src/flb_log_event_encoder_primitives.c @@ -519,8 +519,8 @@ int flb_log_event_encoder_append_forward_v1_timestamp( { uint32_t value[2]; - value[0] = FLB_BSWAP_32((uint32_t) timestamp->tm.tv_sec); - value[1] = FLB_BSWAP_32((uint32_t) timestamp->tm.tv_nsec); + value[0] = FLB_TO_NATIVE_UINT32((uint32_t) timestamp->tm.tv_sec); + value[1] = FLB_TO_NATIVE_UINT32((uint32_t) timestamp->tm.tv_nsec); return flb_log_event_encoder_append_ext(context, target_field, 0, (char *) value, 8);