@encharm/cws 4.5.3 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/CLAUDE.md +83 -0
- package/README.md +20 -4
- package/binding.gyp +8 -2
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +15 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +16 -2
- package/dist/shared.d.ts +1 -0
- package/dist/shared.js +3 -2
- package/package.json +1 -1
- package/src/Addon.cpp +4 -1
- package/src/Addon.h +80 -15
- package/src/Extensions.cpp +7 -1
- package/src/Extensions.h +2 -1
- package/src/Group.cpp +1 -1
- package/src/Group.h +4 -1
- package/src/HTTPSocket.cpp +1 -1
- package/src/Hub.cpp +11 -76
- package/src/Hub.h +12 -10
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +8 -5
- package/src/Zlib.cpp +138 -0
- package/src/Zlib.h +38 -0
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#ifndef SRC_JSON_UTILS_H_
|
|
2
|
+
#define SRC_JSON_UTILS_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "node_concepts.h"
|
|
7
|
+
|
|
8
|
+
#include <iomanip>
|
|
9
|
+
#include <limits>
|
|
10
|
+
#include <ostream>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <string_view>
|
|
13
|
+
|
|
14
|
+
namespace node {
|
|
15
|
+
|
|
16
|
+
constexpr bool NeedsJsonEscape(std::string_view str) {
|
|
17
|
+
for (const char c : str) {
|
|
18
|
+
if (c == '\\' || c == '"' || c < 0x20) return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
std::string EscapeJsonChars(std::string_view str);
|
|
24
|
+
std::string Reindent(const std::string& str, int indentation);
|
|
25
|
+
|
|
26
|
+
// JSON compiler definitions.
|
|
27
|
+
class JSONWriter {
|
|
28
|
+
public:
|
|
29
|
+
JSONWriter(std::ostream& out, bool compact)
|
|
30
|
+
: out_(out), compact_(compact) {}
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
inline void indent() { indent_ += 2; }
|
|
34
|
+
inline void deindent() { indent_ -= 2; }
|
|
35
|
+
inline void advance() {
|
|
36
|
+
if (compact_) return;
|
|
37
|
+
for (int i = 0; i < indent_; i++) out_ << ' ';
|
|
38
|
+
}
|
|
39
|
+
inline void write_one_space() {
|
|
40
|
+
if (compact_) return;
|
|
41
|
+
out_ << ' ';
|
|
42
|
+
}
|
|
43
|
+
inline void write_new_line() {
|
|
44
|
+
if (compact_) return;
|
|
45
|
+
out_ << '\n';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
inline void json_start() {
|
|
50
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
51
|
+
write_new_line();
|
|
52
|
+
advance();
|
|
53
|
+
out_ << '{';
|
|
54
|
+
indent();
|
|
55
|
+
state_ = kObjectStart;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
inline void json_end() {
|
|
59
|
+
write_new_line();
|
|
60
|
+
deindent();
|
|
61
|
+
advance();
|
|
62
|
+
out_ << '}';
|
|
63
|
+
state_ = kAfterValue;
|
|
64
|
+
}
|
|
65
|
+
template <typename T>
|
|
66
|
+
inline void json_objectstart(T key) {
|
|
67
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
68
|
+
write_new_line();
|
|
69
|
+
advance();
|
|
70
|
+
write_string(key);
|
|
71
|
+
out_ << ':';
|
|
72
|
+
write_one_space();
|
|
73
|
+
out_ << '{';
|
|
74
|
+
indent();
|
|
75
|
+
state_ = kObjectStart;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
template <typename T>
|
|
79
|
+
inline void json_arraystart(T key) {
|
|
80
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
81
|
+
write_new_line();
|
|
82
|
+
advance();
|
|
83
|
+
write_string(key);
|
|
84
|
+
out_ << ':';
|
|
85
|
+
write_one_space();
|
|
86
|
+
out_ << '[';
|
|
87
|
+
indent();
|
|
88
|
+
state_ = kObjectStart;
|
|
89
|
+
}
|
|
90
|
+
inline void json_objectend() {
|
|
91
|
+
write_new_line();
|
|
92
|
+
deindent();
|
|
93
|
+
advance();
|
|
94
|
+
out_ << '}';
|
|
95
|
+
if (indent_ == 0) {
|
|
96
|
+
// Top-level object is complete, so end the line.
|
|
97
|
+
out_ << '\n';
|
|
98
|
+
}
|
|
99
|
+
state_ = kAfterValue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline void json_arrayend() {
|
|
103
|
+
write_new_line();
|
|
104
|
+
deindent();
|
|
105
|
+
advance();
|
|
106
|
+
out_ << ']';
|
|
107
|
+
state_ = kAfterValue;
|
|
108
|
+
}
|
|
109
|
+
template <typename T, typename U>
|
|
110
|
+
inline void json_keyvalue(const T& key, const U& value) {
|
|
111
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
112
|
+
write_new_line();
|
|
113
|
+
advance();
|
|
114
|
+
write_string(key);
|
|
115
|
+
out_ << ':';
|
|
116
|
+
write_one_space();
|
|
117
|
+
write_value(value);
|
|
118
|
+
state_ = kAfterValue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
template <typename U>
|
|
122
|
+
inline void json_element(const U& value) {
|
|
123
|
+
if (state_ == kAfterValue) out_ << ',';
|
|
124
|
+
write_new_line();
|
|
125
|
+
advance();
|
|
126
|
+
write_value(value);
|
|
127
|
+
state_ = kAfterValue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
struct Null {}; // Usable as a JSON value.
|
|
131
|
+
|
|
132
|
+
struct ForeignJSON {
|
|
133
|
+
std::string as_string;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
private:
|
|
137
|
+
template <NumericValue T>
|
|
138
|
+
inline void write_value(T number) {
|
|
139
|
+
if constexpr (std::is_same<T, bool>::value)
|
|
140
|
+
out_ << (number ? "true" : "false");
|
|
141
|
+
else
|
|
142
|
+
out_ << number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
inline void write_value(Null null) { out_ << "null"; }
|
|
146
|
+
inline void write_value(std::string_view str) { write_string(str); }
|
|
147
|
+
|
|
148
|
+
inline void write_value(const ForeignJSON& json) {
|
|
149
|
+
out_ << Reindent(json.as_string, indent_);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
inline void write_string(std::string_view str) {
|
|
153
|
+
out_ << '"';
|
|
154
|
+
if (NeedsJsonEscape(str)) // only create temporary std::string if necessary
|
|
155
|
+
out_ << EscapeJsonChars(str);
|
|
156
|
+
else
|
|
157
|
+
out_ << str;
|
|
158
|
+
out_ << '"';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
enum JSONState { kObjectStart, kAfterValue };
|
|
162
|
+
std::ostream& out_;
|
|
163
|
+
bool compact_;
|
|
164
|
+
int indent_ = 0;
|
|
165
|
+
int state_ = kObjectStart;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
} // namespace node
|
|
169
|
+
|
|
170
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
171
|
+
|
|
172
|
+
#endif // SRC_JSON_UTILS_H_
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright (C) 2018 Intel Corporation
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"),
|
|
5
|
+
// to deal in the Software without restriction, including without limitation
|
|
6
|
+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
7
|
+
// and/or sell copies of the Software, and to permit persons to whom
|
|
8
|
+
// the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included
|
|
11
|
+
// in all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
14
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
17
|
+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
18
|
+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
19
|
+
// OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
//
|
|
21
|
+
// SPDX-License-Identifier: MIT
|
|
22
|
+
|
|
23
|
+
#ifndef SRC_LARGE_PAGES_NODE_LARGE_PAGE_H_
|
|
24
|
+
#define SRC_LARGE_PAGES_NODE_LARGE_PAGE_H_
|
|
25
|
+
|
|
26
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
27
|
+
|
|
28
|
+
namespace node {
|
|
29
|
+
int MapStaticCodeToLargePages();
|
|
30
|
+
const char* LargePagesError(int status);
|
|
31
|
+
} // namespace node
|
|
32
|
+
|
|
33
|
+
#endif // NODE_WANT_INTERNALS
|
|
34
|
+
#endif // SRC_LARGE_PAGES_NODE_LARGE_PAGE_H_
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#ifndef SRC_LRU_CACHE_INL_H_
|
|
2
|
+
#define SRC_LRU_CACHE_INL_H_
|
|
3
|
+
|
|
4
|
+
#include <list>
|
|
5
|
+
#include <unordered_map>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
8
|
+
template <typename key_t, typename value_t>
|
|
9
|
+
class LRUCache {
|
|
10
|
+
public:
|
|
11
|
+
using key_value_pair_t = typename std::pair<key_t, value_t>;
|
|
12
|
+
using iterator = typename std::list<key_value_pair_t>::iterator;
|
|
13
|
+
using const_iterator = typename std::list<key_value_pair_t>::const_iterator;
|
|
14
|
+
|
|
15
|
+
const_iterator begin() const { return lru_list_.begin(); }
|
|
16
|
+
const_iterator end() const { return lru_list_.end(); }
|
|
17
|
+
|
|
18
|
+
explicit LRUCache(size_t capacity) : capacity_(capacity) {}
|
|
19
|
+
|
|
20
|
+
void Put(const key_t& key, const value_t& value) {
|
|
21
|
+
auto it = lookup_map_.find(key);
|
|
22
|
+
if (it != lookup_map_.end()) {
|
|
23
|
+
lru_list_.erase(it->second);
|
|
24
|
+
lookup_map_.erase(it);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lru_list_.push_front(std::make_pair(key, value));
|
|
28
|
+
lookup_map_[key] = lru_list_.begin();
|
|
29
|
+
|
|
30
|
+
if (lookup_map_.size() > capacity_) {
|
|
31
|
+
auto last = lru_list_.end();
|
|
32
|
+
last--;
|
|
33
|
+
lookup_map_.erase(last->first);
|
|
34
|
+
lru_list_.pop_back();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
value_t& Get(const key_t& key) {
|
|
39
|
+
auto it = lookup_map_.find(key);
|
|
40
|
+
lru_list_.splice(lru_list_.begin(), lru_list_, it->second);
|
|
41
|
+
return it->second->second;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void Erase(const key_t& key) {
|
|
45
|
+
auto it = lookup_map_.find(key);
|
|
46
|
+
if (it != lookup_map_.end()) {
|
|
47
|
+
lru_list_.erase(it->second);
|
|
48
|
+
lookup_map_.erase(it);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool Exists(const key_t& key) const { return lookup_map_.count(key) > 0; }
|
|
53
|
+
|
|
54
|
+
size_t Size() const { return lookup_map_.size(); }
|
|
55
|
+
|
|
56
|
+
size_t Capacity() const { return capacity_; }
|
|
57
|
+
|
|
58
|
+
void Clear() {
|
|
59
|
+
lru_list_.clear();
|
|
60
|
+
lookup_map_.clear();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
std::list<key_value_pair_t> lru_list_;
|
|
65
|
+
std::unordered_map<key_t, iterator> lookup_map_;
|
|
66
|
+
size_t capacity_;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
#endif // SRC_LRU_CACHE_INL_H_
|