From 42fd73c1184bcec37059d66e5ac39e8342773697 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Oct 2026 01:49:36 +0530 Subject: [PATCH 1/4] docs: audit original PacketForge capture and policy simulation --- PROGRESS.md | 13 +++++++++++++ docs/AUDIT.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 PROGRESS.md create mode 100644 docs/AUDIT.md diff --git a/PROGRESS.md b/PROGRESS.md new file mode 100644 index 0000000..bbd48ad --- /dev/null +++ b/PROGRESS.md @@ -0,0 +1,13 @@ +# PacketForge implementation progress + +- [x] Inspect original files and all Git history; compile both original programs. +- [x] Preserve GitHub history on a feature branch and leave unrelated local copy intact. +- [x] Record initial findings in docs/AUDIT.md. +- [ ] P0: bounded parser, offline libpcap pipeline, Linux capture, CLI, parser tests. +- [ ] P1: bounded flows, configurable IDS, statistics, structured alerts and reports. +- [ ] Reproducible fixtures, integration checks and sanitizer verification. +- [ ] Architecture, protocols, detection, testing and interview documentation. +- [ ] Live capture verification and final delivery evidence. +- [ ] Push tested commits to GitHub. + +No unexecuted tests or live-capture checks are claimed as passing. diff --git a/docs/AUDIT.md b/docs/AUDIT.md new file mode 100644 index 0000000..41aaab6 --- /dev/null +++ b/docs/AUDIT.md @@ -0,0 +1,41 @@ +# PacketForge repository audit + +Audited baseline: `8fd6286f6c3d2e04731b5e49b85b52086ac6f984` on GitHub `main`. +Author: Mayank Kumar Karn. Audit date: 2026-10-21. + +The GitHub repository contains six commits. The latest relocates `forwarder.cpp` +and `rules.hpp` into `src/` and `include/`. A separate pre-existing local copy in +`ctf/PacketForge` has an unborn Git branch and untracked files; it was left untouched. +This work continues the GitHub history on `feature/packetforge-analyzer-ids`. + +## Baseline verification + +Both documented direct compiler builds succeeded with GCC 15.2.0 and +`-std=c++17 -Wall -Wextra`. Original binaries were built in `/tmp`; they were not +run against live traffic during the audit. All six source/documentation files and +`.gitignore` were inspected before editing. No CMake, test suite, configuration +loader, offline reader, reports, or IDS engine exists at baseline. + +| Area | Verified finding | Correction plan | +| --- | --- | --- | +| Ethernet | Direct `EthHeader*` buffer cast, no minimum size check; only Ethernet II assumed | Bounded byte decoding and VLAN tags | +| IPv4 | IHL is calculated (not fixed at 20), but version, minimum IHL, total length, capture boundaries and fragments are unchecked | Validate before reading; distinguish wire/captured lengths | +| TCP/UDP | Unchecked structure casts; TCP offset and UDP length ignored | Explicit network-order reads and transport bounds | +| ARP/ICMP | EtherType/protocol detection only; no ARP addresses or ICMP type/code extraction | Decode supported fields | +| IPv6 | Absent | Bounded base/extension parsing with explicit unsupported cases | +| Capture | Real AF_PACKET socket receives frames; no bind, duration/count controls, signal handler or RAII | Explicit interface, limits, passive socket, graceful shutdown | +| Policy | First-match source/destination/port rules are useful educational logic | Preserve simulation using WOULD_ALLOW / WOULD_BLOCK | +| Enforcement | `forwarder.cpp` never forwards, retransmits or drops anything; README calls it a forwarding engine and labels decisions DROP | Correct code/output/docs; no enforcement | +| Rules | Mutable inline hardcoded table; “configurable” means editing/recompiling C++ | Validated external JSON rules and policy | +| Stats | Total and policy-decision counters only; reporting skipped for non-IPv4 | Shared protocol, flow, rate and alert statistics | +| Build/tests | Two manual g++ commands; no automated checks or PCAP workflow | CMake, CTest, synthetic fixtures, sanitizer builds | +| Privacy | No payload display, injection or persistence | Preserve passive metadata-only behavior | + +## Preservation + +The original implementations remain available at the audited Git commit. +`src/sniffer.cpp` and `src/forwarder.cpp` will become compatibility entry points into +the shared pipeline. `include/headers.hpp` will expose decoded packet types instead +of unsafe on-wire struct layouts. `include/rules.hpp` will preserve first-match +policy evaluation with accurate simulation names. Subsequent implementation and +validation details are recorded in `PROGRESS.md` and `docs/TESTING.md`. From fe625f4c90c5f4b1df5b1dd93d67f63d3e79a181 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Oct 2026 01:55:43 +0530 Subject: [PATCH 2/4] feat: add bounded packet parsing and shared live/offline capture pipeline --- .gitignore | 7 +- CMakeLists.txt | 36 +++++++ PROGRESS.md | 5 + include/headers.hpp | 42 +------- include/packetforge/capture.hpp | 21 ++++ include/packetforge/cli.hpp | 2 + include/packetforge/packet.hpp | 44 ++++++++ samples/arp.pcap | Bin 0 -> 82 bytes samples/big_endian.pcap | Bin 0 -> 94 bytes samples/concentration.pcap | Bin 0 -> 2894 bytes samples/demo.pcap | Bin 0 -> 666 bytes samples/empty.pcap | Bin 0 -> 24 bytes samples/expected.json | 66 ++++++++++++ samples/icmp.pcap | Bin 0 -> 162 bytes samples/icmp_rate.pcap | Bin 0 -> 3543 bytes samples/ipv6.pcap | Bin 0 -> 102 bytes samples/malformed.pcap | Bin 0 -> 135 bytes samples/mixed.pcap | Bin 0 -> 1507 bytes samples/nanosecond.pcap | Bin 0 -> 94 bytes samples/normal_tcp.pcap | Bin 0 -> 304 bytes samples/normal_udp_dns.pcap | Bin 0 -> 175 bytes samples/out_of_order.pcap | Bin 0 -> 164 bytes samples/portscan.pcap | Bin 0 -> 934 bytes samples/sensitive.pcap | Bin 0 -> 94 bytes samples/synrate.pcap | Bin 0 -> 7094 bytes samples/unsupported_link.pcap | Bin 0 -> 94 bytes scripts/generate_fixtures.py | 101 ++++++++++++++++++ src/capture/live.cpp | 116 +++++++++++++++++++++ src/capture/pcap.cpp | 43 ++++++++ src/cli.cpp | 63 ++++++++++++ src/forwarder.cpp | 91 +--------------- src/main.cpp | 2 + src/parsers/packet.cpp | 177 ++++++++++++++++++++++++++++++++ src/sniffer.cpp | 88 +--------------- tests/integration.py | 14 +++ tests/unit.cpp | 36 +++++++ 36 files changed, 741 insertions(+), 213 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 include/packetforge/capture.hpp create mode 100644 include/packetforge/cli.hpp create mode 100644 include/packetforge/packet.hpp create mode 100644 samples/arp.pcap create mode 100644 samples/big_endian.pcap create mode 100644 samples/concentration.pcap create mode 100644 samples/demo.pcap create mode 100644 samples/empty.pcap create mode 100644 samples/expected.json create mode 100644 samples/icmp.pcap create mode 100644 samples/icmp_rate.pcap create mode 100644 samples/ipv6.pcap create mode 100644 samples/malformed.pcap create mode 100644 samples/mixed.pcap create mode 100644 samples/nanosecond.pcap create mode 100644 samples/normal_tcp.pcap create mode 100644 samples/normal_udp_dns.pcap create mode 100644 samples/out_of_order.pcap create mode 100644 samples/portscan.pcap create mode 100644 samples/sensitive.pcap create mode 100644 samples/synrate.pcap create mode 100644 samples/unsupported_link.pcap create mode 100644 scripts/generate_fixtures.py create mode 100644 src/capture/live.cpp create mode 100644 src/capture/pcap.cpp create mode 100644 src/cli.cpp create mode 100644 src/main.cpp create mode 100644 src/parsers/packet.cpp create mode 100644 tests/integration.py create mode 100644 tests/unit.cpp diff --git a/.gitignore b/.gitignore index 2123540..764dee9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +/build*/ +/reports/ *.o *.out -sniffer +/sniffer +/forwarder +/packetforge +__pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..728de88 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.16) +project(PacketForge LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +option(PACKETFORGE_SANITIZERS "Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF) +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") + message(FATAL_ERROR "PacketForge currently targets Linux, including WSL2") +endif() +find_path(PCAP_INCLUDE_DIR pcap/pcap.h REQUIRED) +find_library(PCAP_LIBRARY pcap REQUIRED) +add_library(packetforge_core src/parsers/packet.cpp src/capture/pcap.cpp src/capture/live.cpp) +target_include_directories(packetforge_core PUBLIC include) +target_include_directories(packetforge_core SYSTEM PUBLIC third_party ${PCAP_INCLUDE_DIR}) +target_link_libraries(packetforge_core PUBLIC ${PCAP_LIBRARY}) +target_compile_options(packetforge_core PUBLIC -Wall -Wextra -Wpedantic -Wconversion -Wshadow) +if(PACKETFORGE_SANITIZERS) + target_compile_options(packetforge_core PUBLIC -fsanitize=address,undefined -fno-omit-frame-pointer) + target_link_options(packetforge_core PUBLIC -fsanitize=address,undefined) +endif() +add_executable(packetforge src/main.cpp src/cli.cpp) +target_link_libraries(packetforge PRIVATE packetforge_core) +add_executable(sniffer src/sniffer.cpp src/cli.cpp) +target_link_libraries(sniffer PRIVATE packetforge_core) +add_executable(forwarder src/forwarder.cpp src/cli.cpp) +target_link_libraries(forwarder PRIVATE packetforge_core) +include(CTest) +if(BUILD_TESTING) + add_executable(packetforge_tests tests/unit.cpp) + target_link_libraries(packetforge_tests PRIVATE packetforge_core) + add_test(NAME unit COMMAND packetforge_tests) + find_package(Python3 COMPONENTS Interpreter REQUIRED) + add_test(NAME integration COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/integration.py $ ${CMAKE_SOURCE_DIR}) +endif() +install(TARGETS packetforge RUNTIME DESTINATION bin) +install(FILES config/rules.json DESTINATION share/packetforge) diff --git a/PROGRESS.md b/PROGRESS.md index bbd48ad..9f69ddc 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -11,3 +11,8 @@ - [ ] Push tested commits to GitHub. No unexecuted tests or live-capture checks are claimed as passing. + +Parser/capture stage: C++17 library, bounded Ethernet/VLAN/ARP/IPv4/IPv6/TCP/UDP/ICMP +parser, AF_PACKET capture and libpcap classic-PCAP reader implemented. Initial +parser tests pass. Interface listing passes on the host; the restricted execution +sandbox blocks network-interface enumeration. Deterministic fixtures added. diff --git a/include/headers.hpp b/include/headers.hpp index 279faa5..61a398f 100644 --- a/include/headers.hpp +++ b/include/headers.hpp @@ -1,40 +1,4 @@ #pragma once -#include - -struct EthHeader { - uint8_t dst_mac[6]; - uint8_t src_mac[6]; - uint16_t ethertype; -}; - -struct IPHeader { - uint8_t ver_ihl; - uint8_t tos; - uint16_t total_len; - uint16_t id; - uint16_t flags_fo; - uint8_t ttl; - uint8_t protocol; - uint16_t checksum; - uint32_t src_ip; - uint32_t dst_ip; -}; - -struct TCPHeader { - uint16_t src_port; - uint16_t dst_port; - uint32_t seq; - uint32_t ack; - uint8_t data_offset; - uint8_t flags; - uint16_t window; - uint16_t checksum; - uint16_t urgent_ptr; -}; - -struct UDPHeader { - uint16_t src_port; - uint16_t dst_port; - uint16_t length; - uint16_t checksum; -}; +// Compatibility include. PacketForge now decodes bounded bytes into host-order values. +// The original on-wire struct layouts remain in Git history at 8fd6286. +#include "packetforge/packet.hpp" diff --git a/include/packetforge/capture.hpp b/include/packetforge/capture.hpp new file mode 100644 index 0000000..4103958 --- /dev/null +++ b/include/packetforge/capture.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "packet.hpp" +#include +#include +namespace packetforge { +using PacketConsumer = std::function; +struct CaptureOptions { + std::string interface; + std::uint64_t count = 0; + double duration = 0; + bool promiscuous = false; +}; +struct CaptureResult { + std::uint64_t packets = 0, kernel_drops = 0; + bool interrupted = false; +}; +void list_interfaces(); +CaptureResult analyze_pcap(const std::string& path, const PacketConsumer& consume, std::uint64_t limit = 0); +CaptureResult capture_live(const CaptureOptions& options, const PacketConsumer& consume, + const std::function& tick = {}); +} diff --git a/include/packetforge/cli.hpp b/include/packetforge/cli.hpp new file mode 100644 index 0000000..b5f6bde --- /dev/null +++ b/include/packetforge/cli.hpp @@ -0,0 +1,2 @@ +#pragma once +namespace packetforge { int run_cli(int argc, char** argv, bool legacy_capture = false, bool policy = false); } diff --git a/include/packetforge/packet.hpp b/include/packetforge/packet.hpp new file mode 100644 index 0000000..eb0b978 --- /dev/null +++ b/include/packetforge/packet.hpp @@ -0,0 +1,44 @@ +#pragma once +#include +#include +#include +#include + +namespace packetforge { +using Timestamp = std::int64_t; // Unix nanoseconds; PCAP timestamps drive offline windows. +constexpr Timestamp second = 1000000000LL; +enum class ParseStatus { ok, truncated, malformed, unsupported }; +const char* status_name(ParseStatus status); + +// Decoded host-order values, never overlays of an untrusted network buffer. +struct Packet { + Timestamp timestamp = 0; + std::uint32_t captured_length = 0, wire_length = 0; + ParseStatus status = ParseStatus::ok; + std::string detail; + bool capture_truncated = false, ethernet = false, arp = false; + bool ipv4 = false, ipv6 = false, transport = false, fragmented = false; + std::string source_mac, destination_mac, source, destination; + std::uint16_t ethertype = 0; + std::vector vlan_ids; + std::uint8_t version = 0, ip_header_length = 0, ttl = 0, protocol = 0, next_header = 0; + std::uint16_t ip_total_length = 0, ipv6_payload_length = 0; + std::uint16_t fragment_offset = 0, ip_id = 0; + std::uint32_t ipv6_fragment_id = 0; + bool more_fragments = false, dont_fragment = false; + std::uint16_t source_port = 0, destination_port = 0; + std::uint32_t sequence = 0, acknowledgment = 0; + std::uint8_t tcp_header_length = 0, tcp_flags = 0; + std::uint16_t tcp_window = 0, udp_length = 0; + std::uint8_t icmp_type = 0, icmp_code = 0; + bool echo_request = false, echo_reply = false; + std::uint16_t arp_opcode = 0; + std::string arp_sender_hardware, arp_target_hardware; + bool syn_attempt() const { return transport && protocol == 6 && (tcp_flags & 0x02) && !(tcp_flags & 0x15); } + std::string protocol_name() const; +}; +Packet parse_packet(const std::uint8_t* bytes, std::size_t captured, + std::uint32_t wire_length, Timestamp timestamp); +std::string iso_time(Timestamp timestamp); +Timestamp now_timestamp(); +} diff --git a/samples/arp.pcap b/samples/arp.pcap new file mode 100644 index 0000000000000000000000000000000000000000..c94affee88ae4262942c362ac782b4bc64beb621 GIT binary patch literal 82 zcmca|c+)~A1{MYcU}0bcaXtp8f+#I0W&&}Tz$7CF8v`Q;0~=5wgnxj6i3=pnzyM^4 F003@%2EhOT literal 0 HcmV?d00001 diff --git a/samples/big_endian.pcap b/samples/big_endian.pcap new file mode 100644 index 0000000000000000000000000000000000000000..422089bbff49b43e88b1e1fced9a809e8fda327d GIT binary patch literal 94 zcmZ3u>F^Z>CI%J;7=W-CQ-eRkM9hE;GbRv^2~09_Ft{=>XfQA`FgURF)gEAA;yPxW YA~MH;aW_y6P?Uiofa(8#)hP@N06Pf{xBvhE literal 0 HcmV?d00001 diff --git a/samples/concentration.pcap b/samples/concentration.pcap new file mode 100644 index 0000000000000000000000000000000000000000..59f42e14dcd63dc3fb77bb38150c7231db575b52 GIT binary patch literal 2894 zcmb8xw@U+Y7{>8m&e&qX!O6)*bQDDA*t^EwHEJw_z1J9f?~V@1KOo}j5(qduxC-tr zy1D7aM-ZOvIk-Ds_}zzh`f@Lkhmd8Q=KpdUM|AjX8j8LO{%$KeSiet4f+;m7Cwj~s zceWljmg_0cmwxMZJlbb|KlWJP-&r^IWGkMCq!f~J4JEkePBxMDP*xfEtmZ6B4)qphzF#Z3pIt9oBni6oB7*jwdfJ|cCJ;woViV)D07KkYe+8D`oivZA+Hi#)7 zJekNfMG$C8E5sBBUS<4E`ogtuy9!-z+lRt22{!j3>t9gFfg#ERwU*Y zWOLHQ@p?gBDOB2&0(G#sCa+Hekd+!XIQZPzewKSt1~v4<@q!Enxs- z6rG@$QU|+;v9B5CA`XTFPeFDDBqnF4mbm2?rKf@nF$iZR!4L+96W9!CkYZ!71G)r+ hkzLYuHvuTZz+vT}z{tA;#DoGyG(J-UgNhr-bpY71Wd8sF literal 0 HcmV?d00001 diff --git a/samples/empty.pcap b/samples/empty.pcap new file mode 100644 index 0000000000000000000000000000000000000000..4f9600e90a64e3ed9c747268f5dcbdc29ad1a596 GIT binary patch literal 24 Vcmca|c+)~A1{MYcU}0bcasWb#0`>p^ literal 0 HcmV?d00001 diff --git a/samples/expected.json b/samples/expected.json new file mode 100644 index 0000000..4713b9b --- /dev/null +++ b/samples/expected.json @@ -0,0 +1,66 @@ +{ + "normal_tcp.pcap": { + "packets": 4, + "alerts": [] + }, + "normal_udp_dns.pcap": { + "packets": 2, + "alerts": [] + }, + "arp.pcap": { + "packets": 1, + "alerts": [] + }, + "icmp.pcap": { + "packets": 2, + "alerts": [] + }, + "portscan.pcap": { + "packets": 13, + "alerts": [ + "POSSIBLE_TCP_PORT_SCAN" + ] + }, + "synrate.pcap": { + "packets": 101, + "alerts": [ + "HIGH_TCP_SYN_RATE" + ] + }, + "icmp_rate.pcap": { + "packets": 51, + "alerts": [ + "HIGH_ICMP_ECHO_RATE" + ] + }, + "concentration.pcap": { + "packets": 41, + "alerts": [ + "CONNECTION_CONCENTRATION" + ] + }, + "sensitive.pcap": { + "packets": 1, + "alerts": [ + "SENSITIVE_SERVICE_TRAFFIC" + ] + }, + "ipv6.pcap": { + "packets": 1, + "alerts": [] + }, + "demo.pcap": { + "packets": 9, + "alerts": [] + }, + "malformed.pcap": { + "packets": 2, + "alerts": [] + }, + "mixed.pcap": { + "packets": 21, + "alerts": [ + "POSSIBLE_TCP_PORT_SCAN" + ] + } +} diff --git a/samples/icmp.pcap b/samples/icmp.pcap new file mode 100644 index 0000000000000000000000000000000000000000..a5490ff73043b158107be414a504445fea5ccd47 GIT binary patch literal 162 zcmca|c+)~A1{MYcU}0bcaXtp8f+$lcW&&}Tz$7CFgDV4rI!KuVV_)+D1}3g!#wj8k i3 literal 0 HcmV?d00001 diff --git a/samples/icmp_rate.pcap b/samples/icmp_rate.pcap new file mode 100644 index 0000000000000000000000000000000000000000..45cd0ed7dfaf0e96b074dcfc7a4a6aa16a1c3c49 GIT binary patch literal 3543 zcmb`}ElUJJ9Dwne@znM7#9%Vnt_pJfih^yyVD<18gTWWfA_zti`~r7hK*VZUI51zZ z3Ko;)Y({7qwMXUQYwR|aJ8)bf)|E|wh< zb2Ju2Hx@)U7DP7|L^l>hHx@)U7DP7|L^l>hHx@)U7DP7|L^l>hHx@)U7DP7|L^l>h zHx@)U7DP8T@lU2_SkAKlI>&$x literal 0 HcmV?d00001 diff --git a/samples/ipv6.pcap b/samples/ipv6.pcap new file mode 100644 index 0000000000000000000000000000000000000000..217ee311eedf2e0029c512693c15ddf6c79ed3db GIT binary patch literal 102 zcmca|c+)~A1{MYcU}0bcaXtp8f+#yEW&&}Tz$9ba-2@Pi!^%N{k#`4(2?dO3e5M8l J6*r)9i~w=T3L*di literal 0 HcmV?d00001 diff --git a/samples/malformed.pcap b/samples/malformed.pcap new file mode 100644 index 0000000000000000000000000000000000000000..ad2ec6a48def14b10afcb54e734752da334b1932 GIT binary patch literal 135 zcmca|c+)~A1{MYcU}0bcaXtp8f+$HKHUnZN5Qhm&GIB7uGB9X>lsT~VffO!iV+1S0 jROo_GSbKnhiR+kgipU%X#@#@}z_tW1{r|5zg@FM8IC2sv literal 0 HcmV?d00001 diff --git a/samples/mixed.pcap b/samples/mixed.pcap new file mode 100644 index 0000000000000000000000000000000000000000..b4eb6c9ecce65f43f701899472cf3937a523f3be GIT binary patch literal 1507 zcmbW$y-UMD7zXh7l91M7p_NWf1wSgTQil$b#o}0S^eeHA9aI$U;35>%j#+fy4Uy3HPu%gdJSB27w&!>4^OWy&T1MM@ckGdXwjT?={4CN8Z9*c zSA=02V2rj|rnlPwEpjiKB8LmGYno<2a?kaxnq3F)=`y6Ws>4;DfUSWs$6fU z<0l&TY&u7IoWvjvqqtRIsD7>hA$P}F-&}KzlDl1^uY%l0st>ne~d`@xiX{1^7p K-A|^>0ek_wB<&CY literal 0 HcmV?d00001 diff --git a/samples/nanosecond.pcap b/samples/nanosecond.pcap new file mode 100644 index 0000000000000000000000000000000000000000..4d9ee40ec497d4e309b58b1e6d1f210cf9498d25 GIT binary patch literal 94 zcmeaZ*|d;}frSA9SQr>VoR7h&qGzMo&45f0W&(*Zfk{RV23H0K4UjSiw!Yc}3`|_d Yj8jDBI56%8ssU>bVEX@GbqWIm04u%??f?J) literal 0 HcmV?d00001 diff --git a/samples/normal_tcp.pcap b/samples/normal_tcp.pcap new file mode 100644 index 0000000000000000000000000000000000000000..65074f9971565b7d323d77d18faf31394534bd31 GIT binary patch literal 304 zcmca|c+)~A1{MYcU}0bcaXtp8f+#a6W&&}Tz$7CFgDV4r21uC$TVL$~1}3g!#wj9m z92j>4)qphzF#Z3pIt9oBni6oB7*jwdfJ|cCJ;woViV)D07KkYe+8D`oivZA+Hi#)7 PJekNfMG$C8D+2=no*OZ9 literal 0 HcmV?d00001 diff --git a/samples/normal_udp_dns.pcap b/samples/normal_udp_dns.pcap new file mode 100644 index 0000000000000000000000000000000000000000..6249f6fc424f7e66524bcb43809a036cfd9238f7 GIT binary patch literal 175 zcmca|c+)~A1{MYcU}0bcaXtp8f+&3`W&&}Tz$7CFgDV4rB1oBoU|;0{1}3g!#wj98 z1Vmmk@G>xDq~_%0gR}=6W?=9D>H=X5?N(6j2?*^BrVMI8rHnvx!7gB6U{9?`%q_@C NWhqH5E&+)$0sw!z8TqM14s3n32N;;Rjv1$j Z%yD4c4O9ct%n-oz|G(-KAcHEV001Zv7<&K! literal 0 HcmV?d00001 diff --git a/samples/portscan.pcap b/samples/portscan.pcap new file mode 100644 index 0000000000000000000000000000000000000000..38ecbfaeb97bab8afbba1130d6de76e2dd7b8faa GIT binary patch literal 934 zcmca|c+)~A1{MYcU}0bcaXtp8f+#a6W&&}Tz$7CFgDV4r21uC$TVL$~1}3g!#wj9m z9GG7K)qphzF#Z3poDSpxO$j(mqA4#?Oi6>7vY?HTG`GA$F$Lropj$q8GLdG=YZOyb zAf`C*GLvS?8x&KLA*M{YK%yycQA|mKnDSsU3u$h7hhj=1#1w;YR?Q=F>c+Ekhpf? z*2KLV+_}^DopW>C`khGzn1p$9r~U4G;al&g?qrl5{kvpG3BU2H?zn%OAFfHik<5He zx%587%iIRn1<}{SPPbEJ4FZm^%{PU;co&8`+x>ry#OUNj1p>(w+;;$vM z+>Fu*rLQ&_U&*rj;t{=pk}A%MuVkL$%vxSU>G&!rIb2Hzlpmeh@z;_|Nl8ARm) zl)je!@s+_;?nhBV?QSWRdr+kA4x!QtMe6QQDtDns-5o}y1&Y+&;Z&NTNZlPlvL*+UYsk>vTT!SKYx17pVC{lOFQMm#| z>h5?dm!U}Aoj~Oh6sfxtsWd^6x?4e|5sK8^NmMREk-A$+<${g2YIm!soQEQHcQTc8 zP^9iop>h_A)ZM96&Onj6JB`X|C{lN)Q#l1i>h26GC!t8)ok`^c6sfz_RE|TDx;u+X z0~D#dv#A_|B6W8Tm7`Fk?#`uh1d7z%c~t75NZs{AFHU@ip-A0bK;;k=sk;lQ9E2iu zcM+8XP^9iIrm`Q3)ZHai_C-;a+TEp8_Ck@myNt>nC{lNqQ`rqg>h20EyP!zjO;Oni zMe6QKDm$P^-Caec4vN&>)l{}ak-EEv$~GuccWbDmp-A0bOJyq*sk`f_Y=I(mcRiKO zP^9kGQrQGW>h1x$G}+v9^``@SnucWvGX zip?OdNZqyBCnz=#xgvGf=CGjHZ03s8U7HDmVsoM^Qg>}W4T{aIu1MXrSve>+Kf5B$ zyY*CTmUl(!uAL#mTI^imiqu^@&jiKJIIc+DwX;=F?7WrZ&x>9Bh~d|y-}s;ZtJyg( ID0cSy3oaq0r~m)} literal 0 HcmV?d00001 diff --git a/samples/unsupported_link.pcap b/samples/unsupported_link.pcap new file mode 100644 index 0000000000000000000000000000000000000000..1efc98f8131dd3b16eaa0e629301263ff061a088 GIT binary patch literal 94 zcmca|c+)~A1{MYcU|~oFaXtovDKj7wgqc8MOkk3cgTa-7L4$#jfx&^Tul4`~6W1~0 Z6p=X&jJttqfT9cx0Zjk@t4?8H003E24jcdg literal 0 HcmV?d00001 diff --git a/scripts/generate_fixtures.py b/scripts/generate_fixtures.py new file mode 100644 index 0000000..56fd469 --- /dev/null +++ b/scripts/generate_fixtures.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +"""Deterministic, synthetic classic PCAPs. Python standard library only; no traffic sent.""" +import ipaddress +import json +from pathlib import Path +import struct + +ROOT = Path(__file__).resolve().parents[1] +BASE = 1700000000 + +def checksum(data): + if len(data) % 2: + data += b'\0' + value = sum(struct.unpack('!%dH' % (len(data)//2), data)) + while value >> 16: + value = (value & 65535) + (value >> 16) + return (~value) & 65535 + +def ethernet(payload, kind=0x0800, vlan=None): + macs = bytes.fromhex('020000000002020000000001') + if vlan is not None: + return macs + struct.pack('!HHH', 0x8100, vlan, kind) + payload + return macs + struct.pack('!H', kind) + payload + +def ipv4(payload, proto=6, src='192.0.2.10', dst='198.51.100.20', flags=0, options=b''): + source, destination = ipaddress.ip_address(src).packed, ipaddress.ip_address(dst).packed + header = struct.pack('!BBHHHBBH4s4s', 0x45 + len(options)//4, 0, 20+len(options)+len(payload), 1, flags, 64, proto, 0, source, destination) + options + header = header[:10] + struct.pack('!H', checksum(header)) + header[12:] + return header + payload + +def tcp(port=443, sport=40000, flags=2, seq=1, src='192.0.2.10', dst='198.51.100.20'): + segment = struct.pack('!HHIIBBHHH', sport, port, seq, 0, 0x50, flags, 65535, 0, 0) + pseudo = ipaddress.ip_address(src).packed + ipaddress.ip_address(dst).packed + struct.pack('!BBH',0,6,len(segment)) + segment = segment[:16] + struct.pack('!H',checksum(pseudo+segment)) + segment[18:] + return ethernet(ipv4(segment,src=src,dst=dst)) + +def udp(payload=b'hello', port=5353): + # A zero UDP checksum is legal for IPv4. + segment=struct.pack('!HHHH',42000,port,len(payload)+8,0)+payload + return ethernet(ipv4(segment,17)) + +def icmp(reply=False): + body=struct.pack('!BBHHH',0 if reply else 8,0,0,1,1)+b'PacketForge' + body=body[:2]+struct.pack('!H',checksum(body))+body[4:] + return ethernet(ipv4(body,1)) + +def arp(): + body=struct.pack('!HHBBH',1,0x0800,6,4,1)+bytes.fromhex('020000000001')+ipaddress.ip_address('192.0.2.10').packed + body+=bytes(6)+ipaddress.ip_address('192.0.2.20').packed + return ethernet(body,0x0806) + +def ipv6(): + src=ipaddress.ip_address('2001:db8::1').packed; dst=ipaddress.ip_address('2001:db8::2').packed + body=struct.pack('!BBHHH',128,0,0,1,1) + pseudo=src+dst+struct.pack('!I3xB',len(body),58) + body=body[:2]+struct.pack('!H',checksum(pseudo+body))+body[4:] + return ethernet(struct.pack('!IHBB',6<<28,len(body),58,64)+src+dst+body,0x86dd) + +def write(name, packets, endian='<', nano=False, linktype=1): + path=ROOT/'samples'/name + with path.open('wb') as output: + output.write(struct.pack(endian+'IHHIIII',0xa1b23c4d if nano else 0xa1b2c3d4,2,4,0,0,262144,linktype)) + for i,entry in enumerate(packets): + packet, wire, offset = entry if isinstance(entry,tuple) else (entry,len(entry),i*100_000_000) + seconds, nanos=divmod(offset,1_000_000_000) + output.write(struct.pack(endian+'IIII',BASE+seconds,nanos if nano else nanos//1000,len(packet),wire)) + output.write(packet) + +def generate(): + (ROOT/'samples').mkdir(exist_ok=True) + normal=[tcp(),tcp(40000,443,0x12,src='198.51.100.20',dst='192.0.2.10'),tcp(flags=0x10),tcp(flags=0x11)] + dns=struct.pack('!HHHHHH',1,0x0100,1,0,0,0)+b'\x07example\x04test\0'+struct.pack('!HH',1,1) + cases={'normal_tcp.pcap':normal,'normal_udp_dns.pcap':[udp(),udp(dns,53)],'arp.pcap':[arp()], + 'icmp.pcap':[icmp(),icmp(True)],'portscan.pcap':[tcp(port=1000+i) for i in range(13)], + 'synrate.pcap':[tcp(seq=i) for i in range(101)],'icmp_rate.pcap':[icmp() for _ in range(51)], + 'concentration.pcap':[tcp(sport=40000+i) for i in range(41)],'sensitive.pcap':[tcp(port=22)], + 'ipv6.pcap':[ipv6()], 'demo.pcap':normal+[udp(dns,53),arp(),icmp(),icmp(True),ipv6()]} + # Keep all rate scenarios inside the 10-second demonstration window. + for name,packets in cases.items(): + write(name,[(p,len(p),i*50_000_000) for i,p in enumerate(packets)]) + bad=bytearray(tcp());bad[14]=0x44 + cases['malformed.pcap']=[(tcp()[:25],54,0),(bytes(bad),54,100_000_000)] + write('malformed.pcap',cases['malformed.pcap']) + write('mixed.pcap',normal+[arp(),udp(dns,53),icmp(),ipv6()]+[tcp(port=1000+i) for i in range(13)]) + write('nanosecond.pcap',[(tcp(),54,123456789)],nano=True) + write('big_endian.pcap',[tcp()],endian='>') + write('out_of_order.pcap',[(tcp(),54,1_000_000_000),(tcp(),54,0)]) + write('unsupported_link.pcap',[tcp()],linktype=101) + write('empty.pcap',[]) + expected={name:{'packets':len(packets),'alerts':[]} for name,packets in cases.items()} + expected['portscan.pcap']['alerts']=['POSSIBLE_TCP_PORT_SCAN'] + expected['synrate.pcap']['alerts']=['HIGH_TCP_SYN_RATE'] + expected['icmp_rate.pcap']['alerts']=['HIGH_ICMP_ECHO_RATE'] + expected['concentration.pcap']['alerts']=['CONNECTION_CONCENTRATION'] + expected['sensitive.pcap']['alerts']=['SENSITIVE_SERVICE_TRAFFIC'] + expected['mixed.pcap']={'packets':21,'alerts':['POSSIBLE_TCP_PORT_SCAN']} + (ROOT/'samples'/'expected.json').write_text(json.dumps(expected,indent=2)+'\n') + print(f'Generated synthetic PCAPs in {ROOT / "samples"}') + +if __name__=='__main__': + generate() diff --git a/src/capture/live.cpp b/src/capture/live.cpp new file mode 100644 index 0000000..b96c66c --- /dev/null +++ b/src/capture/live.cpp @@ -0,0 +1,116 @@ +#include "packetforge/capture.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace packetforge { +namespace { +volatile std::sig_atomic_t stopped = 0; +void stop(int) { stopped = 1; } +class Socket { + int fd_; +public: + explicit Socket(int fd) : fd_(fd) {} + ~Socket() { if (fd_ >= 0) ::close(fd_); } + Socket(const Socket&) = delete; Socket& operator=(const Socket&) = delete; + int get() const { return fd_; } +}; +struct Signals { + struct sigaction old_int{}, old_term{}; + Signals() { + stopped = 0; struct sigaction action{}; action.sa_handler = stop; sigemptyset(&action.sa_mask); + if (sigaction(SIGINT, &action, &old_int) < 0) throw std::runtime_error("cannot install SIGINT handler"); + if (sigaction(SIGTERM, &action, &old_term) < 0) { + sigaction(SIGINT, &old_int, nullptr); throw std::runtime_error("cannot install SIGTERM handler"); + } + } + ~Signals() { sigaction(SIGINT, &old_int, nullptr); sigaction(SIGTERM, &old_term, nullptr); } +}; +void check(int rc, const char* message) { if (rc < 0) throw std::runtime_error(std::string(message)+": "+std::strerror(errno)); } +} +void list_interfaces() { + struct if_nameindex* interfaces = if_nameindex(); + if (!interfaces) throw std::runtime_error("could not enumerate interfaces"); + std::cout << "PacketForge | available capture interfaces\n"; + for (auto* i = interfaces; i->if_index; ++i) std::cout << i->if_index << "\t" << i->if_name << '\n'; + if_freenameindex(interfaces); +} +CaptureResult capture_live(const CaptureOptions& options, const PacketConsumer& consume, const std::function& tick) { + const auto index = if_nametoindex(options.interface.c_str()); + if (!index) throw std::runtime_error("unknown interface: " + options.interface + "; use packetforge interfaces"); + Socket socket(::socket(AF_PACKET, SOCK_RAW | SOCK_CLOEXEC, htons(ETH_P_ALL))); + if (socket.get() < 0) throw std::runtime_error(std::string("AF_PACKET capture: ") + std::strerror(errno) + + ". Live capture requires CAP_NET_RAW (or sudo) on an authorized Linux interface; offline analysis needs neither."); + ifreq request{}; std::strncpy(request.ifr_name, options.interface.c_str(), IFNAMSIZ-1); + check(ioctl(socket.get(), SIOCGIFHWADDR, &request), "interface hardware type"); + if (request.ifr_hwaddr.sa_family != ARPHRD_ETHER && request.ifr_hwaddr.sa_family != ARPHRD_LOOPBACK) + throw std::runtime_error("capture requires Ethernet or Linux loopback link framing"); + sockaddr_ll address{}; address.sll_family = AF_PACKET; address.sll_protocol = htons(ETH_P_ALL); + address.sll_ifindex = static_cast(index); + check(bind(socket.get(), reinterpret_cast(&address), sizeof(address)), "bind interface"); + int enabled = 1; + check(setsockopt(socket.get(), SOL_PACKET, PACKET_AUXDATA, &enabled, sizeof(enabled)), "PACKET_AUXDATA"); + check(setsockopt(socket.get(), SOL_SOCKET, SO_TIMESTAMPNS, &enabled, sizeof(enabled)), "SO_TIMESTAMPNS"); + if (options.promiscuous) { + packet_mreq membership{}; membership.mr_ifindex = static_cast(index); membership.mr_type = PACKET_MR_PROMISC; + check(setsockopt(socket.get(), SOL_PACKET, PACKET_ADD_MEMBERSHIP, &membership, sizeof(membership)), "promiscuous membership"); + } + Signals signals; CaptureResult result; + std::array buffer{}; + const auto begin = std::chrono::steady_clock::now(); auto last_tick = begin; + Timestamp last_timestamp = 0; + while (!stopped && (!options.count || result.packets < options.count)) { + const auto now = std::chrono::steady_clock::now(); + if (options.duration > 0 && std::chrono::duration(now-begin).count() >= options.duration) break; + if (tick && now-last_tick >= std::chrono::seconds(1)) { tick(); last_tick = now; } + pollfd poller{socket.get(), POLLIN, 0}; const int ready = poll(&poller, 1, 100); + if (ready < 0 && errno == EINTR) continue; + check(ready, "capture poll"); if (!ready) continue; + if (poller.revents & (POLLERR | POLLHUP | POLLNVAL)) throw std::runtime_error("capture socket disconnected"); + iovec iov{buffer.data(), buffer.size()-4}; + alignas(cmsghdr) std::array control{}; + msghdr message{}; message.msg_iov = &iov; message.msg_iovlen = 1; + message.msg_control = control.data(); message.msg_controllen = control.size(); + const auto received = recvmsg(socket.get(), &message, MSG_TRUNC); + if (received < 0 && errno == EINTR) continue; + if (received < 0) check(-1, "recvmsg"); + auto wire = static_cast(received); + auto captured = std::min(static_cast(received), iov.iov_len); + Timestamp timestamp = now_timestamp(); + for (auto* c = CMSG_FIRSTHDR(&message); c; c = CMSG_NXTHDR(&message,c)) { + if (c->cmsg_level == SOL_SOCKET && c->cmsg_type == SO_TIMESTAMPNS && c->cmsg_len >= CMSG_LEN(sizeof(timespec))) { + timespec ts{}; std::memcpy(&ts, CMSG_DATA(c), sizeof(ts)); timestamp = ts.tv_sec*second + ts.tv_nsec; + } + if (c->cmsg_level == SOL_PACKET && c->cmsg_type == PACKET_AUXDATA && c->cmsg_len >= CMSG_LEN(sizeof(tpacket_auxdata))) { + tpacket_auxdata aux{}; std::memcpy(&aux, CMSG_DATA(c), sizeof(aux)); + if ((aux.tp_status & TP_STATUS_VLAN_VALID) && captured >= 14) { + std::memmove(buffer.data()+16, buffer.data()+12, captured-12); + const std::uint16_t tpid = (aux.tp_status & TP_STATUS_VLAN_TPID_VALID) ? aux.tp_vlan_tpid : 0x8100; + buffer[12] = static_cast(tpid >> 8); buffer[13] = static_cast(tpid); + buffer[14] = static_cast(aux.tp_vlan_tci >> 8); buffer[15] = static_cast(aux.tp_vlan_tci); + captured += 4; wire += 4; + } + } + } + // A wall-clock correction must not run sliding windows backwards. + timestamp = std::max(timestamp, last_timestamp); last_timestamp = timestamp; + consume(parse_packet(buffer.data(), captured, wire, timestamp)); ++result.packets; + } + tpacket_stats stats{}; socklen_t length = sizeof(stats); + if (getsockopt(socket.get(), SOL_PACKET, PACKET_STATISTICS, &stats, &length) == 0) result.kernel_drops = stats.tp_drops; + result.interrupted = stopped != 0; return result; +} +} diff --git a/src/capture/pcap.cpp b/src/capture/pcap.cpp new file mode 100644 index 0000000..cb8e305 --- /dev/null +++ b/src/capture/pcap.cpp @@ -0,0 +1,43 @@ +#include "packetforge/capture.hpp" +#include +#include +#include +#include +#include +#include +#include +namespace packetforge { +CaptureResult analyze_pcap(const std::string& path, const PacketConsumer& consume, std::uint64_t limit) { + // Deliberately support classic PCAP only, despite libpcap accepting some PCAPNG files. + std::ifstream input(path, std::ios::binary); std::array magic{}; + if (!input.read(reinterpret_cast(magic.data()), 4)) throw std::runtime_error("cannot read PCAP header: " + path); + const bool classic = magic == std::array{0xd4,0xc3,0xb2,0xa1} + || magic == std::array{0xa1,0xb2,0xc3,0xd4} + || magic == std::array{0x4d,0x3c,0xb2,0xa1} + || magic == std::array{0xa1,0xb2,0x3c,0x4d}; + if (!classic) throw std::runtime_error("only standard PCAP is supported; PCAPNG is not supported"); + char error[PCAP_ERRBUF_SIZE]{}; + std::unique_ptr handle( + pcap_open_offline_with_tstamp_precision(path.c_str(), PCAP_TSTAMP_PRECISION_NANO, error), pcap_close); + if (!handle) throw std::runtime_error(std::string("PCAP: ") + error); + if (pcap_datalink(handle.get()) != DLT_EN10MB) throw std::runtime_error("unsupported PCAP link type; Ethernet (DLT_EN10MB) required"); + CaptureResult result; Timestamp previous = -1; + while (!limit || result.packets < limit) { + pcap_pkthdr* header = nullptr; const u_char* bytes = nullptr; + const int status = pcap_next_ex(handle.get(), &header, &bytes); + if (status == -2) break; + if (status == -1) throw std::runtime_error(std::string("PCAP read error: ") + pcap_geterr(handle.get())); + if (status == 0) continue; + const auto secs = header->ts.tv_sec, nanos = header->ts.tv_usec; + if (secs < 0 || nanos < 0 || nanos >= second || secs > (std::numeric_limits::max()-nanos)/second) + throw std::runtime_error("PCAP timestamp outside supported Unix nanosecond range"); + const Timestamp timestamp = secs * second + nanos; + if (timestamp < previous) throw std::runtime_error("PCAP timestamps are not chronological; sort capture before analysis"); + previous = timestamp; + if (header->caplen > 16U*1024U*1024U || header->caplen > header->len) + throw std::runtime_error("invalid PCAP captured/wire length"); + consume(parse_packet(bytes, header->caplen, header->len, timestamp)); ++result.packets; + } + return result; +} +} diff --git a/src/cli.cpp b/src/cli.cpp new file mode 100644 index 0000000..2665a38 --- /dev/null +++ b/src/cli.cpp @@ -0,0 +1,63 @@ +#include "packetforge/cli.hpp" +#include "packetforge/capture.hpp" +#include +#include +#include +#include +namespace packetforge { +namespace { +std::uint64_t number(const std::string& text) { + std::uint64_t value = 0; const auto parsed = std::from_chars(text.data(), text.data()+text.size(), value); + if (parsed.ec != std::errc{} || parsed.ptr != text.data()+text.size() || value == 0 || value > 1000000000) + throw std::runtime_error("expected positive integer <= 1000000000: " + text); + return value; +} +void help() { + std::cout << "PacketForge | passive network packet analyzer\n" + "Usage: packetforge interfaces\n" + " packetforge capture --interface NAME [--count N] [--duration SECONDS] [--promiscuous] [--verbose]\n" + " packetforge analyze --pcap FILE [--count N] [--verbose]\n" + " packetforge --help\n" + "Offline analysis needs no privileges. Live capture requires CAP_NET_RAW.\n"; +} +} +int run_cli(int argc, char** argv, bool legacy, bool policy) { + try { + if (argc < 2) { help(); return legacy ? 2 : 0; } + if (std::string(argv[1]) == "--help") { help(); return 0; } + std::string command = legacy ? "capture" : argv[1], path; + CaptureOptions options; bool verbose = false; + for (int i = legacy ? 1 : 2; i < argc; ++i) { + const std::string arg = argv[i]; + auto value = [&]() { if (++i >= argc) throw std::runtime_error("missing value for " + arg); return std::string(argv[i]); }; + if (arg == "--interface") options.interface = value(); + else if (arg == "--pcap") path = value(); + else if (arg == "--count") options.count = number(value()); + else if (arg == "--duration") options.duration = static_cast(number(value())); + else if (arg == "--promiscuous") options.promiscuous = true; + else if (arg == "--verbose") verbose = true; + else throw std::runtime_error("unknown option: " + arg); + } + if (command == "interfaces") { + if (argc != 2) throw std::runtime_error("interfaces takes no options"); + list_interfaces(); return 0; + } + if (command != "capture" && command != "analyze") throw std::runtime_error("unknown command: " + command); + if (command == "capture" && (options.interface.empty() || !path.empty())) throw std::runtime_error("capture requires --interface and does not accept --pcap"); + if (command == "analyze" && (path.empty() || !options.interface.empty() || options.duration || options.promiscuous)) + throw std::runtime_error("analyze requires --pcap; capture-only options are invalid"); + std::cout << "PacketForge | " << command << " | " << (command == "capture" ? options.interface : path) << '\n'; + if (policy) std::cout << "Firewall Policy Simulation: no traffic is blocked or forwarded\n"; + std::uint64_t packets = 0, bytes = 0; + auto consume = [&](const Packet& p) { + ++packets; bytes += p.captured_length; + if (verbose) std::cout << iso_time(p.timestamp) << ' ' << p.protocol_name() << ' ' << p.source << ':' + << p.source_port << " -> " << p.destination << ':' << p.destination_port << ' ' << status_name(p.status) << '\n'; + if (policy && p.transport) std::cout << "Source: " << p.source << " | Destination: " << p.destination << ':' + << p.destination_port << " | Policy: " << ((p.destination_port == 22 || p.destination_port == 445) ? "WOULD_BLOCK" : "WOULD_ALLOW") << '\n'; + }; + if (command == "capture") capture_live(options, consume); else analyze_pcap(path, consume, options.count); + std::cout << "Packets: " << packets << " | Observed bytes: " << bytes << '\n'; return 0; + } catch (const std::exception& e) { std::cerr << "PacketForge error: " << e.what() << '\n'; return 2; } +} +} diff --git a/src/forwarder.cpp b/src/forwarder.cpp index a10d940..7c543d3 100644 --- a/src/forwarder.cpp +++ b/src/forwarder.cpp @@ -1,88 +1,3 @@ -#include -#include -#include -#include -#include -#include -#include -#include "../include/headers.hpp" -#include "../include/rules.hpp" - -void print_mac(uint8_t* mac) { - printf("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); -} - -// Check packet against rule table, return matching action -Action checkRules(const std::string& src_ip, const std::string& dst_ip, int dst_port) { - for (auto& rule : ruleTable) { - bool src_match = (rule.src_ip == "any" || rule.src_ip == src_ip); - bool dst_match = (rule.dst_ip == "any" || rule.dst_ip == dst_ip); - bool port_match = (rule.dst_port == -1 || rule.dst_port == dst_port); - - if (src_match && dst_match && port_match) { - return rule.action; - } - } - return Action::ALLOW; // fallback -} - -int main() { - int sock = socket(AF_PACKET, SOCK_RAW, htons(0x0003)); // ETH_P_ALL - - if (sock < 0) { - std::cerr << "Socket creation failed: " << strerror(errno) << std::endl; - return 1; - } - - std::cout << "PacketForge running. Listening + filtering... (Ctrl+C to stop)\n" << std::endl; - - unsigned char buffer[65536]; - long total = 0, allowed = 0, dropped = 0; - - while (true) { - int data_size = recvfrom(sock, buffer, sizeof(buffer), 0, nullptr, nullptr); - if (data_size < 0) break; - - total++; - EthHeader* eth = (EthHeader*)buffer; - uint16_t ethertype = ntohs(eth->ethertype); - - if (ethertype != 0x0800) continue; // only handle IPv4 for forwarding - - IPHeader* ip = (IPHeader*)(buffer + sizeof(EthHeader)); - int ip_header_len = (ip->ver_ihl & 0x0F) * 4; - - struct in_addr src, dst; - src.s_addr = ip->src_ip; - dst.s_addr = ip->dst_ip; - std::string src_ip = inet_ntoa(src); - std::string dst_ip = inet_ntoa(dst); - - int dst_port = -1; - unsigned char* transport = buffer + sizeof(EthHeader) + ip_header_len; - - if (ip->protocol == 6) { - TCPHeader* tcp = (TCPHeader*)transport; - dst_port = ntohs(tcp->dst_port); - } else if (ip->protocol == 17) { - UDPHeader* udp = (UDPHeader*)transport; - dst_port = ntohs(udp->dst_port); - } - - Action decision = checkRules(src_ip, dst_ip, dst_port); - - printf("Src: %s -> Dst: %s:%d | Protocol: %d | Decision: %s\n", - src_ip.c_str(), dst_ip.c_str(), dst_port, ip->protocol, - decision == Action::ALLOW ? "ALLOW" : "DROP"); - - if (decision == Action::ALLOW) allowed++; - else dropped++; - - if (total % 20 == 0) { - printf("\n[Stats] Total: %ld | Allowed: %ld | Dropped: %ld\n\n", total, allowed, dropped); - } - } - - close(sock); - return 0; -} +#include "packetforge/cli.hpp" +// Historical name only: policy simulation observes packets and never forwards/blocks. +int main(int argc, char** argv) { return packetforge::run_cli(argc, argv, true, true); } diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..e7bb449 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,2 @@ +#include "packetforge/cli.hpp" +int main(int argc, char** argv) { return packetforge::run_cli(argc, argv); } diff --git a/src/parsers/packet.cpp b/src/parsers/packet.cpp new file mode 100644 index 0000000..28f4e35 --- /dev/null +++ b/src/parsers/packet.cpp @@ -0,0 +1,177 @@ +#include "packetforge/packet.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace packetforge { +namespace { +struct Failure { ParseStatus status; const char* reason; }; +class Decoder { + const std::uint8_t* data_; + std::size_t end_; +public: + Decoder(const std::uint8_t* data, std::size_t size) : data_(data), end_(size) {} + void need(std::size_t offset, std::size_t length) const { + if (offset > end_ || length > end_ - offset) + throw Failure{ParseStatus::truncated, "captured header incomplete"}; + } + void limit(std::size_t end) { end_ = std::min(end_, end); } + std::uint8_t u8(std::size_t i) const { need(i, 1); return data_[i]; } + std::uint16_t u16(std::size_t i) const { + need(i, 2); return static_cast((data_[i] << 8) | data_[i+1]); + } + std::uint32_t u32(std::size_t i) const { + need(i, 4); return (std::uint32_t(data_[i]) << 24) | (std::uint32_t(data_[i+1]) << 16) + | (std::uint32_t(data_[i+2]) << 8) | data_[i+3]; + } + std::string mac(std::size_t i) const { + need(i, 6); char out[18]; + std::snprintf(out, sizeof(out), "%02x:%02x:%02x:%02x:%02x:%02x", data_[i], data_[i+1], + data_[i+2], data_[i+3], data_[i+4], data_[i+5]); + return out; + } + std::string ip(std::size_t i, bool v6) const { + need(i, v6 ? 16 : 4); char out[INET6_ADDRSTRLEN]{}; + inet_ntop(v6 ? AF_INET6 : AF_INET, data_ + i, out, sizeof(out)); return out; + } +}; +void malformed(bool condition, const char* reason) { + if (condition) throw Failure{ParseStatus::malformed, reason}; +} +void unsupported(const char* reason) { throw Failure{ParseStatus::unsupported, reason}; } +} +const char* status_name(ParseStatus status) { + switch (status) { + case ParseStatus::ok: return "ok"; + case ParseStatus::truncated: return "truncated"; + case ParseStatus::malformed: return "malformed"; + case ParseStatus::unsupported: return "unsupported"; + } + return "unsupported"; +} +std::string Packet::protocol_name() const { + if (arp) return "ARP"; + if (ipv4 || ipv6) { + if (protocol == 6) return "TCP"; + if (protocol == 17) return "UDP"; + if (protocol == 1 || protocol == 58) return "ICMP"; + return ipv6 ? "IPv6-other" : "IPv4-other"; + } + return "Ethernet-other"; +} +Packet parse_packet(const std::uint8_t* data, std::size_t size, std::uint32_t wire, Timestamp ts) { + Packet p; p.timestamp = ts; p.wire_length = wire; + p.captured_length = static_cast(std::min(size, UINT32_MAX)); + p.capture_truncated = size < wire; + Decoder b(data, size); + try { + malformed(size > wire || size > UINT32_MAX || (!data && size), "invalid capture/wire length"); + b.need(0, 14); p.ethernet = true; + p.destination_mac = b.mac(0); p.source_mac = b.mac(6); p.ethertype = b.u16(12); + std::size_t o = 14; + while (p.ethertype == 0x8100 || p.ethertype == 0x88a8) { + if (p.vlan_ids.size() == 2) unsupported("more than two VLAN tags"); + b.need(o, 4); p.vlan_ids.push_back(b.u16(o) & 0x0fff); + p.ethertype = b.u16(o+2); o += 4; + } + if (p.ethertype == 0x0806) { + b.need(o, 8); p.arp_opcode = b.u16(o+6); + const auto hlen = b.u8(o+4), plen = b.u8(o+5); + b.need(o+8, 2U * hlen + 2U * plen); + if (b.u16(o) != 1 || b.u16(o+2) != 0x0800 || hlen != 6 || plen != 4) + unsupported("ARP address format is not Ethernet/IPv4"); + p.arp = true; p.arp_sender_hardware = b.mac(o+8); p.source = b.ip(o+14, false); + p.arp_target_hardware = b.mac(o+18); p.destination = b.ip(o+24, false); + return p; + } + std::size_t end = 0; + if (p.ethertype == 0x0800) { + b.need(o, 20); p.version = b.u8(o) >> 4; p.ip_header_length = (b.u8(o) & 15) * 4; + malformed(p.version != 4 || p.ip_header_length < 20, "invalid IPv4 version or IHL"); + p.ip_total_length = b.u16(o+2); + malformed(p.ip_total_length < p.ip_header_length, "IPv4 total length smaller than header"); + malformed(p.ip_total_length > wire - o, "IPv4 total length exceeds wire frame"); + b.need(o, p.ip_header_length); p.ipv4 = true; + p.source = b.ip(o+12, false); p.destination = b.ip(o+16, false); + p.ttl = b.u8(o+8); p.protocol = b.u8(o+9); p.next_header = p.protocol; p.ip_id = b.u16(o+4); + const auto fragment = b.u16(o+6); + p.fragment_offset = static_cast((fragment & 0x1fff) * 8); + p.more_fragments = (fragment & 0x2000) != 0; p.dont_fragment = (fragment & 0x4000) != 0; + p.fragmented = p.more_fragments || p.fragment_offset != 0; + malformed((fragment & 0x8000) || (p.dont_fragment && p.fragmented), "invalid IPv4 fragmentation flags"); + malformed(p.more_fragments && ((p.ip_total_length - p.ip_header_length) % 8 != 0), + "non-final IPv4 fragment payload not multiple of eight"); + end = o + p.ip_total_length; b.need(o, p.ip_total_length); b.limit(end); o += p.ip_header_length; + if (p.fragment_offset) { p.detail = "non-initial IPv4 fragment; transport skipped"; return p; } + } else if (p.ethertype == 0x86dd) { + b.need(o, 40); p.version = b.u8(o) >> 4; + malformed(p.version != 6, "invalid IPv6 version"); p.ipv6 = true; + p.source = b.ip(o+8, true); p.destination = b.ip(o+24, true); + p.ipv6_payload_length = b.u16(o+4); p.next_header = b.u8(o+6); p.protocol = p.next_header; p.ttl = b.u8(o+7); + if (p.ipv6_payload_length == 0 && p.protocol != 59) unsupported("IPv6 jumbograms/zero-length payload unsupported"); + malformed(40U + p.ipv6_payload_length > wire - o, "IPv6 payload exceeds wire frame"); + end = o + 40 + p.ipv6_payload_length; b.need(o, 40 + p.ipv6_payload_length); b.limit(end); o += 40; + unsigned extensions = 0; bool seen_fragment = false; + while (p.protocol == 0 || p.protocol == 43 || p.protocol == 60 || p.protocol == 44 || p.protocol == 51) { + if (++extensions > 8) unsupported("IPv6 extension chain limit reached"); + malformed(p.protocol == 0 && extensions != 1, "hop-by-hop header must be first"); + if (end - o < 2) throw Failure{ParseStatus::malformed, "IPv6 extension exceeds payload"}; + std::size_t length = (std::size_t(b.u8(o+1)) + 1) * 8; + if (p.protocol == 51) length = (std::size_t(b.u8(o+1)) + 2) * 4; + if (p.protocol == 44) { + malformed(seen_fragment, "duplicate IPv6 fragment header"); seen_fragment = true; length = 8; + malformed(end - o < length, "IPv6 fragment exceeds payload"); b.need(o, length); + const auto bits = b.u16(o+2); + malformed((bits & 6) != 0 || b.u8(o+1) != 0, "invalid IPv6 fragment reserved bits"); + p.fragment_offset = bits & 0xfff8; p.more_fragments = bits & 1; + p.fragmented = p.fragment_offset != 0 || p.more_fragments; p.ipv6_fragment_id = b.u32(o+4); + malformed(p.more_fragments && ((end-o-8) % 8 != 0), "non-final IPv6 fragment length"); + } + malformed(length > end - o, "IPv6 extension exceeds payload"); b.need(o, length); + p.protocol = b.u8(o); o += length; + if (p.fragment_offset) { p.detail = "non-initial IPv6 fragment; transport skipped"; return p; } + } + if (p.protocol == 59) { p.detail = "IPv6 no next header"; return p; } + } else { unsupported(p.ethertype <= 1500 ? "IEEE 802.3 LLC unsupported" : "EtherType unsupported"); } + const auto remaining = end - o; + auto require_transport = [&](std::size_t n) { + if (remaining < n && p.fragmented) unsupported("initial fragment lacks complete transport header"); + malformed(remaining < n, "transport header exceeds IP payload"); b.need(o, n); + }; + if (p.protocol == 6) { + require_transport(20); p.tcp_header_length = (b.u8(o+12) >> 4) * 4; + malformed(p.tcp_header_length < 20, "invalid TCP data offset"); require_transport(p.tcp_header_length); + p.source_port = b.u16(o); p.destination_port = b.u16(o+2); + p.sequence = b.u32(o+4); p.acknowledgment = b.u32(o+8); + p.tcp_flags = b.u8(o+13); p.tcp_window = b.u16(o+14); p.transport = true; + } else if (p.protocol == 17) { + require_transport(8); p.udp_length = b.u16(o+4); + malformed(p.udp_length < 8 || (!p.fragmented && p.udp_length > remaining), "invalid UDP length"); + p.source_port = b.u16(o); p.destination_port = b.u16(o+2); p.transport = true; + } else if ((p.ipv4 && p.protocol == 1) || (p.ipv6 && p.protocol == 58)) { + require_transport(4); p.icmp_type = b.u8(o); p.icmp_code = b.u8(o+1); + p.echo_request = p.icmp_code == 0 && p.icmp_type == (p.ipv6 ? 128 : 8); + p.echo_reply = p.icmp_code == 0 && p.icmp_type == (p.ipv6 ? 129 : 0); + if (p.echo_request || p.echo_reply) require_transport(8); + p.transport = true; + } else unsupported("IP protocol/extension unsupported (including ESP)"); + } catch (const Failure& error) { p.status = error.status; p.detail = error.reason; p.transport = false; } + return p; +} +Timestamp now_timestamp() { + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); +} +std::string iso_time(Timestamp timestamp) { + const auto whole = timestamp / second; + const std::time_t seconds = static_cast(whole); + std::tm tm{}; if (!gmtime_r(&seconds, &tm)) return "invalid timestamp"; + std::ostringstream out; + out << std::put_time(&tm, "%Y-%m-%dT%H:%M:%S") << '.' << std::setw(9) << std::setfill('0') + << (timestamp % second) << 'Z'; return out.str(); +} +} diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 7c2f154..4380785 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -1,85 +1,3 @@ -#include -#include -#include -#include -#include -#include -#include -#include "../include/headers.hpp" - -void print_mac(uint8_t* mac) { - printf("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); -} - -int main() { - int sock = socket(AF_PACKET, SOCK_RAW, htons(0x0003)); // ETH_P_ALL - - if (sock < 0) { - std::cerr << "Socket creation failed: " << strerror(errno) << std::endl; - return 1; - } - - std::cout << "Raw socket created. Listening for packets... (Ctrl+C to stop)\n" << std::endl; - - unsigned char buffer[65536]; - - while (true) { - int data_size = recvfrom(sock, buffer, sizeof(buffer), 0, nullptr, nullptr); - - if (data_size < 0) { - std::cerr << "recvfrom failed: " << strerror(errno) << std::endl; - break; - } - - EthHeader* eth = (EthHeader*)buffer; - uint16_t ethertype = ntohs(eth->ethertype); - - printf("--- Packet (%d bytes) ---\n", data_size); - printf("Src MAC: "); print_mac(eth->src_mac); printf("\n"); - printf("Dst MAC: "); print_mac(eth->dst_mac); printf("\n"); - printf("EtherType: 0x%04x\n", ethertype); - - if (ethertype == 0x0800) { // IPv4 - IPHeader* ip = (IPHeader*)(buffer + sizeof(EthHeader)); - int ip_header_len = (ip->ver_ihl & 0x0F) * 4; - - struct in_addr src, dst; - src.s_addr = ip->src_ip; - dst.s_addr = ip->dst_ip; - - printf("Src IP: %s\n", inet_ntoa(src)); - printf("Dst IP: %s\n", inet_ntoa(dst)); - printf("Protocol: %d ", ip->protocol); - - unsigned char* transport = buffer + sizeof(EthHeader) + ip_header_len; - - if (ip->protocol == 6) { // TCP - TCPHeader* tcp = (TCPHeader*)transport; - printf("(TCP)\n"); - printf("Src Port: %d\n", ntohs(tcp->src_port)); - printf("Dst Port: %d\n", ntohs(tcp->dst_port)); - } - else if (ip->protocol == 17) { // UDP - UDPHeader* udp = (UDPHeader*)transport; - printf("(UDP)\n"); - printf("Src Port: %d\n", ntohs(udp->src_port)); - printf("Dst Port: %d\n", ntohs(udp->dst_port)); - } - else if (ip->protocol == 1) { - printf("(ICMP)\n"); - } - else { - printf("(Other)\n"); - } - } - else if (ethertype == 0x0806) { - printf("ARP packet\n"); - } - - printf("\n"); - } - - close(sock); - return 0; -} - +#include "packetforge/cli.hpp" +// Preserve the original teaching entry point using the safe, shared pipeline. +int main(int argc, char** argv) { return packetforge::run_cli(argc, argv, true); } diff --git a/tests/integration.py b/tests/integration.py new file mode 100644 index 0000000..0344485 --- /dev/null +++ b/tests/integration.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +import subprocess +import sys +binary = sys.argv[1] +for args, expected in [(['--help'], 0), (['interfaces'], 0), (['analyze'], 2), + (['analyze', '--pcap', 'missing.pcap'], 2), + (['capture', '--count', '-1'], 2), (['wat'], 2)]: + result = subprocess.run([binary] + args, capture_output=True, text=True) + assert result.returncode == expected, (args, result.stdout, result.stderr) +from pathlib import Path +root = Path(sys.argv[2]) +result = subprocess.run([binary, 'analyze', '--pcap', str(root/'samples/demo.pcap')], capture_output=True, text=True) +assert result.returncode == 0 and 'Packets: 9' in result.stdout, (result.stdout, result.stderr) +print('CLI and offline PCAP checks passed') diff --git a/tests/unit.cpp b/tests/unit.cpp new file mode 100644 index 0000000..99dad6d --- /dev/null +++ b/tests/unit.cpp @@ -0,0 +1,36 @@ +#include "packetforge/packet.hpp" +#include +#include +#include +#include +using namespace packetforge; +namespace { +unsigned checks = 0; +void check(bool condition, const char* message) { ++checks; if (!condition) throw std::runtime_error(message); } +void put16(std::vector& b, std::size_t o, std::uint16_t value) { b[o] = static_cast(value >> 8); b[o+1] = static_cast(value); } +std::vector tcp() { + std::vector b(54); put16(b,12,0x0800); b[14]=0x45; put16(b,16,40); b[22]=64; b[23]=6; + b[26]=192; b[28]=2; b[29]=1; b[30]=198; b[31]=51; b[32]=100; b[33]=2; + put16(b,34,12345); put16(b,36,443); b[38]=0x12; b[39]=0x34; b[40]=0x56; b[41]=0x78; + b[46]=0x50; b[47]=2; put16(b,48,4096); return b; +} +Packet parse(const std::vector& b) { return parse_packet(b.data(), b.size(), static_cast(b.size()), 0); } +void parser_tests() { + auto b=tcp(); auto p=parse(b); + check(p.status==ParseStatus::ok && p.ethernet && p.ipv4 && p.transport, "Ethernet IPv4 TCP"); + check(p.source=="192.0.2.1" && p.destination=="198.51.100.2", "addresses"); + check(p.source_port==12345 && p.destination_port==443 && p.sequence==0x12345678 && p.tcp_window==4096, "network order"); + check(p.syn_attempt() && p.tcp_header_length==20 && p.ttl==64, "TCP fields"); + for (std::size_t n=0; n Date: Wed, 21 Oct 2026 02:18:52 +0530 Subject: [PATCH 3/4] feat: implement configurable IDS, bounded flows, statistics and investigation reports --- CMakeLists.txt | 12 +- PROGRESS.md | 10 + config/rules.json | 84 + include/packetforge/analysis.hpp | 24 + include/packetforge/config.hpp | 33 + include/packetforge/detection.hpp | 33 + include/packetforge/flows.hpp | 40 + include/packetforge/reporting.hpp | 10 + include/packetforge/statistics.hpp | 20 + include/rules.hpp | 33 +- samples/README.md | 48 + samples/demo.pcap | Bin 666 -> 666 bytes samples/mixed.pcap | Bin 1507 -> 1507 bytes samples/normal_tcp.pcap | Bin 304 -> 304 bytes samples/synrate.pcap | Bin 7094 -> 7094 bytes scripts/generate_fixtures.py | 8 +- src/cli.cpp | 157 +- src/detection/config.cpp | 125 + src/detection/detection.cpp | 104 + src/flows/flows.cpp | 48 + src/parsers/packet.cpp | 5 +- src/reporting/reporting.cpp | 125 + src/statistics/analysis.cpp | 59 + src/statistics/statistics.cpp | 48 + tests/integration.py | 118 +- tests/live_capture.py | 53 + tests/unit.cpp | 170 +- third_party/README.md | 7 + third_party/nlohmann/LICENSE.MIT | 21 + third_party/nlohmann/json.hpp | 25526 +++++++++++++++++++++++++++ 30 files changed, 26840 insertions(+), 81 deletions(-) create mode 100644 config/rules.json create mode 100644 include/packetforge/analysis.hpp create mode 100644 include/packetforge/config.hpp create mode 100644 include/packetforge/detection.hpp create mode 100644 include/packetforge/flows.hpp create mode 100644 include/packetforge/reporting.hpp create mode 100644 include/packetforge/statistics.hpp create mode 100644 samples/README.md create mode 100644 src/detection/config.cpp create mode 100644 src/detection/detection.cpp create mode 100644 src/flows/flows.cpp create mode 100644 src/reporting/reporting.cpp create mode 100644 src/statistics/analysis.cpp create mode 100644 src/statistics/statistics.cpp create mode 100644 tests/live_capture.py create mode 100644 third_party/README.md create mode 100644 third_party/nlohmann/LICENSE.MIT create mode 100644 third_party/nlohmann/json.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 728de88..14b80d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() find_path(PCAP_INCLUDE_DIR pcap/pcap.h REQUIRED) find_library(PCAP_LIBRARY pcap REQUIRED) -add_library(packetforge_core src/parsers/packet.cpp src/capture/pcap.cpp src/capture/live.cpp) +add_library(packetforge_core src/parsers/packet.cpp src/capture/pcap.cpp src/capture/live.cpp + src/detection/config.cpp src/detection/detection.cpp src/flows/flows.cpp + src/statistics/statistics.cpp src/statistics/analysis.cpp src/reporting/reporting.cpp src/cli.cpp) target_include_directories(packetforge_core PUBLIC include) target_include_directories(packetforge_core SYSTEM PUBLIC third_party ${PCAP_INCLUDE_DIR}) target_link_libraries(packetforge_core PUBLIC ${PCAP_LIBRARY}) @@ -18,17 +20,19 @@ if(PACKETFORGE_SANITIZERS) target_compile_options(packetforge_core PUBLIC -fsanitize=address,undefined -fno-omit-frame-pointer) target_link_options(packetforge_core PUBLIC -fsanitize=address,undefined) endif() -add_executable(packetforge src/main.cpp src/cli.cpp) +add_executable(packetforge src/main.cpp) target_link_libraries(packetforge PRIVATE packetforge_core) -add_executable(sniffer src/sniffer.cpp src/cli.cpp) +add_executable(sniffer src/sniffer.cpp) target_link_libraries(sniffer PRIVATE packetforge_core) -add_executable(forwarder src/forwarder.cpp src/cli.cpp) +add_executable(forwarder src/forwarder.cpp) target_link_libraries(forwarder PRIVATE packetforge_core) include(CTest) if(BUILD_TESTING) add_executable(packetforge_tests tests/unit.cpp) target_link_libraries(packetforge_tests PRIVATE packetforge_core) add_test(NAME unit COMMAND packetforge_tests) + add_test(NAME interfaces COMMAND packetforge interfaces) + set_tests_properties(interfaces PROPERTIES LABELS "host") find_package(Python3 COMPONENTS Interpreter REQUIRED) add_test(NAME integration COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/integration.py $ ${CMAKE_SOURCE_DIR}) endif() diff --git a/PROGRESS.md b/PROGRESS.md index 9f69ddc..90629f1 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -16,3 +16,13 @@ Parser/capture stage: C++17 library, bounded Ethernet/VLAN/ARP/IPv4/IPv6/TCP/UDP parser, AF_PACKET capture and libpcap classic-PCAP reader implemented. Initial parser tests pass. Interface listing passes on the host; the restricted execution sandbox blocks network-interface enumeration. Deterministic fixtures added. + +P1 implemented: validated JSON rules; five metadata detections; bounded directional +flows and statistics; consistent alert schema; cooldowns/exclusions; accurate +WOULD_ALLOW/WOULD_BLOCK policy simulation; JSON, CSV and standalone HTML reports. + +Verification so far: 10,153 unit checks (including 10,000 randomized inputs), +68 CLI/fixture subprocess checks, and isolated WSL2 live-capture checks passed. +Live checks covered real loopback UDP frames, count limit, idle duration, Ctrl+C, +Ethernet device binding and explicit promiscuous membership. No external traffic +was generated. Sanitizer and final documentation work remain in progress. diff --git a/config/rules.json b/config/rules.json new file mode 100644 index 0000000..2780d0a --- /dev/null +++ b/config/rules.json @@ -0,0 +1,84 @@ +{ + "rules": { + "POSSIBLE_TCP_PORT_SCAN": { + "enabled": true, + "threshold": 12, + "window_seconds": 10, + "cooldown_seconds": 30, + "severity": "MEDIUM", + "exclude_sources": [], + "exclude_destinations": [] + }, + "HIGH_TCP_SYN_RATE": { + "enabled": true, + "threshold": 100, + "window_seconds": 10, + "cooldown_seconds": 30, + "severity": "MEDIUM", + "exclude_sources": [], + "exclude_destinations": [] + }, + "HIGH_ICMP_ECHO_RATE": { + "enabled": true, + "threshold": 50, + "window_seconds": 10, + "cooldown_seconds": 30, + "severity": "LOW", + "exclude_sources": [], + "exclude_destinations": [] + }, + "SENSITIVE_SERVICE_TRAFFIC": { + "enabled": true, + "threshold": 1, + "window_seconds": 10, + "cooldown_seconds": 60, + "severity": "INFO", + "exclude_sources": [], + "exclude_destinations": [], + "ports": [ + 22, + 23, + 445, + 3389 + ] + }, + "CONNECTION_CONCENTRATION": { + "enabled": true, + "threshold": 40, + "window_seconds": 10, + "cooldown_seconds": 30, + "severity": "LOW", + "exclude_sources": [], + "exclude_destinations": [] + } + }, + "limits": { + "max_flows": 4096, + "max_unique_flows": 65536, + "max_talkers": 4096, + "max_rule_keys": 1024, + "max_rule_events": 50000, + "max_alerts": 10000, + "flow_timeout_seconds": 60 + }, + "policy": [ + { + "source": "any", + "destination": "any", + "destination_port": 22, + "action": "WOULD_BLOCK" + }, + { + "source": "any", + "destination": "any", + "destination_port": 445, + "action": "WOULD_BLOCK" + }, + { + "source": "any", + "destination": "any", + "destination_port": -1, + "action": "WOULD_ALLOW" + } + ] +} diff --git a/include/packetforge/analysis.hpp b/include/packetforge/analysis.hpp new file mode 100644 index 0000000..c27da41 --- /dev/null +++ b/include/packetforge/analysis.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "capture.hpp" +#include "detection.hpp" +#include "flows.hpp" +#include "statistics.hpp" +#include +namespace packetforge { +class Analysis { + Config config_; + bool ids_; + Timestamp previous_=-1; +public: + Statistics statistics; + FlowTable flows; + DetectionEngine detection; + std::vector alerts; + std::map alert_counts; + std::uint64_t total_alerts=0,alerts_not_retained=0; + Analysis(const Config& config,bool ids) : config_(config),ids_(ids),statistics(config.max_talkers),flows(config),detection(config) {} + void observe(const Packet& packet,const std::function& emit = {}); + Json report(const std::string& mode,const std::string& source,const CaptureResult& capture) const; + void summary(std::ostream& out) const; +}; +} diff --git a/include/packetforge/config.hpp b/include/packetforge/config.hpp new file mode 100644 index 0000000..41b82ee --- /dev/null +++ b/include/packetforge/config.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +namespace packetforge { +using Json = nlohmann::json; +struct RuleConfig { + bool enabled = true; + std::size_t threshold = 1; + std::int64_t window_seconds = 10, cooldown_seconds = 30; + std::string severity = "MEDIUM"; + std::set ports; + std::set exclude_sources, exclude_destinations; +}; +struct PolicyRule { + std::string source = "any", destination = "any", action = "WOULD_ALLOW"; + int destination_port = -1; +}; +struct Config { + std::map rules; + std::vector policy; + std::size_t max_flows = 4096, max_unique_flows = 65536, max_talkers = 4096; + std::size_t max_rule_keys = 1024, max_rule_events = 50000, max_alerts = 10000; + std::int64_t flow_timeout_seconds = 60; + static Config defaults(); + static Config load(const std::string& path); + Json json() const; +}; +} diff --git a/include/packetforge/detection.hpp b/include/packetforge/detection.hpp new file mode 100644 index 0000000..b15b84c --- /dev/null +++ b/include/packetforge/detection.hpp @@ -0,0 +1,33 @@ +#pragma once +#include "config.hpp" +#include "packet.hpp" +#include +#include +#include +namespace packetforge { +class DetectionEngine { + struct Event { Timestamp time; std::uint16_t port; std::string destination, attempt; }; + struct State { + std::deque events; + Timestamp last_seen=0,last_alert=0; + bool alerted=false, above=false; + }; + struct Runtime { + std::map states; + std::size_t events=0; + std::uint64_t matched=0,alerts=0,cooldown_suppressed=0,scan_suppressed=0,dropped_events=0,dropped_keys=0; + }; + Config config_; + std::map runtime_; + Timestamp last_sweep_=-1; + std::uint64_t next_id_=1; + void trim(State& state, Runtime& runtime, Timestamp now, const RuleConfig& rule); +public: + explicit DetectionEngine(const Config& config) : config_(config) { + for (const auto& [id,rule]:config.rules) { (void)rule; runtime_.emplace(id,Runtime{}); } + } + void expire(Timestamp now); + std::vector observe(const Packet& packet); + Json counters() const; +}; +} diff --git a/include/packetforge/flows.hpp b/include/packetforge/flows.hpp new file mode 100644 index 0000000..0c7f2cd --- /dev/null +++ b/include/packetforge/flows.hpp @@ -0,0 +1,40 @@ +#pragma once +#include "config.hpp" +#include "packet.hpp" +#include +#include +#include +#include +namespace packetforge { +struct FlowKey { + std::string source, destination; + std::uint16_t source_port = 0, destination_port = 0; + std::uint8_t protocol = 0; + auto tuple() const { return std::tie(source,destination,source_port,destination_port,protocol); } + bool operator<(const FlowKey& other) const { return tuple() active_; + std::deque closed_; + std::set unique_; + Timestamp last_sweep_=-1; + void archive(std::map::iterator entry); +public: + std::uint64_t evictions=0, expired=0, archives_discarded=0; + bool unique_saturated=false; + explicit FlowTable(const Config& config) : config_(config) {} + void observe(const Packet& packet); + void expire(Timestamp now, bool force=false); + std::size_t active_count() const { return active_.size(); } + std::size_t unique_count() const { return unique_.size(); } + Json json() const; +}; +} diff --git a/include/packetforge/reporting.hpp b/include/packetforge/reporting.hpp new file mode 100644 index 0000000..a25ee35 --- /dev/null +++ b/include/packetforge/reporting.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "config.hpp" +#include +#include +namespace packetforge { +std::string html_escape(const std::string& value); +std::string csv_field(const std::string& value); +std::string html_report(const Json& data); +std::vector write_reports(const Json& data,const std::string& format,const std::string& prefix); +} diff --git a/include/packetforge/statistics.hpp b/include/packetforge/statistics.hpp new file mode 100644 index 0000000..8a0e3cf --- /dev/null +++ b/include/packetforge/statistics.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "config.hpp" +#include "packet.hpp" +#include +namespace packetforge { +class Statistics { + std::size_t max_talkers_; + void talker(std::map& table,const std::string& address,std::uint64_t& omitted); +public: + std::uint64_t packets=0,observed_bytes=0,wire_bytes=0,truncated=0,malformed=0,unsupported=0; + std::uint64_t omitted_sources=0,omitted_destinations=0; + Timestamp first=0,last=0; + std::map protocols,sources,destinations; + std::map ports; + explicit Statistics(std::size_t maximum) : max_talkers_(maximum) {} + void observe(const Packet& p); + double duration() const; + Json json() const; +}; +} diff --git a/include/rules.hpp b/include/rules.hpp index e360e03..1898ffc 100644 --- a/include/rules.hpp +++ b/include/rules.hpp @@ -1,20 +1,15 @@ #pragma once -#include -#include -#include - -enum class Action { ALLOW, DROP }; - -struct Rule { - std::string src_ip; // "any" = match all - std::string dst_ip; // "any" = match all - int dst_port; // -1 = match all - Action action; -}; - -// Simple rule table — checked top to bottom, first match wins -inline std::vector ruleTable = { - { "any", "any", 22, Action::DROP }, // block SSH traffic - { "any", "any", 445, Action::DROP }, // block SMB (common attack port) - { "any", "any", -1, Action::ALLOW } // default: allow everything else -}; +#include "packetforge/config.hpp" +#include "packetforge/packet.hpp" +namespace packetforge { +// Original first-match source/destination/port logic, now explicitly simulation. +inline std::string evaluate_policy(const Packet& packet, const std::vector& rules) { + for (const auto& rule : rules) { + if ((rule.source == "any" || rule.source == packet.source) + && (rule.destination == "any" || rule.destination == packet.destination) + && (rule.destination_port == -1 || (packet.transport && (packet.protocol == 6 || packet.protocol == 17) + && rule.destination_port == packet.destination_port))) return rule.action; + } + return "WOULD_ALLOW"; +} +} diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 0000000..832fa4c --- /dev/null +++ b/samples/README.md @@ -0,0 +1,48 @@ +# Synthetic PacketForge captures + +Every capture was generated locally by `python3 scripts/generate_fixtures.py` using +only the Python standard library. The script writes files and never sends packets. +Source ranges are RFC 5737 documentation IPv4 ranges and `2001:db8::/32` for IPv6; +MAC addresses are synthetic locally administered values. There are no real users, +credentials, third-party captures or runtime packet-building dependencies. + +Timestamps begin at 2023-11-14T22:13:20Z. Files use classic Ethernet PCAP, mostly +little-endian with microsecond timestamp resolution. Protocol checksums are +constructed for normal IP/TCP/ICMP messages; zero IPv4 UDP checksums are legal. +The normal TCP example shows SYN, SYN/ACK, ACK and FIN/ACK metadata, without claiming +a complete session or application exchange. DNS contains a harmless `example.test` +query; PacketForge treats it as UDP metadata, not decoded DNS. + +| Fixture | Packets | Default alerts / expected behavior | +| --- | ---: | --- | +| `normal_tcp.pcap` | 4 | None; 2 directional flows | +| `normal_udp_dns.pcap` | 2 | None; UDP including one port-53 query | +| `arp.pcap` | 1 | None; Ethernet/IPv4 ARP request | +| `icmp.pcap` | 2 | None; echo request and reply | +| `ipv6.pcap` | 1 | None; ICMPv6 echo request | +| `demo.pcap` | 9 | None; benign mixed traffic | +| `portscan.pcap` | 13 | One POSSIBLE_TCP_PORT_SCAN, observed count 12 | +| `synrate.pcap` | 101 | One HIGH_TCP_SYN_RATE, observed count 100; repeated same attempt | +| `icmp_rate.pcap` | 51 | One HIGH_ICMP_ECHO_RATE, observed count 50 | +| `concentration.pcap` | 41 | One CONNECTION_CONCENTRATION, observed count 40 | +| `sensitive.pcap` | 1 | One INFO SENSITIVE_SERVICE_TRAFFIC; policy WOULD_BLOCK for port 22 | +| `malformed.pcap` | 2 | No alerts; 1 truncated capture, 1 invalid IPv4 IHL | +| `mixed.pcap` | 21 | One POSSIBLE_TCP_PORT_SCAN; ARP, IPv4, IPv6, TCP, UDP, ICMP | +| `nanosecond.pcap` | 1 | Timestamp ends `.123456789Z` | +| `big_endian.pcap` | 1 | Valid alternate-byte-order PCAP | +| `empty.pcap` | 0 | Valid empty capture; rates null/not applicable | +| `out_of_order.pcap` | 2 | Error: nonchronological timestamps; no successful report | +| `unsupported_link.pcap` | 1 | Error: non-Ethernet link type | + +`expected.json` is consumed by integration tests for ordinary analyses. The special +byte-order, timestamp and error fixtures are asserted separately. Integration tests +also construct a short/corrupt file and PCAPNG magic in a temporary directory. + +```bash +python3 scripts/generate_fixtures.py +./build/packetforge analyze --pcap samples/mixed.pcap --report all +``` + +Randomized and crafted unit tests cover additional VLAN, options, extension-header, +fragmentation and invalid-length cases directly, rather than requiring a PCAP file +for every byte-level mutation. diff --git a/samples/demo.pcap b/samples/demo.pcap index 0b1aa5e619b8ce4b4a8eeedc12083a5b60186d25..9faa2be563838a0e741786d40235b185fdcdbeb8 100644 GIT binary patch delta 63 zcmbQmI*WC}G*QMc3=9lR0Yd-(EB6CgAA?gDv@uTnXvEFLz`*!5KmaH{Vd4vGC|3}q KY_lF?4kG}vJQgwl delta 63 zcmbQmI*WC}G*Jdd1|SF!`u|_G1<3dqoVuWmapFfKZiu)5P`qv83u`D>5Xf!atjCzc F2mn=A6Ey$; diff --git a/samples/mixed.pcap b/samples/mixed.pcap index b4eb6c9ecce65f43f701899472cf3937a523f3be..416593f723b4b577c06f86275b38d271a251eac0 100644 GIT binary patch delta 63 zcmaFN{g`{gG=9b}3=9lR0Yd-(EB6Cglk=F31sHdO#26SDzXk{Z#V1UBVa*NU3WAhv J)??ht0swlQ6p8=< delta 55 zcmaFN{g`{gG=2s~1|SF!`u|_G1<073$80>&hnrOZ$ZwnY!kQZ*EePbcZq{Sm$^rn{ CH4$9^ diff --git a/samples/normal_tcp.pcap b/samples/normal_tcp.pcap index 65074f9971565b7d323d77d18faf31394534bd31..2a04851883515333e6011609eacd6ee6be314965 100644 GIT binary patch delta 60 zcmdnMw1H{DG*QMc3=9lR0Yd-(EB6CgAA?gDv@uTnXvEFLz`*!5KmaH{Vd4vGUIjzLwMiDd`wl5%JT^S6_3s%8y znawuu8G;|+`5)XJFTD5T&l?`@eeycYsZ9S@nFs75(lL%#STLjE9JI(=0uiFSv?xzvT=R+AV%id`- zK)Km$1t`;x2xV)y6fnz0za5~Aca{T`^{)u!?70&#%gg0TfRYYY1C;6~LK%#@0kh1m z*Q8Q}bQi^U7sYoM#djCQcNfKX7sYoM#djCQcNfKX7sYoM#djCQcNfKX7sYoM#djCQ zcNfKX7sYoM#dkMzF7@U9cTs$IQG9n%e0NcNcTs$IQG9n%e0NcNcTs$IQG9n%e0NcN zcTs$IQG9n%e0NcNcTs$IQG9n%e0Lk1i|#Ip?=Fh(E{g9iitjFp?=Fh(E{g9iitjFp z?=Fh(E{g9iitjFp?=Fh(E{g9iitjFp?=Fh(E{gAN$+_t6qWJEj`0k?k?xOhaqWJEj y`0k?k?xOhaqWJEj`0k?k?xOhaqWJEj`0k?k?xOhaqWJEj`0k?k?lw6W-Q8boz@?}F literal 7094 zcmbW+$4`_|7{%dlh7O{r*sx(iuw(B!7F4XG*efdb2KEMG!;UDra{>Q=F>c+Ekhpf? z*2KLV+_}^DopW>C`khGzn1p$9r~U4G;al&g?qrl5{kvpG3BU2H?zn%OAFfHik<5He zx%587%iIRn1<}{SPPbEJ4FZm^%{PU;co&8`+x>ry#OUNj1p>(w+;;$vM z+>Fu*rLQ&_U&*rj;t{=pk}A%MuVkL$%vxSU>G&!rIb2Hzlpmeh@z;_|Nl8ARm) zl)je!@s+_;?nhBV?QSWRdr+kA4x!QtMe6QQDtDns-5o}y1&Y+&;Z&NTNZlPlvL*+UYsk>vTT!SKYx17pVC{lOFQMm#| z>h5?dm!U}Aoj~Oh6sfxtsWd^6x?4e|5sK8^NmMREk-A$+<${g2YIm!soQEQHcQTc8 zP^9iop>h_A)ZM96&Onj6JB`X|C{lN)Q#l1i>h26GC!t8)ok`^c6sfz_RE|TDx;u+X z0~D#dv#A_|B6W8Tm7`Fk?#`uh1d7z%c~t75NZs{AFHU@ip-A0bK;;k=sk;lQ9E2iu zcM+8XP^9iIrm`Q3)ZHai_C-;a+TEp8_Ck@myNt>nC{lNqQ`rqg>h20EyP!zjO;Oni zMe6QKDm$P^-Caec4vN&>)l{}ak-EEv$~GuccWbDmp-A0bOJyq*sk`f_Y=I(mcRiKO zP^9kGQrQGW>h1x$G}+v9^``@SnucWvGX zip?OdNZqyBCnz=#xgvGf=CGjHZ03s8U7HDmVsoM^Qg>}W4T{aIu1MXrSve>+Kf5B$ zyY*CTmUl(!uAL#mTI^imiqu^@&jiKJIIc+DwX;=F?7WrZ&x>9Bh~d|y-}s;ZtJyg( ID0cSy3oaq0r~m)} diff --git a/scripts/generate_fixtures.py b/scripts/generate_fixtures.py index 56fd469..e895590 100644 --- a/scripts/generate_fixtures.py +++ b/scripts/generate_fixtures.py @@ -28,8 +28,8 @@ def ipv4(payload, proto=6, src='192.0.2.10', dst='198.51.100.20', flags=0, optio header = header[:10] + struct.pack('!H', checksum(header)) + header[12:] return header + payload -def tcp(port=443, sport=40000, flags=2, seq=1, src='192.0.2.10', dst='198.51.100.20'): - segment = struct.pack('!HHIIBBHHH', sport, port, seq, 0, 0x50, flags, 65535, 0, 0) +def tcp(port=443, sport=40000, flags=2, seq=1, ack=0, src='192.0.2.10', dst='198.51.100.20'): + segment = struct.pack('!HHIIBBHHH', sport, port, seq, ack, 0x50, flags, 65535, 0, 0) pseudo = ipaddress.ip_address(src).packed + ipaddress.ip_address(dst).packed + struct.pack('!BBH',0,6,len(segment)) segment = segment[:16] + struct.pack('!H',checksum(pseudo+segment)) + segment[18:] return ethernet(ipv4(segment,src=src,dst=dst)) @@ -68,11 +68,11 @@ def write(name, packets, endian='<', nano=False, linktype=1): def generate(): (ROOT/'samples').mkdir(exist_ok=True) - normal=[tcp(),tcp(40000,443,0x12,src='198.51.100.20',dst='192.0.2.10'),tcp(flags=0x10),tcp(flags=0x11)] + normal=[tcp(),tcp(40000,443,0x12,seq=500,ack=2,src='198.51.100.20',dst='192.0.2.10'),tcp(flags=0x10,seq=2,ack=501),tcp(flags=0x11,seq=2,ack=501)] dns=struct.pack('!HHHHHH',1,0x0100,1,0,0,0)+b'\x07example\x04test\0'+struct.pack('!HH',1,1) cases={'normal_tcp.pcap':normal,'normal_udp_dns.pcap':[udp(),udp(dns,53)],'arp.pcap':[arp()], 'icmp.pcap':[icmp(),icmp(True)],'portscan.pcap':[tcp(port=1000+i) for i in range(13)], - 'synrate.pcap':[tcp(seq=i) for i in range(101)],'icmp_rate.pcap':[icmp() for _ in range(51)], + 'synrate.pcap':[tcp() for _ in range(101)],'icmp_rate.pcap':[icmp() for _ in range(51)], 'concentration.pcap':[tcp(sport=40000+i) for i in range(41)],'sensitive.pcap':[tcp(port=22)], 'ipv6.pcap':[ipv6()], 'demo.pcap':normal+[udp(dns,53),arp(),icmp(),icmp(True),ipv6()]} # Keep all rate scenarios inside the 10-second demonstration window. diff --git a/src/cli.cpp b/src/cli.cpp index 2665a38..84acb03 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -1,63 +1,138 @@ #include "packetforge/cli.hpp" -#include "packetforge/capture.hpp" +#include "packetforge/analysis.hpp" +#include "packetforge/reporting.hpp" +#include "rules.hpp" #include +#include #include +#include #include #include namespace packetforge { namespace { std::uint64_t number(const std::string& text) { - std::uint64_t value = 0; const auto parsed = std::from_chars(text.data(), text.data()+text.size(), value); - if (parsed.ec != std::errc{} || parsed.ptr != text.data()+text.size() || value == 0 || value > 1000000000) - throw std::runtime_error("expected positive integer <= 1000000000: " + text); + std::uint64_t value=0; const auto parsed=std::from_chars(text.data(),text.data()+text.size(),value); + if (parsed.ec!=std::errc{} || parsed.ptr!=text.data()+text.size() || value==0 || value>1000000000) + throw std::runtime_error("expected positive integer <= 1000000000: "+text); + return value; +} +double duration(const std::string& text) { + double value=0; const auto parsed=std::from_chars(text.data(),text.data()+text.size(),value); + if (parsed.ec!=std::errc{} || parsed.ptr!=text.data()+text.size() || !std::isfinite(value) || value<=0 || value>86400) + throw std::runtime_error("duration must be a number in (0, 86400] seconds"); return value; } void help() { - std::cout << "PacketForge | passive network packet analyzer\n" - "Usage: packetforge interfaces\n" - " packetforge capture --interface NAME [--count N] [--duration SECONDS] [--promiscuous] [--verbose]\n" - " packetforge analyze --pcap FILE [--count N] [--verbose]\n" - " packetforge --help\n" - "Offline analysis needs no privileges. Live capture requires CAP_NET_RAW.\n"; + std::cout << "PacketForge | Network Packet Analyzer & Intrusion Detection System\n" + "Author: Mayank Kumar Karn\n\n" + "Usage:\n packetforge interfaces\n" + " packetforge capture --interface NAME [--count N] [--duration SECONDS]\n" + " packetforge analyze --pcap FILE [--count N]\n\n" + "Analysis options:\n" + " --ids / --no-ids Enable (default) or disable metadata detection\n" + " --rules FILE Validated JSON overrides for rules, limits and policy\n" + " --policy Print Firewall Policy Simulation decisions\n" + " --verbose Packet metadata for each observed frame\n" + " --quiet Suppress immediate alerts; retain final summary/reports\n" + " --report FORMAT json, csv, html, or all\n" + " --output PREFIX Report path prefix (existing files are never overwritten)\n" + "Capture-only options:\n" + " --promiscuous Explicitly request socket-scoped promiscuous membership\n" + " --duration SECONDS Positive duration, up to 86400 seconds\n" + " --help Show this help\n\n" + "Offline analysis supports classic Ethernet PCAP without root or internet.\n" + "Live AF_PACKET capture needs CAP_NET_RAW on an authorized Linux interface.\n" + "PacketForge observes metadata; it never blocks, forwards or injects packets.\n" + "Compatibility: sniffer --interface NAME; forwarder --interface NAME (simulation).\n"; } } -int run_cli(int argc, char** argv, bool legacy, bool policy) { +int run_cli(int argc,char** argv,bool legacy,bool policy) { try { - if (argc < 2) { help(); return legacy ? 2 : 0; } - if (std::string(argv[1]) == "--help") { help(); return 0; } - std::string command = legacy ? "capture" : argv[1], path; - CaptureOptions options; bool verbose = false; - for (int i = legacy ? 1 : 2; i < argc; ++i) { - const std::string arg = argv[i]; - auto value = [&]() { if (++i >= argc) throw std::runtime_error("missing value for " + arg); return std::string(argv[i]); }; - if (arg == "--interface") options.interface = value(); - else if (arg == "--pcap") path = value(); - else if (arg == "--count") options.count = number(value()); - else if (arg == "--duration") options.duration = static_cast(number(value())); - else if (arg == "--promiscuous") options.promiscuous = true; - else if (arg == "--verbose") verbose = true; - else throw std::runtime_error("unknown option: " + arg); + if (argc<2) { help(); return legacy ? 2 : 0; } + if (std::string(argv[1])=="--help") { if (argc!=2) throw std::runtime_error("--help takes no arguments"); help(); return 0; } + const std::string command=legacy ? "capture" : argv[1]; + std::string path,rules_path,report_format,output; + CaptureOptions options; bool verbose=false,ids=true,quiet=false; + std::set seen; + for (int i=legacy ? 1 : 2;i=argc) throw std::runtime_error("missing value for "+arg); return std::string(argv[i]); }; + if (arg=="--interface") options.interface=value(); + else if (arg=="--pcap") path=value(); + else if (arg=="--count") options.count=number(value()); + else if (arg=="--duration") options.duration=duration(value()); + else if (arg=="--promiscuous") options.promiscuous=true; + else if (arg=="--verbose") verbose=true; + else if (arg=="--quiet") quiet=true; + else if (arg=="--ids") ids=true; + else if (arg=="--no-ids") ids=false; + else if (arg=="--policy") policy=true; + else if (arg=="--rules") rules_path=value(); + else if (arg=="--report") report_format=value(); + else if (arg=="--output") output=value(); + else if (arg=="--help" && argc==(legacy ? 2 : 3)) { help(); return 0; } + else throw std::runtime_error("unknown option: "+arg); } - if (command == "interfaces") { - if (argc != 2) throw std::runtime_error("interfaces takes no options"); + if (command=="interfaces") { + if (argc!=2) throw std::runtime_error("interfaces takes no options"); list_interfaces(); return 0; } - if (command != "capture" && command != "analyze") throw std::runtime_error("unknown command: " + command); - if (command == "capture" && (options.interface.empty() || !path.empty())) throw std::runtime_error("capture requires --interface and does not accept --pcap"); - if (command == "analyze" && (path.empty() || !options.interface.empty() || options.duration || options.promiscuous)) + if (command!="capture" && command!="analyze") throw std::runtime_error("unknown command: "+command); + if (command=="capture" && (options.interface.empty() || seen.count("--pcap"))) throw std::runtime_error("capture requires --interface and does not accept --pcap"); + if (command=="analyze" && (path.empty() || seen.count("--interface") || seen.count("--duration") || options.promiscuous)) throw std::runtime_error("analyze requires --pcap; capture-only options are invalid"); - std::cout << "PacketForge | " << command << " | " << (command == "capture" ? options.interface : path) << '\n'; + if (seen.count("--ids") && seen.count("--no-ids")) throw std::runtime_error("--ids and --no-ids conflict"); + if (!report_format.empty() && report_format!="json" && report_format!="csv" && report_format!="html" && report_format!="all") + throw std::runtime_error("--report must be json, csv, html or all"); + if (seen.count("--report") && report_format.empty()) throw std::runtime_error("empty report format"); + if (seen.count("--output") && (report_format.empty() || output.empty())) throw std::runtime_error("--output requires a nonempty prefix and --report"); + if (seen.count("--rules") && rules_path.empty()) throw std::runtime_error("empty rules path"); + const auto config=rules_path.empty() ? Config::defaults() : Config::load(rules_path); + Analysis analysis(config,ids); + const auto source=command=="capture" ? options.interface : path; + std::cout << "PacketForge | " << command << " | " << source << " | IDS " << (ids ? "enabled" : "disabled") << '\n'; + if (command=="capture") std::cout << "Capture: " << (options.promiscuous ? "promiscuous" : "non-promiscuous") << "; Ctrl+C stops gracefully\n"; if (policy) std::cout << "Firewall Policy Simulation: no traffic is blocked or forwarded\n"; - std::uint64_t packets = 0, bytes = 0; - auto consume = [&](const Packet& p) { - ++packets; bytes += p.captured_length; - if (verbose) std::cout << iso_time(p.timestamp) << ' ' << p.protocol_name() << ' ' << p.source << ':' - << p.source_port << " -> " << p.destination << ':' << p.destination_port << ' ' << status_name(p.status) << '\n'; - if (policy && p.transport) std::cout << "Source: " << p.source << " | Destination: " << p.destination << ':' - << p.destination_port << " | Policy: " << ((p.destination_port == 22 || p.destination_port == 445) ? "WOULD_BLOCK" : "WOULD_ALLOW") << '\n'; + auto emit=[&](const Json& alert) { + if (!quiet) std::cout << '[' << alert.at("severity").get() << "] " << alert.at("rule_id").get() << " | " + << alert.at("timestamp").get() << " | " << alert.at("source").get() << " -> " + << alert.at("destination").get() << " | observed=" << alert.at("observed_count") << " threshold=" + << alert.at("threshold") << " window=" << alert.at("detection_window_seconds") << "s\n"; + }; + auto consume=[&](const Packet& p) { + analysis.observe(p,emit); + if (verbose) { + std::cout << iso_time(p.timestamp) << ' ' << p.protocol_name() << " [" << p.source << "]:" << p.source_port + << " -> [" << p.destination << "]:" << p.destination_port << " cap=" << p.captured_length << " wire=" << p.wire_length + << " status=" << status_name(p.status); + if (p.ethernet) std::cout << " mac=" << p.source_mac << "->" << p.destination_mac << " ethertype=" << p.ethertype; + for (auto vlan:p.vlan_ids) std::cout << " vlan=" << vlan; + if (p.ipv4 || p.ipv6) std::cout << " ttl/hop=" << unsigned(p.ttl) << " protocol=" << unsigned(p.protocol); + if (p.fragmented) std::cout << " fragment_offset=" << p.fragment_offset << " more_fragments=" << p.more_fragments; + if (p.arp) std::cout << " arp_opcode=" << p.arp_opcode << " sender_hw=" << p.arp_sender_hardware << " target_hw=" << p.arp_target_hardware; + if (p.transport && (p.protocol==1 || p.protocol==58)) std::cout << " type=" << unsigned(p.icmp_type) << " code=" << unsigned(p.icmp_code); + if (p.protocol==6 && p.transport) std::cout << " flags=" << unsigned(p.tcp_flags) << " seq=" << p.sequence << " ack=" << p.acknowledgment; + if (!p.detail.empty()) std::cout << " (" << p.detail << ')'; + std::cout << '\n'; + } + if (policy && p.status==ParseStatus::ok && !p.source.empty()) std::cout << "Source: " << p.source << " | Destination: [" << p.destination << "]:" + << p.destination_port << " | Policy: " << evaluate_policy(p,config.policy) << '\n'; }; - if (command == "capture") capture_live(options, consume); else analyze_pcap(path, consume, options.count); - std::cout << "Packets: " << packets << " | Observed bytes: " << bytes << '\n'; return 0; - } catch (const std::exception& e) { std::cerr << "PacketForge error: " << e.what() << '\n'; return 2; } + auto tick=[&]() { + const auto now=std::max(now_timestamp(),analysis.statistics.last); analysis.flows.expire(now); analysis.detection.expire(now); + if (!quiet) std::cout << "[capture] packets=" << analysis.statistics.packets << " bytes=" << analysis.statistics.observed_bytes + << " active_flows=" << analysis.flows.active_count() << " alerts=" << analysis.total_alerts << std::endl; + }; + const auto result=command=="capture" ? capture_live(options,consume,tick) : analyze_pcap(path,consume,options.count); + if (command=="capture") analysis.flows.expire(std::max(now_timestamp(),analysis.statistics.last),true); + analysis.summary(std::cout); + if (command=="capture") std::cout << "Kernel capture drops: " << result.kernel_drops << " | Interrupted: " << (result.interrupted ? "yes" : "no") << '\n'; + if (!report_format.empty()) { + if (output.empty()) output="reports/packetforge-"+std::to_string(now_timestamp()); + for (const auto& report:write_reports(analysis.report(command,source,result),report_format,output)) std::cout << "Report: " << report << '\n'; + } + return 0; + } catch (const std::exception& error) { std::cerr << "PacketForge error: " << error.what() << '\n'; return 2; } } } diff --git a/src/detection/config.cpp b/src/detection/config.cpp new file mode 100644 index 0000000..b797d59 --- /dev/null +++ b/src/detection/config.cpp @@ -0,0 +1,125 @@ +#include "packetforge/config.hpp" +#include +#include +#include +namespace packetforge { +namespace { +void keys(const Json& value, const std::set& allowed, const std::string& context) { + if (!value.is_object()) throw std::runtime_error(context + " must be an object"); + for (auto it=value.begin(); it!=value.end(); ++it) + if (!allowed.count(it.key())) throw std::runtime_error("unknown " + context + " setting: " + it.key()); +} +std::int64_t integer(const Json& value, std::int64_t low, std::int64_t high, const std::string& name) { + if (!value.is_number_integer() || (value.is_number_unsigned() && value.get() > static_cast(high))) + throw std::runtime_error(name + " must be an integer in range"); + const auto result = value.get(); + if (result < low || result > high) throw std::runtime_error(name + " outside range " + std::to_string(low)+".."+std::to_string(high)); + return result; +} +std::string ip(const Json& value) { + if (!value.is_string()) throw std::runtime_error("IP exclusions/policy addresses must be strings"); + const auto text=value.get(); unsigned char buffer[16]{}; char out[INET6_ADDRSTRLEN]{}; + const int family = text.find(':') == std::string::npos ? AF_INET : AF_INET6; + if (inet_pton(family,text.c_str(),buffer)!=1) throw std::runtime_error("invalid literal IP address: "+text); + inet_ntop(family,buffer,out,sizeof(out)); return out; +} +std::set exclusions(const Json& value) { + if (!value.is_array() || value.size()>4096) throw std::runtime_error("exclusions must be an array of at most 4096 IPs"); + std::set result; for (const auto& entry:value) result.insert(ip(entry)); return result; +} +} +Config Config::defaults() { + Config c; + c.rules["POSSIBLE_TCP_PORT_SCAN"] = {true,12,10,30,"MEDIUM",{},{},{}}; + c.rules["HIGH_TCP_SYN_RATE"] = {true,100,10,30,"MEDIUM",{},{},{}}; + c.rules["HIGH_ICMP_ECHO_RATE"] = {true,50,10,30,"LOW",{},{},{}}; + c.rules["SENSITIVE_SERVICE_TRAFFIC"] = {true,1,10,60,"INFO",{22,23,445,3389},{},{}}; + c.rules["CONNECTION_CONCENTRATION"] = {true,40,10,30,"LOW",{},{},{}}; + c.policy = {{"any","any","WOULD_BLOCK",22},{"any","any","WOULD_BLOCK",445},{"any","any","WOULD_ALLOW",-1}}; + return c; +} +Config Config::load(const std::string& path) { + Config config=defaults(); std::ifstream file(path, std::ios::binary); + if (!file) throw std::runtime_error("cannot open rules file: "+path); + file.seekg(0,std::ios::end); if (file.tellg()>1024*1024) throw std::runtime_error("rules file exceeds 1 MiB"); file.seekg(0); + Json root; + // Reject duplicate JSON keys; silently taking the last value is dangerous for rules. + std::vector> object_keys; + auto callback=[&](int depth, Json::parse_event_t event, Json& parsed) { + if (depth>32) throw std::runtime_error("configuration nesting exceeds limit"); + if (event==Json::parse_event_t::object_start) object_keys.emplace_back(); + if (event==Json::parse_event_t::key && !object_keys.back().insert(parsed.get()).second) + throw std::runtime_error("duplicate JSON key: "+parsed.get()); + if (event==Json::parse_event_t::object_end) object_keys.pop_back(); + if (object_keys.size()>32) throw std::runtime_error("configuration nesting exceeds limit"); + return true; + }; + root=Json::parse(file,callback); + keys(root,{"rules","limits","policy"},"configuration"); + if (root.contains("limits")) { + const auto& limits=root.at("limits"); + keys(limits,{"max_flows","max_unique_flows","max_talkers","max_rule_keys","max_rule_events","max_alerts","flow_timeout_seconds"},"limits"); + auto set=[&](const char* name,std::size_t& target,std::int64_t maximum) { + if (limits.contains(name)) target=static_cast(integer(limits.at(name),1,maximum,name)); + }; + set("max_flows",config.max_flows,100000); set("max_unique_flows",config.max_unique_flows,1000000); + set("max_talkers",config.max_talkers,100000); set("max_rule_keys",config.max_rule_keys,10000); + set("max_rule_events",config.max_rule_events,1000000); set("max_alerts",config.max_alerts,100000); + if (limits.contains("flow_timeout_seconds")) config.flow_timeout_seconds=integer(limits.at("flow_timeout_seconds"),1,86400,"flow_timeout_seconds"); + } + if (root.contains("rules")) { + std::set names; for (const auto& item:config.rules) names.insert(item.first); + keys(root.at("rules"),names,"rules"); + for (auto it=root.at("rules").begin(); it!=root.at("rules").end(); ++it) { + const auto& object=it.value(); auto& rule=config.rules.at(it.key()); + keys(object,{"enabled","threshold","window_seconds","cooldown_seconds","severity","ports","exclude_sources","exclude_destinations"},it.key()); + if (object.contains("enabled")) { if (!object.at("enabled").is_boolean()) throw std::runtime_error("enabled must be boolean"); rule.enabled=object.at("enabled").get(); } + if (object.contains("threshold")) rule.threshold=static_cast(integer(object.at("threshold"),1,10000,"threshold")); + if (object.contains("window_seconds")) rule.window_seconds=integer(object.at("window_seconds"),1,3600,"window_seconds"); + if (object.contains("cooldown_seconds")) rule.cooldown_seconds=integer(object.at("cooldown_seconds"),0,86400,"cooldown_seconds"); + if (object.contains("severity")) rule.severity=object.at("severity").get(); + if (!std::set{"INFO","LOW","MEDIUM","HIGH"}.count(rule.severity)) throw std::runtime_error("invalid severity: "+rule.severity); + if (object.contains("ports")) { + if (it.key()!="SENSITIVE_SERVICE_TRAFFIC") throw std::runtime_error("ports is only valid for SENSITIVE_SERVICE_TRAFFIC"); + const auto& ports=object.at("ports"); + if (!ports.is_array() || ports.empty() || ports.size()>1024) throw std::runtime_error("ports must contain 1..1024 integers"); + rule.ports.clear(); for (const auto& port:ports) rule.ports.insert(static_cast(integer(port,1,65535,"port"))); + } + if (object.contains("exclude_sources")) rule.exclude_sources=exclusions(object.at("exclude_sources")); + if (object.contains("exclude_destinations")) rule.exclude_destinations=exclusions(object.at("exclude_destinations")); + if (rule.threshold>config.max_rule_events) throw std::runtime_error("rule threshold exceeds max_rule_events"); + if (it.key()=="POSSIBLE_TCP_PORT_SCAN" && rule.threshold<2) throw std::runtime_error("port-scan threshold must be >= 2"); + } + } + for (const auto& [id,rule]:config.rules) + if (rule.enabled && rule.threshold>config.max_rule_events) throw std::runtime_error(id+" threshold exceeds max_rule_events"); + if (root.contains("policy")) { + if (!root.at("policy").is_array() || root.at("policy").size()>1024) throw std::runtime_error("policy must be an array of at most 1024 rules"); + config.policy.clear(); + for (const auto& item:root.at("policy")) { + keys(item,{"source","destination","destination_port","action"},"policy"); PolicyRule rule; + if (item.contains("source") && item.at("source")!="any") rule.source=ip(item.at("source")); + if (item.contains("destination") && item.at("destination")!="any") rule.destination=ip(item.at("destination")); + if (item.contains("destination_port")) rule.destination_port=static_cast(integer(item.at("destination_port"),-1,65535,"destination_port")); + rule.action=item.at("action").get(); + if (rule.action!="WOULD_ALLOW" && rule.action!="WOULD_BLOCK") throw std::runtime_error("policy action must be WOULD_ALLOW or WOULD_BLOCK"); + config.policy.push_back(rule); + } + } + return config; +} +Json Config::json() const { + Json result; result["rules"]=Json::object(); + for (const auto& [id,r]:rules) { + result["rules"][id]={{"enabled",r.enabled},{"threshold",r.threshold},{"window_seconds",r.window_seconds}, + {"cooldown_seconds",r.cooldown_seconds},{"severity",r.severity}, + {"exclude_sources",r.exclude_sources},{"exclude_destinations",r.exclude_destinations}}; + if (id=="SENSITIVE_SERVICE_TRAFFIC") result["rules"][id]["ports"]=r.ports; + } + result["limits"]={{"max_flows",max_flows},{"max_unique_flows",max_unique_flows},{"max_talkers",max_talkers}, + {"max_rule_keys",max_rule_keys},{"max_rule_events",max_rule_events},{"max_alerts",max_alerts},{"flow_timeout_seconds",flow_timeout_seconds}}; + result["policy"]=Json::array(); + for (const auto& r:policy) result["policy"].push_back({{"source",r.source},{"destination",r.destination},{"destination_port",r.destination_port},{"action",r.action}}); + return result; +} +} diff --git a/src/detection/detection.cpp b/src/detection/detection.cpp new file mode 100644 index 0000000..9f7a99b --- /dev/null +++ b/src/detection/detection.cpp @@ -0,0 +1,104 @@ +#include "packetforge/detection.hpp" +#include +#include +#include +namespace packetforge { +void DetectionEngine::trim(State& state, Runtime& runtime, Timestamp now, const RuleConfig& rule) { + // Half-open window (now-window, now]; events at the left boundary expire. + while (!state.events.empty() && now-state.events.front().time>=rule.window_seconds*second) { + state.events.pop_front(); --runtime.events; + } +} +void DetectionEngine::expire(Timestamp now) { + if (last_sweep_>=0 && now-last_sweep_second,runtime,now,rule); + if (it->second.events.empty() && (!it->second.alerted || now-it->second.last_alert>=rule.cooldown_seconds*second)) + it=runtime.states.erase(it); + else ++it; + } + } +} +std::vector DetectionEngine::observe(const Packet& p) { + expire(p.timestamp); std::vector alerts; + if (p.status!=ParseStatus::ok || !p.transport || p.fragmented) return alerts; + for (const auto& [id,rule]:config_.rules) { + if (!rule.enabled || rule.exclude_sources.count(p.source) || rule.exclude_destinations.count(p.destination)) continue; + const bool sensitive=id=="SENSITIVE_SERVICE_TRAFFIC", concentration=id=="CONNECTION_CONCENTRATION"; + if (sensitive) { + if ((p.protocol!=6 && p.protocol!=17) || (!rule.ports.count(p.source_port) && !rule.ports.count(p.destination_port))) continue; + } else if (id=="HIGH_ICMP_ECHO_RATE") { if (!p.echo_request) continue; } + else if (!p.syn_attempt()) continue; + auto& runtime=runtime_.at(id); ++runtime.matched; + const auto service_port=rule.ports.count(p.destination_port) ? p.destination_port : p.source_port; + std::string key=concentration ? p.source : p.source+"|"+p.destination; + if (sensitive) key+="|"+std::to_string(p.protocol)+"|"+std::to_string(service_port); + auto found=runtime.states.find(key); + if (found==runtime.states.end()) { + if (runtime.states.size()>=config_.max_rule_keys) { ++runtime.dropped_keys; continue; } + found=runtime.states.emplace(key,State{}).first; + } + auto& state=found->second; trim(state,runtime,p.timestamp,rule); state.last_seen=p.timestamp; + if (runtime.events>=config_.max_rule_events) { ++runtime.dropped_events; continue; } + const auto attempt=p.destination+"|"+std::to_string(p.source_port)+"|"+std::to_string(p.destination_port)+"|"+std::to_string(p.sequence); + state.events.push_back({p.timestamp,p.destination_port,p.destination,attempt}); ++runtime.events; + std::set ports; + std::set attempts,destinations; + std::map> ports_by_host; + for (const auto& event:state.events) { + ports.insert(event.port); destinations.insert(event.destination); + if (concentration) { attempts.insert(event.attempt); ports_by_host[event.destination].insert(event.port); } + } + const std::size_t count=id=="POSSIBLE_TCP_PORT_SCAN" ? ports.size() : concentration ? attempts.size() : state.events.size(); + if (count=scan.threshold) scan_shape=true; + if (scan_shape) { ++runtime.scan_suppressed; continue; } + } + if (state.alerted && (p.timestamp-state.last_alert(0,p.timestamp-rule.window_seconds*second))}, + {"window_end",iso_time(p.timestamp)},{"window_interval","(start, end]"}}; + if (concentration) evidence["distinct_connection_attempts"]=attempts.size(); + if (sensitive) evidence["observed_service_port"]=service_port; + if (p.protocol==6) evidence["trigger_tcp_flags"]=p.tcp_flags; + const std::string limitation=sensitive ? "Informational observation only. Service access can be authorized; port number does not prove application identity." + : id=="HIGH_ICMP_ECHO_RATE" ? "Heuristic only. Monitoring and diagnostics can generate echo bursts." + : id=="HIGH_TCP_SYN_RATE" ? "Heuristic only. Retransmissions, busy clients and capture duplicates can raise SYN counts; this does not confirm denial of service." + : "Heuristic only. Authorized scanning, retries, NAT aggregation and incomplete visibility can produce similar metadata; no compromise is confirmed."; + alerts.push_back({{"alert_id",alert_id.str()},{"rule_id",id},{"title",title},{"timestamp",iso_time(p.timestamp)}, + {"timestamp_ns",p.timestamp},{"severity",rule.severity},{"source",p.source}, + {"destination",concentration && destinations.size()>1 ? "multiple observed destinations" : p.destination}, + {"source_port",p.source_port},{"destination_port",p.destination_port},{"detection_window_seconds",rule.window_seconds}, + {"observed_count",count},{"threshold",rule.threshold},{"evidence",evidence},{"confidence","metadata heuristic"}, + {"limitations",limitation},{"recommendation",sensitive ? "Confirm that service access matches policy and inspect authorized service logs." + : "Validate against the traffic baseline, approved scans and endpoint/service logs before responding."}, + {"mitre_technique",id=="POSSIBLE_TCP_PORT_SCAN" ? Json("T1046 - Network Service Discovery") : Json(nullptr)}}); + } + return alerts; +} +Json DetectionEngine::counters() const { + Json counters=Json::object(); + for (const auto& [id,runtime]:runtime_) counters[id]={{"matched_packets",runtime.matched},{"alerts",runtime.alerts}, + {"cooldown_suppressed",runtime.cooldown_suppressed},{"scan_overlap_suppressed",runtime.scan_suppressed}, + {"dropped_events",runtime.dropped_events},{"dropped_keys",runtime.dropped_keys}, + {"retained_events",runtime.events},{"retained_keys",runtime.states.size()}}; + return counters; +} +} diff --git a/src/flows/flows.cpp b/src/flows/flows.cpp new file mode 100644 index 0000000..3ece9a8 --- /dev/null +++ b/src/flows/flows.cpp @@ -0,0 +1,48 @@ +#include "packetforge/flows.hpp" +#include +namespace packetforge { +Json Flow::json() const { + return {{"source",key.source},{"destination",key.destination},{"source_port",key.source_port}, + {"destination_port",key.destination_port},{"protocol",key.protocol},{"packets",packets}, + {"observed_bytes",observed_bytes},{"wire_bytes",wire_bytes},{"first_seen",iso_time(first)}, + {"last_seen",iso_time(last)},{"first_seen_ns",first},{"last_seen_ns",last}, + {"duration_seconds",static_cast(last-first)/second},{"tcp_flags",tcp_flags}, + {"direction","source_to_destination"}}; +} +void FlowTable::archive(std::map::iterator entry) { + if (closed_.size()==config_.max_flows) { closed_.pop_front(); ++archives_discarded; } + closed_.push_back(entry->second); active_.erase(entry); +} +void FlowTable::expire(Timestamp now, bool force) { + if (!force && last_sweep_>=0 && now-last_sweep_second.last>=config_.flow_timeout_seconds*second) { auto old=it++; archive(old); ++expired; } + else ++it; + } +} +void FlowTable::observe(const Packet& p) { + expire(p.timestamp); + if (p.status!=ParseStatus::ok || !p.transport || p.fragmented || (p.protocol!=6 && p.protocol!=17)) return; + FlowKey key{p.source,p.destination,p.source_port,p.destination_port,p.protocol}; + if (!unique_.count(key)) { + if (unique_.size()second; ++f.packets; f.observed_bytes+=p.captured_length; f.wire_bytes+=p.wire_length; + f.last=p.timestamp; f.tcp_flags|=p.tcp_flags; +} +Json FlowTable::json() const { + Json flows=Json::array(); + for (const auto& flow:closed_) { auto j=flow.json(); j["active"]=false; flows.push_back(std::move(j)); } + for (const auto& [key,flow]:active_) { (void)key; auto j=flow.json(); j["active"]=true; flows.push_back(std::move(j)); } + return flows; +} +} diff --git a/src/parsers/packet.cpp b/src/parsers/packet.cpp index 28f4e35..b9afbaa 100644 --- a/src/parsers/packet.cpp +++ b/src/parsers/packet.cpp @@ -122,7 +122,10 @@ Packet parse_packet(const std::uint8_t* data, std::size_t size, std::uint32_t wi malformed(p.protocol == 0 && extensions != 1, "hop-by-hop header must be first"); if (end - o < 2) throw Failure{ParseStatus::malformed, "IPv6 extension exceeds payload"}; std::size_t length = (std::size_t(b.u8(o+1)) + 1) * 8; - if (p.protocol == 51) length = (std::size_t(b.u8(o+1)) + 2) * 4; + if (p.protocol == 51) { + length = (std::size_t(b.u8(o+1)) + 2) * 4; + malformed(length < 12, "IPv6 AH header smaller than fixed fields"); + } if (p.protocol == 44) { malformed(seen_fragment, "duplicate IPv6 fragment header"); seen_fragment = true; length = 8; malformed(end - o < length, "IPv6 fragment exceeds payload"); b.need(o, length); diff --git a/src/reporting/reporting.cpp b/src/reporting/reporting.cpp new file mode 100644 index 0000000..b89f912 --- /dev/null +++ b/src/reporting/reporting.cpp @@ -0,0 +1,125 @@ +#include "packetforge/reporting.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +namespace packetforge { +std::string html_escape(const std::string& value) { + std::string result; + for (char c:value) switch (c) { + case '&':result+="&";break; case '<':result+="<";break; case '>':result+=">";break; + case '"':result+=""";break; case '\'':result+="'";break; default:result+=c; + } + return result; +} +std::string csv_field(const std::string& value) { + std::string result="\""; + // Prevent spreadsheet formula execution as well as ordinary CSV quoting. + if (!value.empty() && (value[0]=='=' || value[0]=='+' || value[0]=='-' || value[0]=='@' || value[0]=='\t' || value[0]=='\r' || value[0]=='\n')) result+='\''; + for (char c:value) { if (c=='"') result+='"'; result+=c; } result+='"'; return result; +} +namespace { +std::string value(const Json& j) { return j.is_string() ? j.get() : j.dump(); } +std::string table(const Json& rows,const std::vector& columns) { + std::ostringstream out; out << "
"; + for (const auto& column:columns) out << ""; + out << ""; + for (const auto& row:rows) { + out << ""; for (const auto& column:columns) out << ""; out << ""; + } + out << "
" << html_escape(column) << "
" << html_escape(value(row.at(column))) << "
"; return out.str(); +} +std::string csv(const Json& rows,const std::vector& columns) { + std::ostringstream out; + for (std::size_t i=0;i + +PacketForge — Investigation Report

Network security investigation

PacketForge

Passive packet analysis · Explainable intrusion detection

)HTML"; + out << "

Mode: " << html_escape(value(metadata.at("mode"))) << " · Source: " << html_escape(value(metadata.at("source"))) << "

" + << "

" << html_escape(value(metadata.at("first_packet"))) << " → " << html_escape(value(metadata.at("last_packet"))) << "

"; + out << "
"; + for (const auto& key:{"packets","observed_bytes","unique_flows","total_ids_alerts"}) + out << "
" << key << "" << html_escape(value(stats.at(key))) << "
"; + out << "

Protocol distribution

Layer counters overlap; Ethernet, IP and transport counts are not additive.

"; + const double total=stats.at("packets").get(); + for (const auto& [name,count]:stats.at("protocols").items()) out << "
" << html_escape(name) << " " << count + << "
"; + out << "

Top sources

" << table(stats.at("top_sources"),{"address","packets"}) + << "

Top destinations

" << table(stats.at("top_destinations"),{"address","packets"}) + << "

Destination ports

" << table(stats.at("destination_ports"),{"port","packets"}) << "

Security observations

"; + if (data.at("alerts").empty()) out << "

No alerts were retained. This does not establish that traffic is safe. IDS enabled: " << metadata.at("ids_enabled") << ".

