Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine:enhanced byte order handling for timestamps #9196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/fluent-bit/flb_byteswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FLB_BYTESWAP_H

#include <stdint.h>
#include <fluent-bit/flb_endian.h>

#if defined(FLB_HAVE_WIN32_BYTESWAP)
#include <stdlib.h>
Expand Down Expand Up @@ -102,4 +103,15 @@ static inline uint64_t FLB_BSWAP_64(uint64_t value)

#endif

static inline uint32_t FLB_UINT32_TO_HOST_BYTE_ORDER(uint32_t value)
{
#if FLB_BYTE_ORDER == FLB_LITTLE_ENDIAN
return FLB_BSWAP_32(value);
#else
return value;
#endif
}

#define FLB_UINT32_TO_NETWORK_BYTE_ORDER(value) FLB_UINT32_TO_HOST_BYTE_ORDER(value)

#endif
4 changes: 2 additions & 2 deletions src/flb_log_event_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input,
}

output->tm.tv_sec =
(int32_t) FLB_BSWAP_32(
(int32_t) FLB_UINT32_TO_HOST_BYTE_ORDER(
FLB_ALIGNED_DWORD_READ(
(unsigned char *) &input->via.ext.ptr[0]));

output->tm.tv_nsec =
(int32_t) FLB_BSWAP_32(
(int32_t) FLB_UINT32_TO_HOST_BYTE_ORDER(
FLB_ALIGNED_DWORD_READ(
(unsigned char *) &input->via.ext.ptr[4]));
}
Expand Down
4 changes: 2 additions & 2 deletions src/flb_log_event_encoder_primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_UINT32_TO_NETWORK_BYTE_ORDER((uint32_t) timestamp->tm.tv_sec);
value[1] = FLB_UINT32_TO_NETWORK_BYTE_ORDER((uint32_t) timestamp->tm.tv_nsec);

return flb_log_event_encoder_append_ext(context, target_field,
0, (char *) value, 8);
Expand Down
Loading