-
Notifications
You must be signed in to change notification settings - Fork 20
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
Error on big endian machine #449
Comments
I'm sorry, but I'm having trouble understanding whether you're asking about copying data between a buffer and a struct, or between two structs. Could you please clarify which scenario you're referring to? |
This structure should be defined in this way
At 2023-05-17 17:30:34, "xinyi" ***@***.***> wrote:
I'm sorry, but I'm having trouble understanding whether you're asking about copying data between a buffer and a struct, or between two structs. Could you please clarify which scenario you're referring to?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Index: CMakeLists.txt
===================================================================
…--- CMakeLists.txt
+++ CMakeLists.txt
@@ -145,6 +145,12 @@
set(NNG_SANITIZER_FLAGS "-fsanitize=${NNG_SANITIZER}")
endif ()
+include(TestBigEndian)
+test_big_endian(NNG_BIG_ENDIAN)
+if (NNG_BIG_ENDIAN)
+ add_definitions(-DNNG_BIG_ENDIAN)
+endif ()
+
if (NNG_ENABLE_COVERAGE)
# NB: This only works for GCC and Clang 3.0 and newer. If your stuff
# is older than that, you will need to find something newer. For
Index: src/supplemental/mqtt/mqtt_msg.h
===================================================================
--- src/supplemental/mqtt/mqtt_msg.h(版本 1888)
+++ src/supplemental/mqtt/mqtt_msg.h(版本 1889)
@@ -55,7 +55,16 @@
/* CONNECT flags */
typedef struct conn_flags_t {
+#ifdef NNG_BIG_ENDIAN
+uint8_t username_flag : 1;
+uint8_t password_flag : 1;
+uint8_t will_retain : 1;
+uint8_t will_qos : 2;
+uint8_t will_flag : 1;
+uint8_t clean_session : 1;
uint8_t reserved : 1;
+#else
+uint8_t reserved : 1;
uint8_t clean_session : 1;
uint8_t will_flag : 1;
uint8_t will_qos : 2;
@@ -62,6 +71,7 @@
uint8_t will_retain : 1;
uint8_t password_flag : 1;
uint8_t username_flag : 1;
+#endif
} conn_flags;
/*****************************************************************************
@@ -211,18 +221,33 @@
};
typedef struct {
+#ifdef NNG_BIG_ENDIAN
+uint8_t packet_type : 4;
+uint8_t bit_3 : 1;
+uint8_t bit_2 : 1;
+uint8_t bit_1 : 1;
uint8_t bit_0 : 1;
+#else
+uint8_t bit_0 : 1;
uint8_t bit_1 : 1;
uint8_t bit_2 : 1;
uint8_t bit_3 : 1;
uint8_t packet_type : 4;
+#endif
} mqtt_common_hdr;
typedef struct {
+#ifdef NNG_BIG_ENDIAN
+uint8_t packet_type : 4;
+uint8_t dup : 1;
+uint8_t qos : 2;
uint8_t retain : 1;
+#else
+uint8_t retain : 1;
uint8_t qos : 2;
uint8_t dup : 1;
uint8_t packet_type : 4;
+#endif
} mqtt_pub_hdr;
typedef struct mqtt_fixed_hdr_t {
At 2023-05-17 17:30:34, "xinyi" ***@***.***> wrote:
I'm sorry, but I'm having trouble understanding whether you're asking about copying data between a buffer and a struct, or between two structs. Could you please clarify which scenario you're referring to?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
@nnllyy thanks for your advice, I will try it. |
Hi @nnllyy, I wanted to thank you for your advice. I've implemented the struct with bit-field endian-independent, but I haven't tested it on a big endian machine yet. Would you be able to test it on your machine and provide some feedback? |
My machine is a router and requires cross compilation to run. You can push it and I will test it again |
is that router an OpenWRT on MIPS ? |
The following structures cannot use memcpy
mqtt_msg.h
typedef struct {
uint8_t bit_0 : 1;
uint8_t bit_1 : 1;
uint8_t bit_2 : 1;
uint8_t bit_3 : 1;
uint8_t packet_type : 4;
} mqtt_common_hdr;
typedef struct {
uint8_t retain : 1;
uint8_t qos : 2;
uint8_t dup : 1;
uint8_t packet_type : 4;
} mqtt_pub_hdr;
The text was updated successfully, but these errors were encountered: