@zlink-systems/zlink 0.17.3
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/LICENSE +373 -0
- package/README.md +198 -0
- package/README.typedoc.md +56 -0
- package/THIRD_PARTY_NOTICES.md +84 -0
- package/binding.gyp +27 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +117 -0
- package/dist/index.mjs +4 -0
- package/dist/zlink/contracts/core/buffer_like.d.ts +2 -0
- package/dist/zlink/contracts/core/buffer_like.js +3 -0
- package/dist/zlink/contracts/core/context.d.ts +103 -0
- package/dist/zlink/contracts/core/context.js +11 -0
- package/dist/zlink/contracts/core/index.d.ts +3 -0
- package/dist/zlink/contracts/core/index.js +20 -0
- package/dist/zlink/contracts/core/routing_id.d.ts +28 -0
- package/dist/zlink/contracts/core/routing_id.js +120 -0
- package/dist/zlink/contracts/errors/errors.d.ts +44 -0
- package/dist/zlink/contracts/errors/errors.js +89 -0
- package/dist/zlink/contracts/errors/index.d.ts +2 -0
- package/dist/zlink/contracts/errors/index.js +29 -0
- package/dist/zlink/contracts/errors/results.d.ts +106 -0
- package/dist/zlink/contracts/errors/results.js +102 -0
- package/dist/zlink/contracts/eventing/index.d.ts +3 -0
- package/dist/zlink/contracts/eventing/index.js +20 -0
- package/dist/zlink/contracts/eventing/monitor.d.ts +157 -0
- package/dist/zlink/contracts/eventing/monitor.js +82 -0
- package/dist/zlink/contracts/eventing/poller.d.ts +76 -0
- package/dist/zlink/contracts/eventing/poller.js +3 -0
- package/dist/zlink/contracts/eventing/timer.d.ts +38 -0
- package/dist/zlink/contracts/eventing/timer.js +3 -0
- package/dist/zlink/contracts/index.d.ts +5 -0
- package/dist/zlink/contracts/index.js +22 -0
- package/dist/zlink/contracts/messaging/handlers.d.ts +5 -0
- package/dist/zlink/contracts/messaging/handlers.js +3 -0
- package/dist/zlink/contracts/messaging/index.d.ts +8 -0
- package/dist/zlink/contracts/messaging/index.js +15 -0
- package/dist/zlink/contracts/messaging/message.d.ts +68 -0
- package/dist/zlink/contracts/messaging/message.js +280 -0
- package/dist/zlink/contracts/messaging/message_parts_envelope.d.ts +14 -0
- package/dist/zlink/contracts/messaging/message_parts_envelope.js +56 -0
- package/dist/zlink/contracts/messaging/operations.d.ts +54 -0
- package/dist/zlink/contracts/messaging/operations.js +3 -0
- package/dist/zlink/contracts/messaging/received.d.ts +41 -0
- package/dist/zlink/contracts/messaging/received.js +130 -0
- package/dist/zlink/contracts/messaging/stream_packet.d.ts +14 -0
- package/dist/zlink/contracts/messaging/stream_packet.js +33 -0
- package/dist/zlink/contracts/messaging/subscription_event.d.ts +12 -0
- package/dist/zlink/contracts/messaging/subscription_event.js +20 -0
- package/dist/zlink/contracts/messaging/topic_message.d.ts +14 -0
- package/dist/zlink/contracts/messaging/topic_message.js +36 -0
- package/dist/zlink/contracts/sockets/dealer_socket.d.ts +29 -0
- package/dist/zlink/contracts/sockets/dealer_socket.js +3 -0
- package/dist/zlink/contracts/sockets/index.d.ts +10 -0
- package/dist/zlink/contracts/sockets/index.js +15 -0
- package/dist/zlink/contracts/sockets/pair_socket.d.ts +20 -0
- package/dist/zlink/contracts/sockets/pair_socket.js +3 -0
- package/dist/zlink/contracts/sockets/pubsub_sockets.d.ts +40 -0
- package/dist/zlink/contracts/sockets/pubsub_sockets.js +3 -0
- package/dist/zlink/contracts/sockets/router_socket.d.ts +32 -0
- package/dist/zlink/contracts/sockets/router_socket.js +3 -0
- package/dist/zlink/contracts/sockets/socket.d.ts +58 -0
- package/dist/zlink/contracts/sockets/socket.js +3 -0
- package/dist/zlink/contracts/sockets/socket_constants.d.ts +88 -0
- package/dist/zlink/contracts/sockets/socket_constants.js +67 -0
- package/dist/zlink/contracts/sockets/socket_options.d.ts +105 -0
- package/dist/zlink/contracts/sockets/socket_options.js +3 -0
- package/dist/zlink/contracts/sockets/stream_socket.d.ts +31 -0
- package/dist/zlink/contracts/sockets/stream_socket.js +3 -0
- package/dist/zlink/runtime/buffers/message_conversion.d.ts +6 -0
- package/dist/zlink/runtime/buffers/message_conversion.js +49 -0
- package/dist/zlink/runtime/core/context.d.ts +43 -0
- package/dist/zlink/runtime/core/context.js +150 -0
- package/dist/zlink/runtime/core/context_options.d.ts +19 -0
- package/dist/zlink/runtime/core/context_options.js +23 -0
- package/dist/zlink/runtime/core/routing_id.d.ts +3 -0
- package/dist/zlink/runtime/core/routing_id.js +30 -0
- package/dist/zlink/runtime/core/routing_id_conversion.d.ts +2 -0
- package/dist/zlink/runtime/core/routing_id_conversion.js +11 -0
- package/dist/zlink/runtime/core/runtime_info.d.ts +8 -0
- package/dist/zlink/runtime/core/runtime_info.js +39 -0
- package/dist/zlink/runtime/errors/error_mapping.d.ts +4 -0
- package/dist/zlink/runtime/errors/error_mapping.js +132 -0
- package/dist/zlink/runtime/errors/error_state.d.ts +1 -0
- package/dist/zlink/runtime/errors/error_state.js +15 -0
- package/dist/zlink/runtime/errors/native_errors.d.ts +16 -0
- package/dist/zlink/runtime/errors/native_errors.js +86 -0
- package/dist/zlink/runtime/eventing/counters.d.ts +16 -0
- package/dist/zlink/runtime/eventing/counters.js +33 -0
- package/dist/zlink/runtime/eventing/index.d.ts +6 -0
- package/dist/zlink/runtime/eventing/index.js +22 -0
- package/dist/zlink/runtime/eventing/monitor_event_state.d.ts +3 -0
- package/dist/zlink/runtime/eventing/monitor_event_state.js +19 -0
- package/dist/zlink/runtime/eventing/monitor_raw.d.ts +50 -0
- package/dist/zlink/runtime/eventing/monitor_raw.js +3 -0
- package/dist/zlink/runtime/eventing/monitor_socket.d.ts +9 -0
- package/dist/zlink/runtime/eventing/monitor_socket.js +39 -0
- package/dist/zlink/runtime/eventing/monitor_status.d.ts +3 -0
- package/dist/zlink/runtime/eventing/monitor_status.js +52 -0
- package/dist/zlink/runtime/eventing/poll_events.d.ts +20 -0
- package/dist/zlink/runtime/eventing/poll_events.js +92 -0
- package/dist/zlink/runtime/eventing/poller.d.ts +34 -0
- package/dist/zlink/runtime/eventing/poller.js +275 -0
- package/dist/zlink/runtime/eventing/thread.d.ts +6 -0
- package/dist/zlink/runtime/eventing/thread.js +52 -0
- package/dist/zlink/runtime/eventing/timer.d.ts +8 -0
- package/dist/zlink/runtime/eventing/timer.js +45 -0
- package/dist/zlink/runtime/handles/native_handle.d.ts +7 -0
- package/dist/zlink/runtime/handles/native_handle.js +24 -0
- package/dist/zlink/runtime/messaging/completion_owner.d.ts +86 -0
- package/dist/zlink/runtime/messaging/completion_owner.js +570 -0
- package/dist/zlink/runtime/messaging/message_materializer.d.ts +36 -0
- package/dist/zlink/runtime/messaging/message_materializer.js +199 -0
- package/dist/zlink/runtime/messaging/message_parts_state.d.ts +4 -0
- package/dist/zlink/runtime/messaging/message_parts_state.js +20 -0
- package/dist/zlink/runtime/messaging/message_snapshot.d.ts +13 -0
- package/dist/zlink/runtime/messaging/message_snapshot.js +42 -0
- package/dist/zlink/runtime/messaging/received_operations.d.ts +5 -0
- package/dist/zlink/runtime/messaging/received_operations.js +46 -0
- package/dist/zlink/runtime/messaging/received_state.d.ts +13 -0
- package/dist/zlink/runtime/messaging/received_state.js +29 -0
- package/dist/zlink/runtime/messaging/request_executor.d.ts +2 -0
- package/dist/zlink/runtime/messaging/request_executor.js +8 -0
- package/dist/zlink/runtime/messaging/send_operation_base.d.ts +13 -0
- package/dist/zlink/runtime/messaging/send_operation_base.js +52 -0
- package/dist/zlink/runtime/messaging/subscription_event_state.d.ts +4 -0
- package/dist/zlink/runtime/messaging/subscription_event_state.js +17 -0
- package/dist/zlink/runtime/messaging/topic_message_state.d.ts +11 -0
- package/dist/zlink/runtime/messaging/topic_message_state.js +75 -0
- package/dist/zlink/runtime/native/binding.d.ts +6 -0
- package/dist/zlink/runtime/native/binding.js +3 -0
- package/dist/zlink/runtime/native/binding_context.d.ts +14 -0
- package/dist/zlink/runtime/native/binding_context.js +3 -0
- package/dist/zlink/runtime/native/binding_core.d.ts +21 -0
- package/dist/zlink/runtime/native/binding_core.js +3 -0
- package/dist/zlink/runtime/native/binding_eventing.d.ts +40 -0
- package/dist/zlink/runtime/native/binding_eventing.js +3 -0
- package/dist/zlink/runtime/native/binding_socket.d.ts +52 -0
- package/dist/zlink/runtime/native/binding_socket.js +3 -0
- package/dist/zlink/runtime/native/binding_types.d.ts +8 -0
- package/dist/zlink/runtime/native/binding_types.js +3 -0
- package/dist/zlink/runtime/native/native.d.ts +2 -0
- package/dist/zlink/runtime/native/native.js +40 -0
- package/dist/zlink/runtime/native/native_load_paths.d.ts +16 -0
- package/dist/zlink/runtime/native/native_load_paths.js +165 -0
- package/dist/zlink/runtime/options/byte_values.d.ts +3 -0
- package/dist/zlink/runtime/options/byte_values.js +27 -0
- package/dist/zlink/runtime/options/option_mapping.d.ts +72 -0
- package/dist/zlink/runtime/options/option_mapping.js +41 -0
- package/dist/zlink/runtime/options/validation.d.ts +1 -0
- package/dist/zlink/runtime/options/validation.js +17 -0
- package/dist/zlink/runtime/public_bridge.d.ts +6 -0
- package/dist/zlink/runtime/public_bridge.js +23 -0
- package/dist/zlink/runtime/sockets/dealer_socket.d.ts +16 -0
- package/dist/zlink/runtime/sockets/dealer_socket.js +56 -0
- package/dist/zlink/runtime/sockets/index.d.ts +19 -0
- package/dist/zlink/runtime/sockets/index.js +27 -0
- package/dist/zlink/runtime/sockets/pair_socket.d.ts +7 -0
- package/dist/zlink/runtime/sockets/pair_socket.js +12 -0
- package/dist/zlink/runtime/sockets/pub_socket.d.ts +7 -0
- package/dist/zlink/runtime/sockets/pub_socket.js +12 -0
- package/dist/zlink/runtime/sockets/router_socket.d.ts +19 -0
- package/dist/zlink/runtime/sockets/router_socket.js +70 -0
- package/dist/zlink/runtime/sockets/socket_base.d.ts +21 -0
- package/dist/zlink/runtime/sockets/socket_base.js +102 -0
- package/dist/zlink/runtime/sockets/socket_operation_builders.d.ts +38 -0
- package/dist/zlink/runtime/sockets/socket_operation_builders.js +93 -0
- package/dist/zlink/runtime/sockets/socket_operations.d.ts +40 -0
- package/dist/zlink/runtime/sockets/socket_operations.js +177 -0
- package/dist/zlink/runtime/sockets/socket_options.d.ts +104 -0
- package/dist/zlink/runtime/sockets/socket_options.js +259 -0
- package/dist/zlink/runtime/sockets/socket_submit_errors.d.ts +3 -0
- package/dist/zlink/runtime/sockets/socket_submit_errors.js +13 -0
- package/dist/zlink/runtime/sockets/stream_socket.d.ts +15 -0
- package/dist/zlink/runtime/sockets/stream_socket.js +93 -0
- package/dist/zlink/runtime/sockets/sub_socket.d.ts +7 -0
- package/dist/zlink/runtime/sockets/sub_socket.js +12 -0
- package/dist/zlink/runtime/sockets/xpub_socket.d.ts +10 -0
- package/dist/zlink/runtime/sockets/xpub_socket.js +39 -0
- package/dist/zlink/runtime/sockets/xsub_socket.d.ts +7 -0
- package/dist/zlink/runtime/sockets/xsub_socket.js +12 -0
- package/native/src/addon.cc +11 -0
- package/native/src/addon_common_api.h +57 -0
- package/native/src/addon_core.cc +3974 -0
- package/native/src/addon_core_api.h +110 -0
- package/native/src/addon_core_options.cc +119 -0
- package/native/src/addon_core_options.h +9 -0
- package/native/src/addon_exports.cc +151 -0
- package/native/src/addon_exports.h +7 -0
- package/native/src/addon_message_parts.h +67 -0
- package/native/src/addon_message_values.h +345 -0
- package/native/src/addon_monitor_status_values.h +71 -0
- package/native/src/addon_submit_results.h +30 -0
- package/package.json +74 -0
- package/prebuilds/linux-x64/libzlink.so.0.17.3 +0 -0
- package/prebuilds/linux-x64/zlink.node +0 -0
- package/provenance/core-package-provenance.json +73 -0
- package/scripts/install.js +37 -0
- package/scripts/resolve_core.js +86 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.routedReceivedPrefersManagedBuffer = routedReceivedPrefersManagedBuffer;
|
|
5
|
+
exports.routedReceivedRoutingBytes = routedReceivedRoutingBytes;
|
|
6
|
+
exports.nativeReceivedRoutingId = nativeReceivedRoutingId;
|
|
7
|
+
exports.materializeReceived = materializeReceived;
|
|
8
|
+
exports.materializeReceivedInto = materializeReceivedInto;
|
|
9
|
+
exports.materializeRoutedReceivedInto = materializeRoutedReceivedInto;
|
|
10
|
+
exports.materializeTopicMessage = materializeTopicMessage;
|
|
11
|
+
exports.adoptTopicMessage = adoptTopicMessage;
|
|
12
|
+
const message_1 = require("../../contracts/messaging/message");
|
|
13
|
+
const routing_id_1 = require("../core/routing_id");
|
|
14
|
+
const received_1 = require("../../contracts/messaging/received");
|
|
15
|
+
const message_snapshot_1 = require("./message_snapshot");
|
|
16
|
+
const received_state_1 = require("./received_state");
|
|
17
|
+
const received_operations_1 = require("./received_operations");
|
|
18
|
+
const topic_message_state_1 = require("./topic_message_state");
|
|
19
|
+
function isNativeTopicMessageSinglePart(raw) {
|
|
20
|
+
return Array.isArray(raw);
|
|
21
|
+
}
|
|
22
|
+
function isNativeReceivedBufferParts(raw) {
|
|
23
|
+
return Array.isArray(raw);
|
|
24
|
+
}
|
|
25
|
+
const routedReceiveContexts = new WeakMap();
|
|
26
|
+
function routedReceivedPrefersManagedBuffer(target) {
|
|
27
|
+
const parts = target.parts;
|
|
28
|
+
// HOT PATH: a reusable Received reveals its stable consumer role. A data
|
|
29
|
+
// reader should avoid a second addon call on the next receive, while a
|
|
30
|
+
// relay consumes the native frame and therefore stays on the movable path.
|
|
31
|
+
return parts.length === 1
|
|
32
|
+
&& parts[0].size() <= 64
|
|
33
|
+
&& (0, message_1.hasObservedManagedReceiveData)(parts[0]);
|
|
34
|
+
}
|
|
35
|
+
function routedReceivedRoutingBytes(target) {
|
|
36
|
+
return target.routingId === null ? null : (0, routing_id_1.normalizeRoutingId)(target.routingId);
|
|
37
|
+
}
|
|
38
|
+
function envelopeOf(raw) {
|
|
39
|
+
const candidate = raw;
|
|
40
|
+
return candidate.data !== undefined
|
|
41
|
+
|| candidate.nativeMessage !== undefined
|
|
42
|
+
|| candidate.parts !== undefined
|
|
43
|
+
|| candidate.routingId !== undefined
|
|
44
|
+
|| candidate.replyToken !== undefined
|
|
45
|
+
? candidate
|
|
46
|
+
: null;
|
|
47
|
+
}
|
|
48
|
+
function nativeReceivedRoutingId(raw) {
|
|
49
|
+
return envelopeOf(raw)?.routingId ?? null;
|
|
50
|
+
}
|
|
51
|
+
function wrapNativeRoutingId(routingId) {
|
|
52
|
+
if (!routingId || routingId.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return (0, routing_id_1.routingIdFromOwnedBuffer)(routingId);
|
|
56
|
+
}
|
|
57
|
+
function materializeParts(parts) {
|
|
58
|
+
if (parts.length === 1) {
|
|
59
|
+
return [(0, message_snapshot_1.messageFromSnapshot)(parts[0])];
|
|
60
|
+
}
|
|
61
|
+
const messages = new Array(parts.length);
|
|
62
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
63
|
+
messages[i] = (0, message_snapshot_1.messageFromSnapshot)(parts[i]);
|
|
64
|
+
}
|
|
65
|
+
return messages;
|
|
66
|
+
}
|
|
67
|
+
function materializeReceivedParts(raw) {
|
|
68
|
+
if (isNativeReceivedBufferParts(raw)) {
|
|
69
|
+
const messages = new Array(raw.length);
|
|
70
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
71
|
+
messages[i] = (0, message_snapshot_1.messageFromOwnedBuffer)(raw[i]);
|
|
72
|
+
}
|
|
73
|
+
return messages;
|
|
74
|
+
}
|
|
75
|
+
const envelope = envelopeOf(raw);
|
|
76
|
+
if (envelope === null) {
|
|
77
|
+
if (Buffer.isBuffer(raw)) {
|
|
78
|
+
return [(0, message_snapshot_1.messageFromOwnedBuffer)(raw)];
|
|
79
|
+
}
|
|
80
|
+
return [(0, message_snapshot_1.messageFromNativeFrame)(raw)];
|
|
81
|
+
}
|
|
82
|
+
if (envelope.data !== undefined) {
|
|
83
|
+
return envelope.routingId && envelope.routingId.length > 0
|
|
84
|
+
? [(0, message_snapshot_1.messageFromOwnedRoutedBuffer)(envelope.data, envelope.routingId, envelope.nativeMessage)]
|
|
85
|
+
: [(0, message_snapshot_1.messageFromOwnedBuffer)(envelope.data, envelope.nativeMessage)];
|
|
86
|
+
}
|
|
87
|
+
if (envelope.nativeMessage !== undefined) {
|
|
88
|
+
const identity = envelope.routingId && envelope.routingId.length > 0
|
|
89
|
+
? envelope.routingId.toString()
|
|
90
|
+
: undefined;
|
|
91
|
+
return [(0, message_snapshot_1.messageFromNativeFrame)(envelope.nativeMessage, identity === undefined ? undefined : { 'Routing-Id': identity, Identity: identity }, true)];
|
|
92
|
+
}
|
|
93
|
+
return materializeParts(envelope.parts ?? []);
|
|
94
|
+
}
|
|
95
|
+
function materializeTopicParts(raw) {
|
|
96
|
+
if (isNativeTopicMessageSinglePart(raw)) {
|
|
97
|
+
return [(0, message_snapshot_1.messageFromOwnedBuffer)(raw[0])];
|
|
98
|
+
}
|
|
99
|
+
if (raw.data) {
|
|
100
|
+
// Hot path: core SUB messages are normally single-part. The native layer
|
|
101
|
+
// passes the owned payload Buffer directly so public TopicMessage adoption
|
|
102
|
+
// avoids a per-message native parts array and snapshot object.
|
|
103
|
+
return [(0, message_snapshot_1.messageFromOwnedBuffer)(raw.data)];
|
|
104
|
+
}
|
|
105
|
+
if (raw.nativeMessage !== undefined) {
|
|
106
|
+
return [(0, message_snapshot_1.messageFromNativeFrame)(raw.nativeMessage)];
|
|
107
|
+
}
|
|
108
|
+
return materializeParts(raw.parts ?? []);
|
|
109
|
+
}
|
|
110
|
+
function materializeReceived(raw, send, sendManaged) {
|
|
111
|
+
const envelope = envelopeOf(raw);
|
|
112
|
+
return (0, received_state_1.createReceived)(materializeReceivedParts(raw), wrapNativeRoutingId(envelope?.routingId ?? null), null, null, send && sendManaged
|
|
113
|
+
? {
|
|
114
|
+
beginSend() {
|
|
115
|
+
return (0, received_operations_1.createReceivedSendOperation)((parts) => send(parts), (parts) => sendManaged(parts));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
: null);
|
|
119
|
+
}
|
|
120
|
+
function materializeReceivedInto(target, raw, send, sendManaged) {
|
|
121
|
+
const envelope = envelopeOf(raw);
|
|
122
|
+
(0, received_state_1.replaceReceived)(target, materializeReceivedParts(raw), wrapNativeRoutingId(envelope?.routingId ?? null), null, null, send && sendManaged
|
|
123
|
+
? {
|
|
124
|
+
beginSend() {
|
|
125
|
+
return (0, received_operations_1.createReceivedSendOperation)((parts) => send(parts), (parts) => sendManaged(parts));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
: null);
|
|
129
|
+
}
|
|
130
|
+
function materializeRoutedReceivedInto(target, raw, operations) {
|
|
131
|
+
const envelope = envelopeOf(raw);
|
|
132
|
+
if (envelope === null) {
|
|
133
|
+
throw new Error('routed receive requires a receive envelope');
|
|
134
|
+
}
|
|
135
|
+
let context = routedReceiveContexts.get(target);
|
|
136
|
+
if (!context) {
|
|
137
|
+
context = {
|
|
138
|
+
routingId: null,
|
|
139
|
+
replyToken: null,
|
|
140
|
+
operations,
|
|
141
|
+
sendContext: {
|
|
142
|
+
beginSend() {
|
|
143
|
+
const routingId = context.routingId;
|
|
144
|
+
const operations = context.operations;
|
|
145
|
+
if (routingId == null)
|
|
146
|
+
throw new Error('missing routed send target');
|
|
147
|
+
return (0, received_operations_1.createReceivedSendOperation)((parts) => operations.send(routingId, parts), (parts) => operations.sendManaged(routingId, parts));
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
replyContext: {
|
|
151
|
+
beginReply() {
|
|
152
|
+
const routingId = context.routingId;
|
|
153
|
+
const replyToken = context.replyToken;
|
|
154
|
+
const operations = context.operations;
|
|
155
|
+
if (routingId == null || replyToken == null) {
|
|
156
|
+
throw new Error('missing request reply target');
|
|
157
|
+
}
|
|
158
|
+
return (0, received_operations_1.createReceivedReplyOperation)((parts) => operations.reply(routingId, replyToken, parts));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
routedReceiveContexts.set(target, context);
|
|
163
|
+
}
|
|
164
|
+
context.routingId = envelope.routingId ?? null;
|
|
165
|
+
context.operations = operations;
|
|
166
|
+
const rawReplyToken = envelope.replyToken ?? 0n;
|
|
167
|
+
context.replyToken = rawReplyToken === 0n
|
|
168
|
+
? null
|
|
169
|
+
: (0, received_1.createReplyToken)(operations.replyOwner, rawReplyToken);
|
|
170
|
+
const routingId = context.routingId === null
|
|
171
|
+
? null
|
|
172
|
+
: target.routingId !== null
|
|
173
|
+
&& (0, routing_id_1.normalizeRoutingId)(target.routingId).equals(context.routingId)
|
|
174
|
+
? target.routingId
|
|
175
|
+
: wrapNativeRoutingId(context.routingId);
|
|
176
|
+
(0, received_state_1.replaceReceived)(target, materializeReceivedParts(raw), routingId, context.replyToken, context.replyToken ? context.replyContext : null, context.routingId == null ? null : context.sendContext);
|
|
177
|
+
}
|
|
178
|
+
function materializeTopicMessage(raw) {
|
|
179
|
+
const topic = isNativeTopicMessageSinglePart(raw) ? raw[1] : raw.topic;
|
|
180
|
+
const routingId = isNativeTopicMessageSinglePart(raw)
|
|
181
|
+
? null
|
|
182
|
+
: wrapNativeRoutingId(raw.routingId ?? null);
|
|
183
|
+
return (0, topic_message_state_1.createTopicMessage)(topic, materializeTopicParts(raw), routingId);
|
|
184
|
+
}
|
|
185
|
+
function adoptTopicMessage(result, raw) {
|
|
186
|
+
const topic = isNativeTopicMessageSinglePart(raw) ? raw[1] : raw.topic;
|
|
187
|
+
const routingId = isNativeTopicMessageSinglePart(raw)
|
|
188
|
+
? null
|
|
189
|
+
: wrapNativeRoutingId(raw.routingId ?? null);
|
|
190
|
+
const data = isNativeTopicMessageSinglePart(raw)
|
|
191
|
+
? raw[0]
|
|
192
|
+
: raw.data;
|
|
193
|
+
if (data !== undefined) {
|
|
194
|
+
(0, topic_message_state_1.replaceTopicMessageOwnedSinglePart)(result, topic, data, routingId);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
(0, topic_message_state_1.replaceTopicMessage)(result, topic, materializeTopicParts(raw), routingId);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Message } from '../../contracts/messaging/message';
|
|
2
|
+
export declare function freezeMessageParts(parts: readonly Message[]): Message[];
|
|
3
|
+
export declare function freezeOwnedMessageParts(parts: Message[]): Message[];
|
|
4
|
+
export declare function closeMessageParts(parts: readonly Message[] | undefined): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.freezeMessageParts = freezeMessageParts;
|
|
5
|
+
exports.freezeOwnedMessageParts = freezeOwnedMessageParts;
|
|
6
|
+
exports.closeMessageParts = closeMessageParts;
|
|
7
|
+
function freezeMessageParts(parts) {
|
|
8
|
+
return Object.freeze(parts.slice());
|
|
9
|
+
}
|
|
10
|
+
function freezeOwnedMessageParts(parts) {
|
|
11
|
+
return Object.freeze(parts);
|
|
12
|
+
}
|
|
13
|
+
function closeMessageParts(parts) {
|
|
14
|
+
if (!parts) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
for (const part of parts) {
|
|
18
|
+
part.close();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message } from '../../contracts/messaging/message';
|
|
2
|
+
export interface MessageSnapshot {
|
|
3
|
+
data?: Buffer;
|
|
4
|
+
nativeMessage?: unknown;
|
|
5
|
+
refCount?: number;
|
|
6
|
+
properties?: Readonly<Record<string, string>>;
|
|
7
|
+
metadata?: Readonly<Map<number, Buffer>>;
|
|
8
|
+
}
|
|
9
|
+
export declare function messageFromSnapshot(snapshot: MessageSnapshot): Message;
|
|
10
|
+
export declare function messageFromOwnedBuffer(data: Buffer, nativeMessage?: unknown): Message;
|
|
11
|
+
export declare function messageFromNativeFrame(nativeMessage: unknown, properties?: Readonly<Record<string, string>>, nativeReadOnly?: boolean): Message;
|
|
12
|
+
export declare function messageFromOwnedRoutedBuffer(data: Buffer, routingId: Buffer, nativeMessage?: unknown): Message;
|
|
13
|
+
export declare function messageToSnapshot(message: Message): MessageSnapshot;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.messageFromSnapshot = messageFromSnapshot;
|
|
5
|
+
exports.messageFromOwnedBuffer = messageFromOwnedBuffer;
|
|
6
|
+
exports.messageFromNativeFrame = messageFromNativeFrame;
|
|
7
|
+
exports.messageFromOwnedRoutedBuffer = messageFromOwnedRoutedBuffer;
|
|
8
|
+
exports.messageToSnapshot = messageToSnapshot;
|
|
9
|
+
const message_1 = require("../../contracts/messaging/message");
|
|
10
|
+
function messageFromSnapshot(snapshot) {
|
|
11
|
+
const message = (0, message_1.acquireMessageWrapper)(snapshot.data, snapshot.refCount ?? 1, snapshot.properties, snapshot.nativeMessage, snapshot.metadata);
|
|
12
|
+
return message;
|
|
13
|
+
}
|
|
14
|
+
function messageFromOwnedBuffer(data, nativeMessage) {
|
|
15
|
+
return (0, message_1.acquireMessageWrapper)(data, 1, undefined, nativeMessage);
|
|
16
|
+
}
|
|
17
|
+
function messageFromNativeFrame(nativeMessage, properties, nativeReadOnly = false) {
|
|
18
|
+
return (0, message_1.acquireMessageWrapper)(undefined, 1, properties, nativeMessage, undefined, nativeReadOnly);
|
|
19
|
+
}
|
|
20
|
+
function messageFromOwnedRoutedBuffer(data, routingId, nativeMessage) {
|
|
21
|
+
const identity = routingId.toString();
|
|
22
|
+
return messageFromSnapshot({
|
|
23
|
+
data,
|
|
24
|
+
properties: {
|
|
25
|
+
'Routing-Id': identity,
|
|
26
|
+
Identity: identity
|
|
27
|
+
},
|
|
28
|
+
nativeMessage
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function messageToSnapshot(message) {
|
|
32
|
+
const state = message;
|
|
33
|
+
return {
|
|
34
|
+
...(state._buffer === undefined ? {} : { data: state._buffer }),
|
|
35
|
+
refCount: state._refCount,
|
|
36
|
+
properties: state._properties,
|
|
37
|
+
metadata: state._metadata,
|
|
38
|
+
...((0, message_1.canShareNativeMessage)(message) && state._nativeMessage !== undefined
|
|
39
|
+
? { nativeMessage: state._nativeMessage }
|
|
40
|
+
: {})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BufferLike } from '../../contracts/core/buffer_like';
|
|
2
|
+
import { Message } from '../../contracts/messaging/message';
|
|
3
|
+
import type { ReplyOperation, SendOperation } from '../../contracts/messaging/operations';
|
|
4
|
+
export declare function createReceivedSendOperation(invoke: (parts: readonly Message[]) => void, invokeAsync: (parts: readonly Message[]) => Promise<void>): SendOperation;
|
|
5
|
+
export declare function createReceivedReplyOperation(invoke: (parts: readonly (Message | BufferLike)[]) => void): ReplyOperation;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createReceivedSendOperation = createReceivedSendOperation;
|
|
5
|
+
exports.createReceivedReplyOperation = createReceivedReplyOperation;
|
|
6
|
+
const message_1 = require("../../contracts/messaging/message");
|
|
7
|
+
const send_operation_base_1 = require("./send_operation_base");
|
|
8
|
+
class RuntimeReceivedSendOperation extends send_operation_base_1.PartOperationBase {
|
|
9
|
+
_invoke;
|
|
10
|
+
_invokeAsync;
|
|
11
|
+
constructor(_invoke, _invokeAsync) {
|
|
12
|
+
super((message) => message instanceof message_1.Message ? message : message_1.Message.from(message));
|
|
13
|
+
this._invoke = _invoke;
|
|
14
|
+
this._invokeAsync = _invokeAsync;
|
|
15
|
+
}
|
|
16
|
+
submit() {
|
|
17
|
+
return this._invokeAsync(this.consumeParts());
|
|
18
|
+
}
|
|
19
|
+
submit_sync() {
|
|
20
|
+
const parts = this.consumeParts();
|
|
21
|
+
this._invoke(parts);
|
|
22
|
+
for (const part of parts)
|
|
23
|
+
(0, message_1.consumeSubmittedMessage)(part);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class RuntimeReceivedReplyOperation extends send_operation_base_1.PartOperationBase {
|
|
27
|
+
_invoke;
|
|
28
|
+
constructor(invoke) {
|
|
29
|
+
super((message) => message);
|
|
30
|
+
this._invoke = invoke;
|
|
31
|
+
}
|
|
32
|
+
submit() {
|
|
33
|
+
const parts = this.consumeParts();
|
|
34
|
+
this._invoke(parts);
|
|
35
|
+
for (const part of parts) {
|
|
36
|
+
if (part instanceof message_1.Message)
|
|
37
|
+
(0, message_1.consumeSubmittedMessage)(part);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function createReceivedSendOperation(invoke, invokeAsync) {
|
|
42
|
+
return new RuntimeReceivedSendOperation(invoke, invokeAsync);
|
|
43
|
+
}
|
|
44
|
+
function createReceivedReplyOperation(invoke) {
|
|
45
|
+
return new RuntimeReceivedReplyOperation(invoke);
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Received } from '../../contracts/messaging/received';
|
|
2
|
+
import { Message } from '../../contracts/messaging/message';
|
|
3
|
+
import type { ReplyOperation, SendOperation } from '../../contracts/messaging/operations';
|
|
4
|
+
import type { ReplyToken } from '../../contracts/messaging/received';
|
|
5
|
+
import { RoutingId } from '../../contracts/core/routing_id';
|
|
6
|
+
export interface ReplyContext {
|
|
7
|
+
beginReply(): ReplyOperation;
|
|
8
|
+
}
|
|
9
|
+
export interface SendContext {
|
|
10
|
+
beginSend(): SendOperation;
|
|
11
|
+
}
|
|
12
|
+
export declare function createReceived(parts: readonly Message[], routingId?: RoutingId | null, replyToken?: ReplyToken | null, replyContext?: ReplyContext | null, sendContext?: SendContext | null): Received;
|
|
13
|
+
export declare function replaceReceived(target: Received, parts: Message[], routingId?: RoutingId | null, replyToken?: ReplyToken | null, replyContext?: ReplyContext | null, sendContext?: SendContext | null): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createReceived = createReceived;
|
|
5
|
+
exports.replaceReceived = replaceReceived;
|
|
6
|
+
const received_1 = require("../../contracts/messaging/received");
|
|
7
|
+
const message_parts_state_1 = require("./message_parts_state");
|
|
8
|
+
function createReceived(parts, routingId = null, replyToken = null, replyContext = null, sendContext = null) {
|
|
9
|
+
const received = new received_1.Received();
|
|
10
|
+
replaceReceived(received, (0, message_parts_state_1.freezeMessageParts)(parts), routingId, replyToken, replyContext, sendContext);
|
|
11
|
+
return received;
|
|
12
|
+
}
|
|
13
|
+
function replaceReceived(target, parts, routingId = null, replyToken = null, replyContext = null, sendContext = null) {
|
|
14
|
+
const state = target;
|
|
15
|
+
// Caller-provided receive storage is reused in perf and long-running
|
|
16
|
+
// consumers. Release the previous payload before adopting the replacement
|
|
17
|
+
// so native-backed external Buffers do not wait for GC to drop RSS.
|
|
18
|
+
if (state.parts !== parts) {
|
|
19
|
+
try {
|
|
20
|
+
(0, message_parts_state_1.closeMessageParts)(state.parts);
|
|
21
|
+
}
|
|
22
|
+
finally { }
|
|
23
|
+
}
|
|
24
|
+
state.parts = Object.isFrozen(parts) ? parts : (0, message_parts_state_1.freezeOwnedMessageParts)(parts);
|
|
25
|
+
state.routingId = routingId;
|
|
26
|
+
state.replyToken = replyToken;
|
|
27
|
+
state._replyContext = replyContext;
|
|
28
|
+
state._sendContext = sendContext;
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.messagesFromNativeBuffers = messagesFromNativeBuffers;
|
|
5
|
+
const message_snapshot_1 = require("./message_snapshot");
|
|
6
|
+
function messagesFromNativeBuffers(buffers) {
|
|
7
|
+
return (buffers ?? []).map((buffer) => (0, message_snapshot_1.messageFromSnapshot)({ data: buffer ?? Buffer.alloc(0) }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type OperationPayloadValue<T> = T | readonly T[];
|
|
2
|
+
export declare class PartOperationBase<TInput, TStored = TInput> {
|
|
3
|
+
private readonly _normalize;
|
|
4
|
+
private _single;
|
|
5
|
+
private _hasSingle;
|
|
6
|
+
private _parts;
|
|
7
|
+
private _submitted;
|
|
8
|
+
constructor(normalize?: (value: TInput) => TStored);
|
|
9
|
+
message(message: TInput): this;
|
|
10
|
+
protected ensureOpen(): void;
|
|
11
|
+
protected consumePayload(): OperationPayloadValue<TStored>;
|
|
12
|
+
protected consumeParts(): readonly TStored[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PartOperationBase = void 0;
|
|
5
|
+
function identity(value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
class PartOperationBase {
|
|
9
|
+
_normalize;
|
|
10
|
+
_single;
|
|
11
|
+
_hasSingle = false;
|
|
12
|
+
_parts = null;
|
|
13
|
+
_submitted = false;
|
|
14
|
+
constructor(normalize = identity) {
|
|
15
|
+
this._normalize = normalize;
|
|
16
|
+
}
|
|
17
|
+
message(message) {
|
|
18
|
+
this.ensureOpen();
|
|
19
|
+
const normalized = this._normalize(message);
|
|
20
|
+
if (this._parts) {
|
|
21
|
+
this._parts.push(normalized);
|
|
22
|
+
}
|
|
23
|
+
else if (this._hasSingle) {
|
|
24
|
+
this._parts = [this._single, normalized];
|
|
25
|
+
this._hasSingle = false;
|
|
26
|
+
this._single = undefined;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this._single = normalized;
|
|
30
|
+
this._hasSingle = true;
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
ensureOpen() {
|
|
35
|
+
if (this._submitted) {
|
|
36
|
+
throw new TypeError('operation has already been submitted');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
consumePayload() {
|
|
40
|
+
this.ensureOpen();
|
|
41
|
+
if (!this._parts && !this._hasSingle) {
|
|
42
|
+
throw new TypeError('operation requires at least one message');
|
|
43
|
+
}
|
|
44
|
+
this._submitted = true;
|
|
45
|
+
return this._parts ?? this._single;
|
|
46
|
+
}
|
|
47
|
+
consumeParts() {
|
|
48
|
+
const value = this.consumePayload();
|
|
49
|
+
return Array.isArray(value) ? value : [value];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.PartOperationBase = PartOperationBase;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SubscriptionEvent } from '../../contracts/messaging/subscription_event';
|
|
2
|
+
import { RoutingId } from '../../contracts/core/routing_id';
|
|
3
|
+
export declare function createSubscriptionEvent(topic: string, subscribed: boolean, routingId?: RoutingId | null): SubscriptionEvent;
|
|
4
|
+
export declare function replaceSubscriptionEvent(target: SubscriptionEvent, topic: string, subscribed: boolean, routingId?: RoutingId | null): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createSubscriptionEvent = createSubscriptionEvent;
|
|
5
|
+
exports.replaceSubscriptionEvent = replaceSubscriptionEvent;
|
|
6
|
+
const subscription_event_1 = require("../../contracts/messaging/subscription_event");
|
|
7
|
+
function createSubscriptionEvent(topic, subscribed, routingId = null) {
|
|
8
|
+
const event = new subscription_event_1.SubscriptionEvent();
|
|
9
|
+
replaceSubscriptionEvent(event, topic, subscribed, routingId);
|
|
10
|
+
return event;
|
|
11
|
+
}
|
|
12
|
+
function replaceSubscriptionEvent(target, topic, subscribed, routingId = null) {
|
|
13
|
+
const state = target;
|
|
14
|
+
state.routingId = routingId;
|
|
15
|
+
state.topic = topic;
|
|
16
|
+
state.subscribed = subscribed === true;
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TopicMessage } from '../../contracts/messaging/topic_message';
|
|
2
|
+
import { Message } from '../../contracts/messaging/message';
|
|
3
|
+
import { RoutingId } from '../../contracts/core/routing_id';
|
|
4
|
+
export declare function createTopicMessage(topic: string, parts: readonly Message[], routingId?: RoutingId | null): TopicMessage;
|
|
5
|
+
export declare function replaceTopicMessage(target: TopicMessage, topic: string, parts: Message[], routingId?: RoutingId | null): void;
|
|
6
|
+
/**
|
|
7
|
+
* Replace a caller-provided result from the common owned-Buffer receive path.
|
|
8
|
+
* The previously visible single part becomes the next receive candidate only
|
|
9
|
+
* after the new payload has been adopted, so no public part is reused early.
|
|
10
|
+
*/
|
|
11
|
+
export declare function replaceTopicMessageOwnedSinglePart(target: TopicMessage, topic: string, data: Buffer, routingId?: RoutingId | null): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createTopicMessage = createTopicMessage;
|
|
5
|
+
exports.replaceTopicMessage = replaceTopicMessage;
|
|
6
|
+
exports.replaceTopicMessageOwnedSinglePart = replaceTopicMessageOwnedSinglePart;
|
|
7
|
+
const topic_message_1 = require("../../contracts/messaging/topic_message");
|
|
8
|
+
const message_1 = require("../../contracts/messaging/message");
|
|
9
|
+
const message_parts_state_1 = require("./message_parts_state");
|
|
10
|
+
function createTopicMessage(topic, parts, routingId = null) {
|
|
11
|
+
const message = new topic_message_1.TopicMessage();
|
|
12
|
+
replaceTopicMessage(message, topic, (0, message_parts_state_1.freezeMessageParts)(parts), routingId);
|
|
13
|
+
return message;
|
|
14
|
+
}
|
|
15
|
+
function replaceTopicMessage(target, topic, parts, routingId = null) {
|
|
16
|
+
const state = target;
|
|
17
|
+
// Caller-provided receive storage is a hot path. Replacing the envelope
|
|
18
|
+
// must release the previously owned payload immediately; otherwise reused
|
|
19
|
+
// TopicMessage instances retain external Buffer storage until GC and PUBSUB
|
|
20
|
+
// subscriber benchmarks regress in both RSS and throughput.
|
|
21
|
+
if (state.parts !== parts) {
|
|
22
|
+
try {
|
|
23
|
+
(0, message_parts_state_1.closeMessageParts)(state.parts);
|
|
24
|
+
}
|
|
25
|
+
finally { }
|
|
26
|
+
}
|
|
27
|
+
const candidate = state._reusableSinglePart;
|
|
28
|
+
if (candidate && !parts.includes(candidate)) {
|
|
29
|
+
candidate.close();
|
|
30
|
+
}
|
|
31
|
+
state._reusableSinglePart = null;
|
|
32
|
+
state._reusableSinglePartSlots = [];
|
|
33
|
+
state.parts = Object.isFrozen(parts) ? parts : (0, message_parts_state_1.freezeOwnedMessageParts)(parts);
|
|
34
|
+
state.routingId = routingId;
|
|
35
|
+
state.topic = topic;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Replace a caller-provided result from the common owned-Buffer receive path.
|
|
39
|
+
* The previously visible single part becomes the next receive candidate only
|
|
40
|
+
* after the new payload has been adopted, so no public part is reused early.
|
|
41
|
+
*/
|
|
42
|
+
function replaceTopicMessageOwnedSinglePart(target, topic, data, routingId = null) {
|
|
43
|
+
const state = target;
|
|
44
|
+
let next = state._reusableSinglePart;
|
|
45
|
+
if (next === null) {
|
|
46
|
+
next = (0, message_1.acquireMessageWrapper)(data);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
(0, message_1.refillMessageWrapper)(next, data);
|
|
50
|
+
}
|
|
51
|
+
const previous = state.parts.length === 1 ? state.parts[0] : null;
|
|
52
|
+
if (state.parts !== undefined) {
|
|
53
|
+
for (const part of state.parts) {
|
|
54
|
+
if (part !== next && part !== previous) {
|
|
55
|
+
part.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
state.parts = frozenSinglePartSlot(state, next);
|
|
60
|
+
state._reusableSinglePart = previous === next ? null : previous;
|
|
61
|
+
state.routingId = routingId;
|
|
62
|
+
state.topic = topic;
|
|
63
|
+
}
|
|
64
|
+
function frozenSinglePartSlot(state, part) {
|
|
65
|
+
for (const slot of state._reusableSinglePartSlots) {
|
|
66
|
+
if (slot[0] === part) {
|
|
67
|
+
return slot;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const slot = (0, message_parts_state_1.freezeOwnedMessageParts)([part]);
|
|
71
|
+
if (state._reusableSinglePartSlots.length < 2) {
|
|
72
|
+
state._reusableSinglePartSlots.push(slot);
|
|
73
|
+
}
|
|
74
|
+
return slot;
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CoreNativeBinding } from './binding_core';
|
|
2
|
+
import type { ContextNativeBinding } from './binding_context';
|
|
3
|
+
import type { EventingNativeBinding } from './binding_eventing';
|
|
4
|
+
import type { SocketNativeBinding } from './binding_socket';
|
|
5
|
+
export interface NativeBinding extends CoreNativeBinding, ContextNativeBinding, SocketNativeBinding, EventingNativeBinding {
|
|
6
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NativeBuffer, NativeHandle } from './binding_types';
|
|
2
|
+
import type { CoreHwmBudgetSnapshot } from '../../contracts/core';
|
|
3
|
+
export type CoreHwmBudgetSnapshotRaw = Omit<CoreHwmBudgetSnapshot, 'budgetPlanningActive' | 'budgetInsufficient' | 'aggregateHwmValid' | 'aggregateOverflow'>;
|
|
4
|
+
export interface ContextNativeBinding {
|
|
5
|
+
ctxGetOpt: (ctx: NativeHandle, option: number) => number;
|
|
6
|
+
ctxGetOptData: (ctx: NativeHandle, option: number) => NativeBuffer;
|
|
7
|
+
ctxGetAutoHwmBudgetSnapshot: (ctx: NativeHandle) => CoreHwmBudgetSnapshotRaw;
|
|
8
|
+
ctxNew: () => NativeHandle;
|
|
9
|
+
ctxRecalculateAutoHwm: (ctx: NativeHandle) => void;
|
|
10
|
+
ctxResetAutoHwmBudgetMetrics: (ctx: NativeHandle) => void;
|
|
11
|
+
ctxSetOpt: (ctx: NativeHandle, option: number, value: number | NativeBuffer) => void;
|
|
12
|
+
ctxShutdown: (ctx: NativeHandle) => void;
|
|
13
|
+
ctxTerm: (ctx: NativeHandle) => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NativeHandle, NativeVersion, NullableNativeHandle } from './binding_types';
|
|
2
|
+
export interface CoreNativeBinding {
|
|
3
|
+
errno: () => number;
|
|
4
|
+
messageAllocate: (size: number) => {
|
|
5
|
+
data?: Buffer;
|
|
6
|
+
nativeMessage: unknown;
|
|
7
|
+
};
|
|
8
|
+
messageFrameData: (nativeMessage: unknown) => Buffer;
|
|
9
|
+
messageFrameCopyData: (nativeMessage: unknown) => Buffer;
|
|
10
|
+
messageFrameSize: (nativeMessage: unknown) => number;
|
|
11
|
+
messageFrameClose: (nativeMessage: unknown) => void;
|
|
12
|
+
messageFromBuffer: (data: Buffer) => {
|
|
13
|
+
data?: Buffer;
|
|
14
|
+
nativeMessage: unknown;
|
|
15
|
+
};
|
|
16
|
+
has: (capability: string) => boolean;
|
|
17
|
+
proxy: (frontend: NativeHandle, backend: NativeHandle, capture: NullableNativeHandle) => void;
|
|
18
|
+
sleep: (seconds: number) => void;
|
|
19
|
+
strerror: (code: number) => string;
|
|
20
|
+
version: () => NativeVersion;
|
|
21
|
+
}
|