Browse Source

simplfy encoding even more; improve endianness handling

Julius Pfrommer 9 years ago
parent
commit
57bab892af
3 changed files with 359 additions and 412 deletions
  1. 42 34
      include/ua_config.h.in
  2. 303 354
      src/ua_types_encoding_binary.c
  3. 14 24
      src/ua_util.h

+ 42 - 34
include/ua_config.h.in

@@ -1,49 +1,57 @@
 #ifndef UA_CONFIG_H_
 #define UA_CONFIG_H_
 
-/* Build options and configuration (set by cmake) */
-
 #define UA_LOGLEVEL ${UA_LOGLEVEL}
 #cmakedefine UA_MULTITHREADING
 
 /* Function Export */
 #ifdef _WIN32
-#  ifdef UA_DYNAMIC_LINKING
-#    ifdef __GNUC__
-#      define UA_EXPORT __attribute__ ((dllexport))
-#    else
-#      define UA_EXPORT __declspec(dllexport)
-#    endif
+# ifdef UA_DYNAMIC_LINKING
+#  ifdef __GNUC__
+#   define UA_EXPORT __attribute__ ((dllexport))
 #  else
-#    ifdef __GNUC__
-#      define UA_EXPORT __attribute__ ((dllexport))
-#    else
-#      define UA_EXPORT __declspec(dllimport)
-#    endif
+#   define UA_EXPORT __declspec(dllexport)
 #  endif
-#else
-#  if __GNUC__ || __clang__
-#    define UA_EXPORT __attribute__ ((visibility ("default")))
+# else
+#  ifdef __GNUC__
+#   define UA_EXPORT __attribute__ ((dllexport))
 #  else
-#    define UA_EXPORT
+#   define UA_EXPORT __declspec(dllimport)
 #  endif
+# endif
+#else
+# if __GNUC__ || __clang__
+#  define UA_EXPORT __attribute__ ((visibility ("default")))
+# else
+#  define UA_EXPORT
+# endif
+#endif
+
+/* Endianness */
+#if defined(__linux__) || defined(__APPLE__)
+# include <endian.h>
+# if ( __BYTE_ORDER != __LITTLE_ENDIAN )
+#  define UA_NON_LITTLEENDIAN_ARCHITECTURE
+# endif
+#endif
+
+/* Force non-little endian manually by setting the following. */
+// #define UA_NON_LITTLEENDIAN_ARCHITECTURE
+// #define htole16(x) {...}(x)
+// #define htole32(x) {...}(x)
+// #define htole64(x) {...}(x)
+// #define le16toh(x) {...}(x)
+// #define le32toh(x) {...}(x)
+// #define le64toh(x) {...}(x)
+
+/* Mixed Endian */
+#ifdef __ARM_ARCH_4T__
+# define UA_MIXED_ENDIAN
+#endif
+
+/* Aligned Memory Access */
+#if defined(__arm__) && !defined(__ARM_FEATURE_UNALIGNED)
+# define UA_ALIGNED_MEMORY_ACCESS
 #endif
-#ifdef __arm__
-  #ifndef __ARM_FEATURE_UNALIGNED
-    #define UA_ALIGNED_MEMORY_ACCESS
-  #endif /* __ARM_FEATURE_UNALIGNED */
-  #ifdef __ARM_ARCH_4T__
-    #define UA_MIXED_ENDIAN
-  #endif /*__ARM_ARCH_4T__ */
-#endif /*  __arm__ */
-/*	Define your own htoleXX and leXXtoh here if needed.
-	Otherwise the ones defined in endian.h are used		*/
-//	#define htole16(x)	{...}(x)
-//	#define htole32(x)	{...}(x)
-//	#define htole64(x)	{...}(x)
-//	#define le16toh(x)	{...}(x)
-//	#define le32toh(x)	{...}(x)
-//	#define le64toh(x)	{...}(x)
-//  #define UA_NON_LITTLEENDIAN_ARCHITECTURE
 
 #endif /* UA_CONFIG_H_ */

File diff suppressed because it is too large
+ 303 - 354
src/ua_types_encoding_binary.c


+ 14 - 24
src/ua_util.h

@@ -50,34 +50,32 @@
 
 /* Replace the macros with functions for custom allocators if necessary */
 #ifndef UA_free
-    #define UA_free(ptr) free(ptr)
+# define UA_free(ptr) free(ptr)
 #endif
 #ifndef UA_malloc
-    #define UA_malloc(size) malloc(size)
+# define UA_malloc(size) malloc(size)
 #endif
 #ifndef UA_calloc
-    #define UA_calloc(num, size) calloc(num, size)
+# define UA_calloc(num, size) calloc(num, size)
 #endif
 #ifndef UA_realloc
-    #define UA_realloc(ptr, size) realloc(ptr, size)
+# define UA_realloc(ptr, size) realloc(ptr, size)
 #endif
 
 #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
 #define UA_memset(ptr, value, size) memset(ptr, value, size)
 
-#ifdef NO_ALLOCA
-#else
-#ifdef _WIN32
-    # define UA_alloca(SIZE) _alloca(SIZE)
-#else
- #ifdef __GNUC__
-    # define UA_alloca(size) __builtin_alloca (size)
- #else
-    # include <alloca.h>
-    # define UA_alloca(SIZE) alloca(SIZE)
- #endif
+#ifndef NO_ALLOCA
+# ifdef _WIN32
+#  define UA_alloca(SIZE) _alloca(SIZE)
+# endif
+# ifdef __GNUC__
+#  define UA_alloca(size) __builtin_alloca (size)
+# else
+#  include <alloca.h>
+#  define UA_alloca(SIZE) alloca(SIZE)
+# endif
 #endif
-#endif /* NO_ALLOCA */
 
 /********************/
 /* System Libraries */
@@ -96,14 +94,6 @@
 #else
 # include <sys/time.h>
 # define RAND(SEED) (UA_UInt32)rand_r(SEED)
-# ifndef UA_NON_LITTLEENDIAN_ARCHITECTURE
-#  if defined(__linux__) || defined(__APPLE__)
-#   include <endian.h>
-#   if ( __BYTE_ORDER != __LITTLE_ENDIAN )
-#    define UA_NON_LITTLEENDIAN_ARCHITECTURE
-#   endif
-#  endif
-# endif
 #endif
 
 /*************************/