"; + for (const auto& alert:data.at("alerts")) { + out << "
" << html_escape(value(alert.at("severity"))) << "

" << html_escape(value(alert.at("title"))) + << "

" << html_escape(value(alert.at("alert_id"))) << " · " << html_escape(value(alert.at("rule_id"))) << "

" + << html_escape(value(alert.at("timestamp"))) << " · " << html_escape(value(alert.at("source"))) << " → " << html_escape(value(alert.at("destination"))) + << "

Observed " << alert.at("observed_count") << " / threshold " << alert.at("threshold") << " within " << alert.at("detection_window_seconds") << " seconds.

" + << "
" << html_escape(alert.at("evidence").dump(2)) << "

" << html_escape(value(alert.at("limitations"))) + << "

Recommendation: " << html_escape(value(alert.at("recommendation"))) << "

MITRE: " << html_escape(value(alert.at("mitre_technique"))) << "

"; + } + out << "

Directional flows

" << table(data.at("flows"),{"source","source_port","destination","destination_port","protocol","packets","observed_bytes","duration_seconds","active"}); + for (const auto& section:{"statistics","metadata","rules","rule_counters"}) + out << "

" << section << "

" << html_escape(data.at(section).dump(2)) << "
"; + out << "

Investigation limitations

    "; + for (const auto& limitation:data.at("limitations")) out << "
  • " << html_escape(value(limitation)) << "
  • "; + out << "
