Skip to content

Commit

Permalink
lib: introduce struct library
Browse files Browse the repository at this point in the history
Introduce a new "struct" library which is a port of the Python 3.10 struct
module with a reduced set of API functions. It supports the same format
patterns and conversions while providing the following methods:

    struct = require('struct');

    buf = struct.pack("fmt", args...);
    values = struct.unpack("fmt", buf);

    struct_inst = struct.new("fmt");
    buf = struct_inst.pack(args...);
    values = struct_inst.unpack(buf);

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Oct 31, 2021
1 parent c6dae42 commit 402f603
Show file tree
Hide file tree
Showing 2 changed files with 2,595 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Expand Up @@ -20,6 +20,7 @@ OPTION(UCI_SUPPORT "UCI plugin support" ON)
OPTION(RTNL_SUPPORT "Route Netlink plugin support" ON)
OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ON)
OPTION(RESOLV_SUPPORT "NS resolve plugin support" ON)
OPTION(STRUCT_SUPPORT "Struct plugin support" ON)

OPTION(LEGACY_SUPPORT "Support deprecated syntax features" ON)

Expand Down Expand Up @@ -151,6 +152,16 @@ IF(RESOLV_SUPPORT)
ENDIF()
ENDIF()

IF(STRUCT_SUPPORT)
SET(LIBRARIES ${LIBRARIES} struct_lib)
ADD_LIBRARY(struct_lib MODULE lib/struct.c)
SET_TARGET_PROPERTIES(struct_lib PROPERTIES OUTPUT_NAME struct PREFIX "")
CHECK_FUNCTION_EXISTS(frexp FREXP_FUNCTION_EXISTS)
IF (NOT FREXP_FUNCTION_EXISTS)
TARGET_LINK_LIBRARIES(struct_lib m)
ENDIF()
ENDIF()

IF(UNIT_TESTING)
ENABLE_TESTING()
ADD_DEFINITIONS(-DUNIT_TESTING)
Expand Down

0 comments on commit 402f603

Please sign in to comment.