PacketForge · Mayank Kumar Karn
Exported " << html_escape(value(metadata.at("export_timestamp"))) + << " · Standalone offline report
"; return out.str(); +} +std::vector write_reports(const Json& data,const std::string& format,const std::string& prefix) { + if (format!="json" && format!="csv" && format!="html" && format!="all") throw std::runtime_error("invalid report format"); + std::vector> files; + if (format=="json" || format=="all") files.emplace_back(prefix+".json",data.dump(2)+"\n"); + if (format=="html" || format=="all") files.emplace_back(prefix+".html",html_report(data)); + if (format=="csv" || format=="all") { + files.emplace_back(prefix+"-alerts.csv",csv(data.at("alerts"),{"alert_id","rule_id","title","timestamp","severity","source","destination","source_port","destination_port","detection_window_seconds","observed_count","threshold","evidence","confidence","limitations","recommendation","mitre_technique"})); + files.emplace_back(prefix+"-flows.csv",csv(data.at("flows"),{"source","destination","source_port","destination_port","protocol","packets","observed_bytes","wire_bytes","first_seen","last_seen","duration_seconds","tcp_flags","active"})); + } + // Refuse overwrites so reports cannot accidentally destroy an input/config file. + for (const auto& [path,content]:files) { (void)content; if (std::filesystem::exists(path)) throw std::runtime_error("report already exists: "+path+"; choose another --output prefix"); } + std::vector paths; + for (const auto& [path,content]:files) { + const auto parent=std::filesystem::path(path).parent_path(); if (!parent.empty()) std::filesystem::create_directories(parent); + // Exclusive creation closes the race between the preflight check and writing. + // Investigation metadata is private to the owner on POSIX filesystems. + const int fd=::open(path.c_str(),O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC,0600); + if (fd<0) throw std::runtime_error("cannot create report: "+path+": "+std::strerror(errno)); + struct File { int fd; ~File() { if (fd>=0) ::close(fd); } } file{fd}; + std::size_t offset=0; + while (offset(written); + } + const int closed=::close(fd); file.fd=-1; + if (closed<0) throw std::runtime_error("report close failed: "+path); + paths.push_back(path); + } + return paths; +} +} diff --git a/src/statistics/analysis.cpp b/src/statistics/analysis.cpp new file mode 100644 index 0000000..1ecb9c6 --- /dev/null +++ b/src/statistics/analysis.cpp @@ -0,0 +1,59 @@ +#include "packetforge/analysis.hpp" +#include +#include +#include +namespace packetforge { +void Analysis::observe(const Packet& p,const std::function& emit) { + if (p.timestamp<0 || p.timestamp()]; + if (emit) emit(alert); + if (alerts.size()() : item["port"].dump()) << '=' << item["packets"]; + out << '\n'; + } + for (const auto& [id,count]:alert_counts) out << " " << id << ": " << count << '\n'; + if (flows.evictions || flows.archives_discarded || statistics.omitted_sources || statistics.omitted_destinations || alerts_not_retained) + out << "Warning: retention limits reached; review report counters for omitted evidence.\n"; + const auto counters=detection.counters(); + for (const auto& [id,counter]:counters.items()) + if (counter["dropped_keys"].get() || counter["dropped_events"].get()) + out << "Warning: " << id << " hit a state limit; detections can be missed.\n"; +} +} diff --git a/src/statistics/statistics.cpp b/src/statistics/statistics.cpp new file mode 100644 index 0000000..ccd6fff --- /dev/null +++ b/src/statistics/statistics.cpp @@ -0,0 +1,48 @@ +#include "packetforge/statistics.hpp" +#include +namespace packetforge { +void Statistics::talker(std::map& table,const std::string& address,std::uint64_t& omitted) { + if (address.empty()) return; + auto it=table.find(address); + if (it!=table.end()) ++it->second; + else if (table.size()(last-first)/second : 0; } +Json Statistics::json() const { + auto top=[](const auto& values) { + std::vector> rows(values.begin(),values.end()); + std::sort(rows.begin(),rows.end(),[](const auto& a,const auto& b) { return a.second!=b.second ? a.second>b.second : a.first(rows.size(),10);++i) out.push_back({{"address",rows[i].first},{"packets",rows[i].second}}); + return out; + }; + Json destination_ports=Json::array(); + std::vector> ranked(ports.begin(),ports.end()); + std::sort(ranked.begin(),ranked.end(),[](const auto& a,const auto& b) { return a.second!=b.second ? a.second>b.second : a.first(ranked.size(),10);++i) destination_ports.push_back({{"port",ranked[i].first},{"packets",ranked[i].second}}); + const auto seconds=duration(); + return {{"packets",packets},{"observed_bytes",observed_bytes},{"wire_bytes",wire_bytes},{"truncated",truncated}, + {"malformed",malformed},{"unsupported",unsupported},{"duration_seconds",seconds}, + {"packets_per_second",seconds>0 ? Json(static_cast(packets)/seconds) : Json(nullptr)}, + {"bytes_per_second",seconds>0 ? Json(static_cast(observed_bytes)/seconds) : Json(nullptr)}, + {"protocols",protocols},{"top_sources",top(sources)},{"top_destinations",top(destinations)}, + {"destination_ports",destination_ports},{"omitted_source_observations",omitted_sources}, + {"omitted_destination_observations",omitted_destinations}}; +} +} diff --git a/tests/integration.py b/tests/integration.py index 0344485..169bd75 100644 --- a/tests/integration.py +++ b/tests/integration.py @@ -1,14 +1,110 @@ #!/usr/bin/env python3 +"""End-to-end offline checks; no root, third-party Python packages or network needed.""" +import csv +import json +from pathlib import Path import subprocess import sys -binary = sys.argv[1] -for args, expected in [(['--help'], 0), (['interfaces'], 0), (['analyze'], 2), - (['analyze', '--pcap', 'missing.pcap'], 2), - (['capture', '--count', '-1'], 2), (['wat'], 2)]: - result = subprocess.run([binary] + args, capture_output=True, text=True) - assert result.returncode == expected, (args, result.stdout, result.stderr) -from pathlib import Path -root = Path(sys.argv[2]) -result = subprocess.run([binary, 'analyze', '--pcap', str(root/'samples/demo.pcap')], capture_output=True, text=True) -assert result.returncode == 0 and 'Packets: 9' in result.stdout, (result.stdout, result.stderr) -print('CLI and offline PCAP checks passed') +import tempfile + +binary = Path(sys.argv[1]).resolve() +root = Path(sys.argv[2]).resolve() +checks = 0 + +def run(args, code=0): + global checks + result = subprocess.run([str(binary)] + list(map(str,args)), capture_output=True, text=True) + checks += 1 + assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr) + return result + +run(['--help']) +for args in [['analyze'], ['analyze','--pcap','missing.pcap'], ['capture','--count','-1'], ['wat'], + ['analyze','--pcap',root/'samples/demo.pcap','--duration','1'], + ['capture','--interface','lo','--duration','nan'],['capture','--interface','lo','--duration','0'], + ['analyze','--pcap',root/'samples/demo.pcap','--count','1x'], + ['analyze','--pcap',root/'samples/demo.pcap','--ids','--no-ids'], + ['analyze','--pcap',root/'samples/demo.pcap','--ids','--ids'], + ['analyze','--pcap',root/'samples/demo.pcap','--report','pdf'], + ['analyze','--pcap',root/'samples/demo.pcap','--output','foo'], + ['interfaces','--count','1']]: + run(args,2) + +with tempfile.TemporaryDirectory(prefix='packetforge-tests-') as temp: + temp = Path(temp) + expected = json.loads((root/'samples/expected.json').read_text()) + for name, case in expected.items(): + prefix = temp / name + result = run(['analyze','--pcap',root/'samples'/name,'--rules',root/'config/rules.json','--report','all','--output',prefix]) + report = json.loads(Path(str(prefix)+'.json').read_text()) + assert report['statistics']['packets'] == case['packets'], name + assert sorted(a['rule_id'] for a in report['alerts']) == sorted(case['alerts']), (name,report['alerts']) + assert report['metadata']['ids_enabled'] is True + assert report['statistics']['total_ids_alerts'] == len(case['alerts']) + for alert in report['alerts']: + assert alert['observed_count'] >= alert['threshold'] + for key in ['alert_id','rule_id','title','timestamp','severity','source','destination', + 'detection_window_seconds','observed_count','threshold','evidence','confidence', + 'limitations','recommendation','mitre_technique']: + assert key in alert, (name,key) + with Path(str(prefix)+'-alerts.csv').open(newline='') as stream: + rows = list(csv.DictReader(stream)) + assert len(rows) == len(report['alerts']) + if rows: assert json.loads(rows[0]['evidence']) == report['alerts'][0]['evidence'] + with Path(str(prefix)+'-flows.csv').open(newline='') as stream: + assert len(list(csv.DictReader(stream))) == len(report['flows']) + html = Path(str(prefix)+'.html').read_text() + assert '

PacketForge

' in html and 'Investigation limitations' in html + assert '.pcap' + evil.write_bytes((root/'samples/demo.pcap').read_bytes()) + run(['analyze','--pcap',evil,'--report','html','--output',temp/'escaped']) + html=(temp/'escaped.html').read_text() + assert ' +#include #include #include #include @@ -31,6 +36,169 @@ void parser_tests() { b=tcp(); b[23]=99; check(parse(b).status==ParseStatus::unsupported,"unsupported protocol"); check(parse_packet(nullptr,0,0,0).status==ParseStatus::truncated,"empty buffer"); } +void protocol_tests() { + auto b=tcp(); b[47]=0x3f; auto p=parse(b); + check(p.tcp_flags==0x3f && !p.syn_attempt(),"TCP flags including FIN/SYN/RST/PSH/ACK/URG"); + b[47]=0x12; check(!parse(b).syn_attempt(),"SYN ACK not initiation"); + b=tcp(); b.insert(b.begin()+12,{0x88,0xa8,0,1,0x81,0,0,2}); p=parse(b); + check(p.vlan_ids==std::vector({1,2}) && p.destination_port==443,"double VLAN"); + b.insert(b.begin()+12,{0x81,0,0,3}); check(parse(b).status==ParseStatus::unsupported,"VLAN depth limit"); + b=tcp(); b.resize(42); b[23]=17; put16(b,16,28); put16(b,38,8); p=parse(b); + check(p.transport && p.udp_length==8 && p.destination_port==443,"UDP decode"); + put16(b,38,7); check(parse(b).status==ParseStatus::malformed,"UDP short length"); + put16(b,38,9); check(parse(b).status==ParseStatus::malformed,"UDP long length"); + b=tcp(); b.resize(42); b[23]=1; put16(b,16,28); b[34]=8; b[35]=0; p=parse(b); + check(p.echo_request && p.icmp_code==0 && p.transport,"ICMP request"); + b[34]=0; check(parse(b).echo_reply,"ICMP reply"); + b[35]=1; check(!parse(b).echo_reply,"ICMP echo code validation"); + b.assign(42,0); put16(b,12,0x0806); put16(b,14,1); put16(b,16,0x0800); b[18]=6; b[19]=4; + put16(b,20,1); b[22]=2; b[28]=192; b[30]=2; b[31]=10; b[38]=192; b[40]=2; b[41]=20; p=parse(b); + check(p.arp && p.arp_opcode==1 && p.source=="192.0.2.10" && p.destination=="192.0.2.20","ARP fields"); + check(p.arp_sender_hardware=="02:00:00:00:00:00" && p.arp_target_hardware=="00:00:00:00:00:00","ARP MACs"); + b[19]=16; check(parse(b).status==ParseStatus::truncated,"ARP variable length bounds"); + b.assign(62,0); put16(b,12,0x86dd); b[14]=0x60; put16(b,18,8); b[20]=58; b[21]=64; + b[22]=0x20;b[23]=1;b[24]=0x0d;b[25]=0xb8;b[37]=1; + b[38]=0x20;b[39]=1;b[40]=0x0d;b[41]=0xb8;b[53]=2;b[54]=128; p=parse(b); + check(p.ipv6 && p.echo_request && p.source=="2001:db8::1" && p.destination=="2001:db8::2" && p.ttl==64,"IPv6 ICMP"); + auto ipv6=b; b.insert(b.begin()+54,8,0); b[20]=0; b[54]=58; put16(b,18,16); p=parse(b); + check(p.status==ParseStatus::ok && p.next_header==0 && p.protocol==58 && p.echo_request,"IPv6 hop-by-hop extension"); + b[55]=3; check(parse(b).status==ParseStatus::malformed,"IPv6 extension payload bounds"); + b=ipv6; b.insert(b.begin()+54,8,0); b[20]=44; b[54]=58; put16(b,18,16); put16(b,56,8); p=parse(b); + check(p.fragmented && p.fragment_offset==8 && !p.transport,"IPv6 noninitial fragment"); + put16(b,56,0); p=parse(b); check(!p.fragmented && p.echo_request,"IPv6 atomic fragment"); + b=ipv6; b[20]=50; check(parse(b).status==ParseStatus::unsupported,"IPv6 ESP explicit unsupported"); + b=ipv6; put16(b,18,0); check(parse(b).status==ParseStatus::unsupported,"jumbogram unsupported"); + b=ipv6; b.resize(54); put16(b,18,0); b[20]=59; check(parse(b).status==ParseStatus::ok,"IPv6 no next header"); + b=tcp(); b.resize(58); put16(b,16,44); put16(b,20,0x2000); p=parse(b); + check(p.status==ParseStatus::ok && p.fragmented && p.transport,"complete TCP header in initial fragment"); + b=tcp(); put16(b,20,0x2000); check(parse(b).status==ParseStatus::malformed,"non-final fragment alignment"); + b=tcp(); b.resize(42); b[23]=17; put16(b,16,28); put16(b,20,0x2000); put16(b,38,100); p=parse(b); + check(p.status==ParseStatus::ok && p.fragmented && p.udp_length==100,"fragmented UDP full datagram length"); + b=tcp(); put16(b,16,100); check(parse(b).status==ParseStatus::malformed,"IP total exceeds wire"); + check(parse_packet(b.data(),b.size(),120,0).status==ParseStatus::truncated,"IP total within wire beyond capture"); + b=tcp(); p=parse_packet(b.data(),b.size(),100,0); check(p.capture_truncated && p.transport,"capture truncation distinct from header validity"); + check(parse_packet(b.data(),b.size(),20,0).status==ParseStatus::malformed,"caplen cannot exceed wire length"); + b=tcp(); b[14]=0x65; check(parse(b).status==ParseStatus::malformed,"wrong IPv4 version"); + b=tcp(); put16(b,16,19); check(parse(b).status==ParseStatus::malformed,"IP total below IHL"); + b=tcp(); b[46]=0xf0; check(parse(b).status==ParseStatus::malformed,"TCP options exceed IP payload"); + check(iso_time(1700000000LL*second+123456789)=="2023-11-14T22:13:20.123456789Z","nanosecond timestamp format"); } -int main() { try { parser_tests(); std::cout << checks << " checks passed\n"; return 0; } +Packet syn(Timestamp time=0,std::uint16_t port=443) { + auto p=parse(tcp());p.timestamp=time;p.destination_port=port;return p; +} +Config only(const std::string& id,std::size_t threshold=3) { + auto c=Config::defaults();for (auto& [name,rule]:c.rules) rule.enabled=name==id; + auto& r=c.rules.at(id);r.threshold=threshold;r.window_seconds=10;r.cooldown_seconds=30;return c; +} +void flow_tests() { + auto c=Config::defaults(); c.max_flows=2;c.max_unique_flows=2;c.flow_timeout_seconds=10; + FlowTable flows(c);auto p=syn();flows.observe(p);p.timestamp=second;flows.observe(p); + check(flows.active_count()==1 && flows.unique_count()==1,"flow grouping"); + auto data=flows.json();check(data[0]["packets"]==2 && data[0]["observed_bytes"]==108 && data[0]["duration_seconds"]==1,"flow counters"); + std::swap(p.source,p.destination);std::swap(p.source_port,p.destination_port);flows.observe(p); + check(flows.active_count()==2 && flows.unique_count()==2,"reverse directional flow"); + p.destination_port=80;flows.observe(p);check(flows.evictions==1 && flows.unique_saturated,"bounded flow eviction and unique saturation"); + flows.expire(11*second,true);check(flows.active_count()==0 && flows.expired==2,"idle expiry boundary"); + check(flows.json().size()==2 && flows.archives_discarded==1,"bounded flow archive"); + p.fragmented=true;flows.observe(p);check(flows.active_count()==0,"fragments not grouped into partial flows"); +} +void detection_tests() { + { + DetectionEngine engine(only("POSSIBLE_TCP_PORT_SCAN")); + check(engine.observe(syn(0,80)).empty(),"one SYN is not scan"); + check(engine.observe(syn(second,80)).empty(),"same port deduplicated"); + check(engine.observe(syn(2*second,81)).empty(),"scan below boundary"); + auto a=engine.observe(syn(3*second,82));check(a.size()==1 && a[0]["observed_count"]==3,"scan threshold inclusive"); + check(a[0]["mitre_technique"]=="T1046 - Network Service Discovery","scan MITRE"); + check(engine.observe(syn(4*second,83)).empty(),"scan cooldown"); + } + { + DetectionEngine engine(only("POSSIBLE_TCP_PORT_SCAN")); + engine.observe(syn(0,80));engine.observe(syn(second,81)); + check(engine.observe(syn(10*second,82)).empty(),"half-open sliding window expires exact left edge"); + check(engine.observe(syn(10*second+1,83)).size()==1,"remaining window threshold"); + } + { + DetectionEngine engine(only("HIGH_TCP_SYN_RATE"));auto p=syn();p.tcp_flags=0x12; + check(engine.observe(p).empty(),"SYN ACK excluded"); + check(engine.observe(syn()).empty() && engine.observe(syn(second)).empty(),"SYN below boundary"); + check(engine.observe(syn(2*second)).size()==1,"SYN threshold"); + check(engine.observe(syn(3*second)).empty(),"SYN cooldown"); + engine.observe(syn(31*second));engine.observe(syn(32*second)); + check(engine.observe(syn(33*second)).size()==1,"SYN cooldown expiry and window reset"); + } + { + DetectionEngine engine(only("HIGH_ICMP_ECHO_RATE"));auto p=syn();p.protocol=1;p.echo_request=true;p.icmp_type=8; + engine.observe(p);p.timestamp=second;engine.observe(p);p.timestamp=2*second; + auto a=engine.observe(p);check(a.size()==1 && a[0]["rule_id"]=="HIGH_ICMP_ECHO_RATE","ICMP threshold"); + p.echo_request=false;p.echo_reply=true;p.timestamp=40*second;check(engine.observe(p).empty(),"echo replies excluded"); + } + { + auto c=only("CONNECTION_CONCENTRATION");DetectionEngine engine(c);auto p=syn(); + for (int i=0;i<10;++i) check(engine.observe(p).empty(),"retransmitted attempt deduplication"); + p.source_port++;engine.observe(p);p.destination="198.51.100.21"; + auto a=engine.observe(p);check(a.size()==1 && a[0]["evidence"]["distinct_destinations"]==2,"concentration across destinations"); + c.rules.at("POSSIBLE_TCP_PORT_SCAN").enabled=true;c.rules.at("POSSIBLE_TCP_PORT_SCAN").threshold=2; + DetectionEngine overlap(c);overlap.observe(syn(0,80));overlap.observe(syn(second,81));a=overlap.observe(syn(2*second,82)); + check(a.empty() && overlap.counters()["CONNECTION_CONCENTRATION"]["scan_overlap_suppressed"]==1,"scan overlap suppressed"); + } + { + auto c=only("SENSITIVE_SERVICE_TRAFFIC",1);DetectionEngine engine(c); + auto p=syn();p.source_port=22;check(engine.observe(p).size()==1,"sensitive source service port"); + check(engine.observe(p).empty(),"sensitive cooldown deduplication"); + c.rules.at("SENSITIVE_SERVICE_TRAFFIC").exclude_sources.insert(p.source);DetectionEngine excluded(c); + check(excluded.observe(p).empty(),"source exclusion"); + } + { + auto c=only("HIGH_TCP_SYN_RATE",2);c.max_rule_keys=1;c.max_rule_events=2;DetectionEngine engine(c); + engine.observe(syn());auto p=syn();p.source="192.0.2.99";engine.observe(p); + check(engine.counters()["HIGH_TCP_SYN_RATE"]["dropped_keys"]==1,"bounded keys visible"); + engine.observe(syn());engine.observe(syn());check(engine.counters()["HIGH_TCP_SYN_RATE"]["dropped_events"]==1,"bounded events visible"); + engine.expire(40*second);check(engine.counters()["HIGH_TCP_SYN_RATE"]["retained_keys"]==0,"expired detector storage reclaimed"); + } + { + auto c=only("HIGH_TCP_SYN_RATE",2);c.rules.at("HIGH_TCP_SYN_RATE").cooldown_seconds=0;DetectionEngine engine(c); + engine.observe(syn());check(engine.observe(syn()).size()==1,"zero cooldown crossing"); + check(engine.observe(syn()).empty(),"zero cooldown deduplicates same threshold episode"); + engine.observe(syn(11*second));check(engine.observe(syn(11*second)).size()==1,"zero cooldown rearm after expiry"); + } + { + DetectionEngine engine(Config::defaults());auto p=syn();p.fragmented=true; + check(engine.observe(p).empty(),"fragmented traffic excluded from IDS"); + p.fragmented=false;p.status=ParseStatus::malformed;check(engine.observe(p).empty(),"malformed traffic excluded from IDS"); + auto c=only("HIGH_TCP_SYN_RATE",1);Analysis analysis(c,true);analysis.observe(syn()); + bool threw=false;try { analysis.observe(syn(-1)); } catch (const std::runtime_error&) { threw=true; } + check(threw,"backwards timestamp rejected"); + FlowTable flows(c);p=syn(std::numeric_limits::max());flows.observe(p); + DetectionEngine maximum(c);check(maximum.observe(p).size()==1,"maximum timestamp arithmetic"); + } +} +void report_tests() { + check(html_escape("&")=="<a x="'">&","HTML escaping"); + check(csv_field("a,\"b\"")=="\"a,\"\"b\"\"\"","CSV quoting"); + check(csv_field("=1+1")=="\"'=1+1\"","CSV formula safety"); + auto c=Config::defaults();Analysis analysis(c,true);analysis.observe(syn()); + const auto report=analysis.report("analyze","",CaptureResult{1,0,false}); + check(Json::parse(report.dump())==report,"JSON roundtrip"); + check(html_report(report).find("<test>")!=std::string::npos,"report escapes metadata"); + check(evaluate_policy(syn(0,22),c.policy)=="WOULD_BLOCK" && evaluate_policy(syn(),c.policy)=="WOULD_ALLOW","first-match simulation"); + auto tiny=only("HIGH_TCP_SYN_RATE",1);tiny.max_alerts=1;tiny.rules.at("HIGH_TCP_SYN_RATE").cooldown_seconds=1; + Analysis bounded(tiny,true);bounded.observe(syn());bounded.observe(syn(2*second)); + check(bounded.alerts.size()==1 && bounded.total_alerts==2 && bounded.alerts_not_retained==1,"bounded alerts retain total counts"); + Statistics stats(1);stats.observe(syn());auto p=syn(second);p.source="192.0.2.99";stats.observe(p); + check(stats.omitted_sources==1 && stats.json()["packets_per_second"]==2,"bounded talkers and rates"); +} +void fuzz_tests() { + std::mt19937 random(0x5046); + for (int iteration=0;iteration<10000;++iteration) { + std::vector bytes(random()%256); + for (auto& byte:bytes) byte=static_cast(random()); + if (bytes.size()>14 && iteration%2==0) { bytes[12]=8;bytes[13]=0; } + const auto a=parse_packet(bytes.data(),bytes.size(),static_cast(bytes.size()+random()%100),0); + check(a.captured_length==bytes.size(),"random parser bounded decode"); + } +} + +} +int main() { try { parser_tests(); protocol_tests(); flow_tests(); detection_tests(); report_tests(); fuzz_tests(); std::cout << checks << " checks passed\n"; return 0; } catch (const std::exception& e) { std::cerr << "FAIL: " << e.what() << '\n'; return 1; } } diff --git a/third_party/README.md b/third_party/README.md new file mode 100644 index 0000000..c858730 --- /dev/null +++ b/third_party/README.md @@ -0,0 +1,7 @@ +# Vendored dependency + +nlohmann/json 3.12.0, unmodified single header from the official tagged release: +https://github.com/nlohmann/json/releases/tag/v3.12.0 + +MIT license is included in nlohmann/LICENSE.MIT. Vendoring keeps builds and analysis +offline after installing the compiler, CMake and libpcap development package. diff --git a/third_party/nlohmann/LICENSE.MIT b/third_party/nlohmann/LICENSE.MIT new file mode 100644 index 0000000..a1dacc8 --- /dev/null +++ b/third_party/nlohmann/LICENSE.MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2013-2025 Niels Lohmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third_party/nlohmann/json.hpp b/third_party/nlohmann/json.hpp new file mode 100644 index 0000000..82d69f7 --- /dev/null +++ b/third_party/nlohmann/json.hpp @@ -0,0 +1,25526 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + +/****************************************************************************\ + * Note on documentation: The source files contain links to the online * + * documentation of the public API at https://json.nlohmann.me. This URL * + * contains the most recent documentation and should also be applicable to * + * previous versions; documentation for deprecated functions is not * + * removed, but marked deprecated. See "Generate documentation" section in * + * file docs/README.md. * +\****************************************************************************/ + +#ifndef INCLUDE_NLOHMANN_JSON_HPP_ +#define INCLUDE_NLOHMANN_JSON_HPP_ + +#include // all_of, find, for_each +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#ifndef JSON_NO_IO + #include // istream, ostream +#endif // JSON_NO_IO +#include // random_access_iterator_tag +#include // unique_ptr +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap +#include // vector + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 12 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 0 // NOLINT(modernize-macro-to-enum) + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + +#ifndef JSON_DIAGNOSTIC_POSITIONS + #define JSON_DIAGNOSTIC_POSITIONS 0 +#endif + +#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#endif + +#if JSON_DIAGNOSTICS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#endif + +#if JSON_DIAGNOSTIC_POSITIONS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#else + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif + +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) json_abi ## a ## b ## c +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) + +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS) + +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + +#ifndef NLOHMANN_JSON_NAMESPACE +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ + { +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_END +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann +#endif + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // transform +#include // array +#include // forward_list +#include // inserter, front_inserter, end +#include // map +#ifdef JSON_HAS_CPP_17 + #include // optional +#endif +#include // string +#include // tuple, make_tuple +#include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include // unordered_map +#include // pair, declval +#include // valarray + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // nullptr_t +#include // exception +#if JSON_DIAGNOSTICS + #include // accumulate +#endif +#include // runtime_error +#include // to_string +#include // vector + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // array +#include // size_t +#include // uint8_t +#include // string + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // declval, pair +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +// https://en.cppreference.com/w/cpp/experimental/is_detected +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template class Op, class... Args> +using is_detected = typename detector::value_t; + +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; + +template class Op, class... Args> +using detected_t = typename detector::type; + +template class Op, class... Args> +using detected_or = detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + + +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-FileCopyrightText: 2016 - 2021 Evan Nemerson +// SPDX-License-Identifier: MIT + +/* Hedley - https://nemequ.github.io/hedley + * Created by Evan Nemerson + */ + +#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) +#if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION +#endif +#define JSON_HEDLEY_VERSION 15 + +#if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX +#endif +#define JSON_HEDLEY_STRINGIFY_EX(x) #x + +#if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY +#endif +#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) + +#if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX +#endif +#define JSON_HEDLEY_CONCAT_EX(a,b) a##b + +#if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT +#endif +#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) + +#if defined(JSON_HEDLEY_CONCAT3_EX) + #undef JSON_HEDLEY_CONCAT3_EX +#endif +#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c + +#if defined(JSON_HEDLEY_CONCAT3) + #undef JSON_HEDLEY_CONCAT3 +#endif +#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) + +#if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE +#endif +#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION +#endif +#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) + +#if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION +#endif +#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) +#endif + +#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION +#endif +#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) +#elif defined(_MSC_FULL_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) +#elif defined(_MSC_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK +#endif +#if !defined(JSON_HEDLEY_MSVC_VERSION) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) +#elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) +#else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) +#elif defined(__INTEL_COMPILER) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #undef JSON_HEDLEY_INTEL_CL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) + #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION +#endif +#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION +#endif +#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) +#elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) +#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) +#elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#endif +#if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION +#endif +#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) +#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION +#endif +#if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) +#elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) +#elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION +#endif +#if \ + defined(__TI_COMPILER_VERSION__) && \ + ( \ + defined(__TMS470__) || defined(__TI_ARM__) || \ + defined(__MSP430__) || \ + defined(__TMS320C2000__) \ + ) +#if (__TI_COMPILER_VERSION__ >= 16000000) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif +#endif + +#if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #undef JSON_HEDLEY_TI_CL2000_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) + #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #undef JSON_HEDLEY_TI_CL430_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) + #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #undef JSON_HEDLEY_TI_ARMCL_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) + #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) + #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #undef JSON_HEDLEY_TI_CL6X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) + #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #undef JSON_HEDLEY_TI_CL7X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) + #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #undef JSON_HEDLEY_TI_CLPRU_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) + #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION +#endif +#if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION +#endif +#if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION +#endif +#if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION +#endif +#if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION +#endif +#if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION +#endif +#if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #undef JSON_HEDLEY_MCST_LCC_VERSION +#endif +#if defined(__LCC__) && defined(__LCC_MINOR__) + #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) + #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION +#endif +#if \ + defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_CRAY_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ + !defined(__COMPCERT__) && \ + !defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE +#endif +#if \ + defined(__has_attribute) && \ + ( \ + (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ + ) +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) +#else +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#endif +#if \ + defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#endif +#if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#elif \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) +#else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) +#else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) +#else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) +#else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) +#else + #define JSON_HEDLEY_PRAGMA(value) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#endif +#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP +#endif +#if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) +#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP +#endif + +/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") +# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") +# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# endif +#endif +#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x +#endif + +#if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST +#endif +#if defined(__cplusplus) +# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) +#elif \ + JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) +#else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) +#else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ + ((T) (expr)) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("diag_suppress=Pe137") \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) +# endif +#else +# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif + +#if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED +#endif +#if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) +#elif \ + (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +#elif defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") +#else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) +#endif + +#if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) +#else + #define JSON_HEDLEY_UNAVAILABLE(available_since) +#endif + +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT +#endif +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) +#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) +#elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ +#else + #define JSON_HEDLEY_WARN_UNUSED_RESULT + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) +#endif + +#if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) +#else + #define JSON_HEDLEY_SENTINEL(position) +#endif + +#if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN +#endif +#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NO_RETURN __noreturn +#elif \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn +#elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#else + #define JSON_HEDLEY_NO_RETURN +#endif + +#if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) +#else + #define JSON_HEDLEY_NO_ESCAPE +#endif + +#if defined(JSON_HEDLEY_UNREACHABLE) + #undef JSON_HEDLEY_UNREACHABLE +#endif +#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN +#endif +#if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) +#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) +#elif \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() +#elif defined(JSON_HEDLEY_ASSUME) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif +#if !defined(JSON_HEDLEY_ASSUME) + #if defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) + #else + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #endif +#endif +#if defined(JSON_HEDLEY_UNREACHABLE) + #if \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #endif +#else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) +#endif +#if !defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif + +JSON_HEDLEY_DIAGNOSTIC_PUSH +#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +#endif +#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif +#endif +#if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else + #define JSON_HEDLEY_NON_NULL(...) +#endif +JSON_HEDLEY_DIAGNOSTIC_POP + +#if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT +#endif +#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) +#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) +#else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) +#endif + +#if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif +#endif +#if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR +#endif + +#if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT +#endif +#if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY +#endif +#if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY +#endif +#if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE +#endif +#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) +#elif \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#else +# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) +# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) +#endif +#if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) +#endif + +#if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) +#else + #define JSON_HEDLEY_MALLOC +#endif + +#if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PURE __attribute__((__pure__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) +# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ + ) +# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") +#else +# define JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_CONST __attribute__((__const__)) +#elif \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") +#else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT +#endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + defined(__clang__) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RESTRICT __restrict +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict +#else + #define JSON_HEDLEY_RESTRICT +#endif + +#if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE +#endif +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline +#elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) + #define JSON_HEDLEY_INLINE __inline__ +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_INLINE __inline +#else + #define JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) +# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_ALWAYS_INLINE __forceinline +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ + ) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") +#else +# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#else + #define JSON_HEDLEY_NEVER_INLINE +#endif + +#if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE +#endif +#if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC +#endif +#if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT +#endif +#if defined(_WIN32) || defined(__CYGWIN__) +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC __declspec(dllexport) +# define JSON_HEDLEY_IMPORT __declspec(dllimport) +#else +# if \ + JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + ( \ + defined(__TI_EABI__) && \ + ( \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ + ) \ + ) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) +# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) +# else +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC +# endif +# define JSON_HEDLEY_IMPORT extern +#endif + +#if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) +#else + #define JSON_HEDLEY_NO_THROW +#endif + +#if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) +#elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough +#else + #define JSON_HEDLEY_FALL_THROUGH +#endif + +#if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) +#elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ +#else + #define JSON_HEDLEY_RETURNS_NON_NULL +#endif + +#if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM +#endif +#if \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) +#else + #define JSON_HEDLEY_ARRAY_PARAM(name) +#endif + +#if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT +#endif +#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#endif +/* JSON_HEDLEY_IS_CONSTEXPR_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) +#endif +#if !defined(__cplusplus) +# if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) +#endif +# elif \ + ( \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION)) || \ + (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) +#endif +# elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ + defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ + defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ + defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ + defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ + defined(__clang__) +# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? \ + ((void*) ((expr) * 0L) ) : \ +((struct { char v[sizeof(void) * 2]; } *) 1) \ + ) \ + ) \ + ) +# endif +#endif +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) +#else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) +#endif + +#if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS +#endif +#if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS +#endif +#if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" +#else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL +#endif + +#if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT +#endif +#if \ + !defined(__cplusplus) && ( \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + defined(_Static_assert) \ + ) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) +#elif \ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) +#else +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) +#endif + +#if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif +#elif defined(NULL) + #define JSON_HEDLEY_NULL NULL +#else + #define JSON_HEDLEY_NULL ((void*) 0) +#endif + +#if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) +#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE +#endif +#if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) +# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") +# define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) +# endif +#else +# define JSON_HEDLEY_REQUIRE(expr) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) +#endif + +#if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) +#else + #define JSON_HEDLEY_FLAGS +#endif + +#if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST +#endif +#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) +# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)") \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) +#endif + +#if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES +#endif +#if \ + (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) +#else + #define JSON_HEDLEY_EMPTY_BASES +#endif + +/* Remaining macros are deprecated. */ + +#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#endif +#if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) +#else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#endif +#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + +#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE +#endif +#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + +#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#endif +#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + +#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING +#endif +#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + +#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ + + +// This file contains all internal macro definitions (except those affecting ABI) +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// #include + + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// C++ language standard detection +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) + #define JSON_HAS_CPP_23 + #define JSON_HAS_CPP_20 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus > 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L) + #define JSON_HAS_CPP_20 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus > 201402L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus > 201103L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 + #endif + // the cpp 11 flag is always specified because it is the minimal required version + #define JSON_HAS_CPP_11 +#endif + +#ifdef __has_include + #if __has_include() + #include + #endif +#endif + +#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) + #ifdef JSON_HAS_CPP_17 + #if defined(__cpp_lib_filesystem) + #define JSON_HAS_FILESYSTEM 1 + #elif defined(__cpp_lib_experimental_filesystem) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif !defined(__has_include) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #endif + + // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ + #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__clang_major__) && __clang_major__ < 7 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support + #if defined(_MSC_VER) && _MSC_VER < 1914 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before iOS 13 + #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before macOS Catalina + #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + #endif +#endif + +#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_FILESYSTEM + #define JSON_HAS_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_THREE_WAY_COMPARISON + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ + && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #define JSON_HAS_THREE_WAY_COMPARISON 1 + #else + #define JSON_HAS_THREE_WAY_COMPARISON 0 + #endif +#endif + +#ifndef JSON_HAS_RANGES + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error + #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 + #define JSON_HAS_RANGES 0 + #elif defined(__cpp_lib_ranges) + #define JSON_HAS_RANGES 1 + #else + #define JSON_HAS_RANGES 0 + #endif +#endif + +#ifndef JSON_HAS_STATIC_RTTI + #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0 + #define JSON_HAS_STATIC_RTTI 1 + #else + #define JSON_HAS_STATIC_RTTI 0 + #endif +#endif + +#ifdef JSON_HAS_CPP_17 + #define JSON_INLINE_VARIABLE inline +#else + #define JSON_INLINE_VARIABLE +#endif + +#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) + #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else + #define JSON_NO_UNIQUE_ADDRESS +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdocumentation" + #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +#endif + +// allow disabling exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #include + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// allow overriding assert +#if !defined(JSON_ASSERT) + #include // assert + #define JSON_ASSERT(x) assert(x) +#endif + +// allow to access some private functions (needed by the test suite) +#if defined(JSON_TESTS_PRIVATE) + #define JSON_PRIVATE_UNLESS_TESTED public +#else + #define JSON_PRIVATE_UNLESS_TESTED private +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + /* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + /* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on */ \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + /* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + /* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on */ \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [&j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer, \ + class BinaryType, \ + class CustomBaseClass> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// Macros to simplify conversion from/to types + +#define NLOHMANN_JSON_EXPAND( x ) x +#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME +#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ + NLOHMANN_JSON_PASTE64, \ + NLOHMANN_JSON_PASTE63, \ + NLOHMANN_JSON_PASTE62, \ + NLOHMANN_JSON_PASTE61, \ + NLOHMANN_JSON_PASTE60, \ + NLOHMANN_JSON_PASTE59, \ + NLOHMANN_JSON_PASTE58, \ + NLOHMANN_JSON_PASTE57, \ + NLOHMANN_JSON_PASTE56, \ + NLOHMANN_JSON_PASTE55, \ + NLOHMANN_JSON_PASTE54, \ + NLOHMANN_JSON_PASTE53, \ + NLOHMANN_JSON_PASTE52, \ + NLOHMANN_JSON_PASTE51, \ + NLOHMANN_JSON_PASTE50, \ + NLOHMANN_JSON_PASTE49, \ + NLOHMANN_JSON_PASTE48, \ + NLOHMANN_JSON_PASTE47, \ + NLOHMANN_JSON_PASTE46, \ + NLOHMANN_JSON_PASTE45, \ + NLOHMANN_JSON_PASTE44, \ + NLOHMANN_JSON_PASTE43, \ + NLOHMANN_JSON_PASTE42, \ + NLOHMANN_JSON_PASTE41, \ + NLOHMANN_JSON_PASTE40, \ + NLOHMANN_JSON_PASTE39, \ + NLOHMANN_JSON_PASTE38, \ + NLOHMANN_JSON_PASTE37, \ + NLOHMANN_JSON_PASTE36, \ + NLOHMANN_JSON_PASTE35, \ + NLOHMANN_JSON_PASTE34, \ + NLOHMANN_JSON_PASTE33, \ + NLOHMANN_JSON_PASTE32, \ + NLOHMANN_JSON_PASTE31, \ + NLOHMANN_JSON_PASTE30, \ + NLOHMANN_JSON_PASTE29, \ + NLOHMANN_JSON_PASTE28, \ + NLOHMANN_JSON_PASTE27, \ + NLOHMANN_JSON_PASTE26, \ + NLOHMANN_JSON_PASTE25, \ + NLOHMANN_JSON_PASTE24, \ + NLOHMANN_JSON_PASTE23, \ + NLOHMANN_JSON_PASTE22, \ + NLOHMANN_JSON_PASTE21, \ + NLOHMANN_JSON_PASTE20, \ + NLOHMANN_JSON_PASTE19, \ + NLOHMANN_JSON_PASTE18, \ + NLOHMANN_JSON_PASTE17, \ + NLOHMANN_JSON_PASTE16, \ + NLOHMANN_JSON_PASTE15, \ + NLOHMANN_JSON_PASTE14, \ + NLOHMANN_JSON_PASTE13, \ + NLOHMANN_JSON_PASTE12, \ + NLOHMANN_JSON_PASTE11, \ + NLOHMANN_JSON_PASTE10, \ + NLOHMANN_JSON_PASTE9, \ + NLOHMANN_JSON_PASTE8, \ + NLOHMANN_JSON_PASTE7, \ + NLOHMANN_JSON_PASTE6, \ + NLOHMANN_JSON_PASTE5, \ + NLOHMANN_JSON_PASTE4, \ + NLOHMANN_JSON_PASTE3, \ + NLOHMANN_JSON_PASTE2, \ + NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) +#define NLOHMANN_JSON_PASTE2(func, v1) func(v1) +#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) +#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) +#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4) +#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5) +#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6) +#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7) +#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8) +#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9) +#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10) +#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) +#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) +#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) +#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) +#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) +#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) +#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) +#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) +#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) +#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) +#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) +#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) +#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) +#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) +#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) +#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) +#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) +#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) +#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) +#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) +#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) +#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) +#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) +#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) +#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) +#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) +#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) +#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) +#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) +#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) +#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) +#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) +#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) +#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) +#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) +#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) +#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) +#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) +#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) +#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) +#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) +#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) +#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) +#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) +#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) +#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) +#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) +#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) +#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) +#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) +#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) +#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) +#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) + +#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; +#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); +#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = !nlohmann_json_j.is_null() ? nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1) : nlohmann_json_default_obj.v1; + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE +@since version 3.9.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT +@since version 3.11.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE +@since version 3.11.3 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE +@since version 3.9.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT +@since version 3.11.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE +@since version 3.11.3 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/ +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Type, BaseType, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast(nlohmann_json_t)); const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \ + template::value, int> = 0> \ + friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(Type, BaseType, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + template::value, int> = 0> \ + void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast(nlohmann_json_t)); const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE +@since version 3.12.0 +@sa https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/ +*/ +#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \ + template::value, int> = 0> \ + void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +// inspired from https://stackoverflow.com/a/26745591 +// allows calling any std function as if (e.g., with begin): +// using std::begin; begin(x); +// +// it allows using the detected idiom to retrieve the return type +// of such an expression +#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ + namespace detail { \ + using std::std_name; \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + } \ + \ + namespace detail2 { \ + struct std_name##_tag \ + { \ + }; \ + \ + template \ + std_name##_tag std_name(T&&...); \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + \ + template \ + struct would_call_std_##std_name \ + { \ + static constexpr auto const value = ::nlohmann::detail:: \ + is_detected_exact::value; \ + }; \ + } /* namespace detail2 */ \ + \ + template \ + struct would_call_std_##std_name : detail2::would_call_std_##std_name \ + { \ + } + +#ifndef JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_USE_IMPLICIT_CONVERSIONS 1 +#endif + +#if JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_EXPLICIT +#else + #define JSON_EXPLICIT explicit +#endif + +#ifndef JSON_DISABLE_ENUM_SERIALIZATION + #define JSON_DISABLE_ENUM_SERIALIZATION 0 +#endif + +#ifndef JSON_USE_GLOBAL_UDLS + #define JSON_USE_GLOBAL_UDLS 1 +#endif + +#if JSON_HAS_THREE_WAY_COMPARISON + #include // partial_ordering +#endif + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +#if JSON_HAS_THREE_WAY_COMPARISON + inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* +#else + inline bool operator<(const value_t lhs, const value_t rhs) noexcept +#endif +{ + static constexpr std::array order = {{ + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, + 6 /* binary */ + } + }; + + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); +#if JSON_HAS_THREE_WAY_COMPARISON + if (l_index < order.size() && r_index < order.size()) + { + return order[l_index] <=> order[r_index]; // *NOPAD* + } + return std::partial_ordering::unordered; +#else + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +#endif +} + +// GCC selects the built-in operator< over an operator rewritten from +// a user-defined spaceship operator +// Clang, MSVC, and ICC select the rewritten candidate +// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) +#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + return std::is_lt(lhs <=> rhs); // *NOPAD* +} +#endif + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/*! +@brief replace all occurrences of a substring by another string + +@param[in,out] s the string to manipulate; changed so that all + occurrences of @a f are replaced with @a t +@param[in] f the substring to replace with @a t +@param[in] t the string to replace @a f + +@pre The search string @a f must not be empty. **This precondition is +enforced with an assertion.** + +@since version 2.0.0 +*/ +template +inline void replace_substring(StringType& s, const StringType& f, + const StringType& t) +{ + JSON_ASSERT(!f.empty()); + for (auto pos = s.find(f); // find first occurrence of f + pos != StringType::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f + {} +} + +/*! + * @brief string escaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to escape + * @return escaped string + * + * Note the order of escaping "~" to "~0" and "/" to "~1" is important. + */ +template +inline StringType escape(StringType s) +{ + replace_substring(s, StringType{"~"}, StringType{"~0"}); + replace_substring(s, StringType{"/"}, StringType{"~1"}); + return s; +} + +/*! + * @brief string unescaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to unescape + * @return unescaped string + * + * Note the order of escaping "~1" to "/" and "~0" to "~" is important. + */ +template +static void unescape(StringType& s) +{ + replace_substring(s, StringType{"~1"}, StringType{"/"}); + replace_substring(s, StringType{"~0"}, StringType{"~"}); +} + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // size_t + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-FileCopyrightText: 2018 The Abseil Authors +// SPDX-License-Identifier: MIT + + + +#include // array +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template +using uncvref_t = typename std::remove_cv::type>::type; + +#ifdef JSON_HAS_CPP_14 + +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +#else + +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h +// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. + +//// START OF CODE FROM GOOGLE ABSEIL + +// integer_sequence +// +// Class template representing a compile-time integer sequence. An instantiation +// of `integer_sequence` has a sequence of integers encoded in its +// type through its template arguments (which is a common need when +// working with C++11 variadic templates). `absl::integer_sequence` is designed +// to be a drop-in replacement for C++14's `std::integer_sequence`. +// +// Example: +// +// template< class T, T... Ints > +// void user_function(integer_sequence); +// +// int main() +// { +// // user_function's `T` will be deduced to `int` and `Ints...` +// // will be deduced to `0, 1, 2, 3, 4`. +// user_function(make_integer_sequence()); +// } +template +struct integer_sequence +{ + using value_type = T; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +// index_sequence +// +// A helper template for an `integer_sequence` of `size_t`, +// `absl::index_sequence` is designed to be a drop-in replacement for C++14's +// `std::index_sequence`. +template +using index_sequence = integer_sequence; + +namespace utility_internal +{ + +template +struct Extend; + +// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. +template +struct Extend, SeqSize, 0> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; +}; + +template +struct Extend, SeqSize, 1> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; +}; + +// Recursion helper for 'make_integer_sequence'. +// 'Gen::type' is an alias for 'integer_sequence'. +template +struct Gen +{ + using type = + typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; +}; + +template +struct Gen +{ + using type = integer_sequence; +}; + +} // namespace utility_internal + +// Compile-time sequences of integers + +// make_integer_sequence +// +// This template alias is equivalent to +// `integer_sequence`, and is designed to be a drop-in +// replacement for C++14's `std::make_integer_sequence`. +template +using make_integer_sequence = typename utility_internal::Gen::type; + +// make_index_sequence +// +// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, +// and is designed to be a drop-in replacement for C++14's +// `std::make_index_sequence`. +template +using make_index_sequence = make_integer_sequence; + +// index_sequence_for +// +// Converts a typename pack into an index sequence of the same length, and +// is designed to be a drop-in replacement for C++14's +// `std::index_sequence_for()` +template +using index_sequence_for = make_index_sequence; + +//// END OF CODE FROM GOOGLE ABSEIL + +#endif + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static JSON_INLINE_VARIABLE constexpr T value{}; +}; + +#ifndef JSON_HAS_CPP_17 + template + constexpr T static_const::value; +#endif + +template +constexpr std::array make_array(Args&& ... args) +{ + return std::array {{static_cast(std::forward(args))...}}; +} + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // numeric_limits +#include // char_traits +#include // tuple +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // random_access_iterator_tag + +// #include + +// #include + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN + +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); + +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN + +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); + +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann +// SPDX-License-Identifier: MIT + +#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ + #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + + #include // int64_t, uint64_t + #include // map + #include // allocator + #include // string + #include // vector + + // #include + + + /*! + @brief namespace for Niels Lohmann + @see https://github.com/nlohmann + @since version 1.0.0 + */ + NLOHMANN_JSON_NAMESPACE_BEGIN + + /*! + @brief default JSONSerializer template argument + + This serializer ignores the template arguments and uses ADL + ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) + for serialization. + */ + template + struct adl_serializer; + + /// a class to store JSON values + /// @sa https://json.nlohmann.me/api/basic_json/ + template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector, // cppcheck-suppress syntaxError + class CustomBaseClass = void> + class basic_json; + + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document + /// @sa https://json.nlohmann.me/api/json_pointer/ + template + class json_pointer; + + /*! + @brief default specialization + @sa https://json.nlohmann.me/api/json/ + */ + using json = basic_json<>; + + /// @brief a minimal map-like container that preserves insertion order + /// @sa https://json.nlohmann.me/api/ordered_map/ + template + struct ordered_map; + + /// @brief specialization that maintains the insertion order of object keys + /// @sa https://json.nlohmann.me/api/ordered_json/ + using ordered_json = basic_json; + + NLOHMANN_JSON_NAMESPACE_END + +#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ + + +NLOHMANN_JSON_NAMESPACE_BEGIN +/*! +@brief detail namespace with internal helper functions + +This namespace collects functions that should not be exposed, +implementations of some @ref basic_json methods, and meta-programming helpers. + +@since version 2.1.0 +*/ +namespace detail +{ + +///////////// +// helpers // +///////////// + +// Note to maintainers: +// +// Every trait in this file expects a non CV-qualified type. +// The only exceptions are in the 'aliases for detected' section +// (i.e. those of the form: decltype(T::member_function(std::declval()))) +// +// In this case, T has to be properly CV-qualified to constraint the function arguments +// (e.g. to_json(BasicJsonType&, const T&)) + +template struct is_basic_json : std::false_type {}; + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +struct is_basic_json : std::true_type {}; + +// used by exceptions create() member functions +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t +// false_type otherwise +template +struct is_basic_json_context : + std::integral_constant < bool, + is_basic_json::type>::type>::value + || std::is_same::value > +{}; + +////////////////////// +// json_ref helpers // +////////////////////// + +template +class json_ref; + +template +struct is_json_ref : std::false_type {}; + +template +struct is_json_ref> : std::true_type {}; + +////////////////////////// +// aliases for detected // +////////////////////////// + +template +using mapped_type_t = typename T::mapped_type; + +template +using key_type_t = typename T::key_type; + +template +using value_type_t = typename T::value_type; + +template +using difference_type_t = typename T::difference_type; + +template +using pointer_t = typename T::pointer; + +template +using reference_t = typename T::reference; + +template +using iterator_category_t = typename T::iterator_category; + +template +using to_json_function = decltype(T::to_json(std::declval()...)); + +template +using from_json_function = decltype(T::from_json(std::declval()...)); + +template +using get_template_function = decltype(std::declval().template get()); + +// trait checking if JSONSerializer::from_json(json const&, udt&) exists +template +struct has_from_json : std::false_type {}; + +// trait checking if j.get is valid +// use this trait instead of std::is_constructible or std::is_convertible, +// both rely on, or make use of implicit conversions, and thus fail when T +// has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) +template +struct is_getable +{ + static constexpr bool value = is_detected::value; +}; + +template +struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if JSONSerializer::from_json(json const&) exists +// this overload is used for non-default-constructible user-defined-types +template +struct has_non_default_from_json : std::false_type {}; + +template +struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if BasicJsonType::json_serializer::to_json exists +// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. +template +struct has_to_json : std::false_type {}; + +template +struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +template +using detect_key_compare = typename T::key_compare; + +template +struct has_key_compare : std::integral_constant::value> {}; + +// obtains the actual object key comparator +template +struct actual_object_comparator +{ + using object_t = typename BasicJsonType::object_t; + using object_comparator_t = typename BasicJsonType::default_object_comparator_t; + using type = typename std::conditional < has_key_compare::value, + typename object_t::key_compare, object_comparator_t>::type; +}; + +template +using actual_object_comparator_t = typename actual_object_comparator::type; + +///////////////// +// char_traits // +///////////////// + +// Primary template of char_traits calls std char_traits +template +struct char_traits : std::char_traits +{}; + +// Explicitly define char traits for unsigned char since it is not standard +template<> +struct char_traits : std::char_traits +{ + using char_type = unsigned char; + using int_type = uint64_t; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) noexcept + { + return static_cast(c); + } + + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept + { + return static_cast(std::char_traits::eof()); + } +}; + +// Explicitly define char traits for signed char since it is not standard +template<> +struct char_traits : std::char_traits +{ + using char_type = signed char; + using int_type = uint64_t; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) noexcept + { + return static_cast(c); + } + + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept + { + return static_cast(std::char_traits::eof()); + } +}; + +/////////////////// +// is_ functions // +/////////////////// + +// https://en.cppreference.com/w/cpp/types/conjunction +template struct conjunction : std::true_type { }; +template struct conjunction : B { }; +template +struct conjunction +: std::conditional(B::value), conjunction, B>::type {}; + +// https://en.cppreference.com/w/cpp/types/negation +template struct negation : std::integral_constant < bool, !B::value > { }; + +// Reimplementation of is_constructible and is_default_constructible, due to them being broken for +// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). +// This causes compile errors in e.g. clang 3.5 or gcc 4.9. +template +struct is_default_constructible : std::is_default_constructible {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + +template +struct is_constructible : std::is_constructible {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_iterator_traits : std::false_type {}; + +template +struct is_iterator_traits> +{ + private: + using traits = iterator_traits; + + public: + static constexpr auto value = + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value; +}; + +template +struct is_range +{ + private: + using t_ref = typename std::add_lvalue_reference::type; + + using iterator = detected_t; + using sentinel = detected_t; + + // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator + // and https://en.cppreference.com/w/cpp/iterator/sentinel_for + // but reimplementing these would be too much work, as a lot of other concepts are used underneath + static constexpr auto is_iterator_begin = + is_iterator_traits>::value; + + public: + static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; +}; + +template +using iterator_t = enable_if_t::value, result_of_begin())>>; + +template +using range_value_t = value_type_t>>; + +// The following implementation of is_complete_type is taken from +// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ +// and is written by Xiang Fan who agreed to using it in this library. + +template +struct is_complete_type : std::false_type {}; + +template +struct is_complete_type : std::true_type {}; + +template +struct is_compatible_object_type_impl : std::false_type {}; + +template +struct is_compatible_object_type_impl < + BasicJsonType, CompatibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + // macOS's is_constructible does not play well with nonesuch... + static constexpr bool value = + is_constructible::value && + is_constructible::value; +}; + +template +struct is_compatible_object_type + : is_compatible_object_type_impl {}; + +template +struct is_constructible_object_type_impl : std::false_type {}; + +template +struct is_constructible_object_type_impl < + BasicJsonType, ConstructibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + static constexpr bool value = + (is_default_constructible::value && + (std::is_move_assignable::value || + std::is_copy_assignable::value) && + (is_constructible::value && + std::is_same < + typename object_t::mapped_type, + typename ConstructibleObjectType::mapped_type >::value)) || + (has_from_json::value || + has_non_default_from_json < + BasicJsonType, + typename ConstructibleObjectType::mapped_type >::value); +}; + +template +struct is_constructible_object_type + : is_constructible_object_type_impl {}; + +template +struct is_compatible_string_type +{ + static constexpr auto value = + is_constructible::value; +}; + +template +struct is_constructible_string_type +{ + // launder type through decltype() to fix compilation failure on ICPC +#ifdef __INTEL_COMPILER + using laundered_type = decltype(std::declval()); +#else + using laundered_type = ConstructibleStringType; +#endif + + static constexpr auto value = + conjunction < + is_constructible, + is_detected_exact>::value; +}; + +template +struct is_compatible_array_type_impl : std::false_type {}; + +template +struct is_compatible_array_type_impl < + BasicJsonType, CompatibleArrayType, + enable_if_t < + is_detected::value&& + is_iterator_traits>>::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same>::value >> +{ + static constexpr bool value = + is_constructible>::value; +}; + +template +struct is_compatible_array_type + : is_compatible_array_type_impl {}; + +template +struct is_constructible_array_type_impl : std::false_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t::value >> + : std::true_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t < !std::is_same::value&& + !is_compatible_string_type::value&& + is_default_constructible::value&& +(std::is_move_assignable::value || + std::is_copy_assignable::value)&& +is_detected::value&& +is_iterator_traits>>::value&& +is_detected::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 +!std::is_same>::value&& +is_complete_type < +detected_t>::value >> +{ + using value_type = range_value_t; + + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; +}; + +template +struct is_constructible_array_type + : is_constructible_array_type_impl {}; + +template +struct is_compatible_integer_type_impl : std::false_type {}; + +template +struct is_compatible_integer_type_impl < + RealIntegerType, CompatibleNumberIntegerType, + enable_if_t < std::is_integral::value&& + std::is_integral::value&& + !std::is_same::value >> +{ + // is there an assert somewhere on overflows? + using RealLimits = std::numeric_limits; + using CompatibleLimits = std::numeric_limits; + + static constexpr auto value = + is_constructible::value && + CompatibleLimits::is_integer && + RealLimits::is_signed == CompatibleLimits::is_signed; +}; + +template +struct is_compatible_integer_type + : is_compatible_integer_type_impl {}; + +template +struct is_compatible_type_impl: std::false_type {}; + +template +struct is_compatible_type_impl < + BasicJsonType, CompatibleType, + enable_if_t::value >> +{ + static constexpr bool value = + has_to_json::value; +}; + +template +struct is_compatible_type + : is_compatible_type_impl {}; + +template +struct is_constructible_tuple : std::false_type {}; + +template +struct is_constructible_tuple> : conjunction...> {}; + +template +struct is_json_iterator_of : std::false_type {}; + +template +struct is_json_iterator_of : std::true_type {}; + +template +struct is_json_iterator_of : std::true_type +{}; + +// checks if a given type T is a template specialization of Primary +template