MCPcopy Index your code
hub / github.com/deepclause/agentvm / writeMessage

Method writeMessage

src/ringbuffer.js:106–138  ·  view source on GitHub ↗

* Write a network message to the ring buffer * @param {number} type - Message type (NET_MSG_*) * @param {Uint8Array|Buffer} payload - Message payload * @returns {boolean} - True if written, false if no space

(type, payload)

Source from the content-addressed store, hash-verified

104 * @returns {boolean} - True if written, false if no space
105 */
106 writeMessage(type, payload) {
107 const msgLen = 3 + payload.length; // 2 bytes length + 1 byte type + payload
108
109 if (this.availableSpace() < msgLen) {
110 return false; // No space
111 }
112
113 let head = Atomics.load(this.int32, NET_HEAD_INDEX);
114 const ringStart = NET_RING_OFFSET;
115
116 // Write length (2 bytes, little-endian)
117 this.uint8[ringStart + head] = payload.length & 0xFF;
118 head = (head + 1) % NET_RING_SIZE;
119 this.uint8[ringStart + head] = (payload.length >> 8) & 0xFF;
120 head = (head + 1) % NET_RING_SIZE;
121
122 // Write type (1 byte)
123 this.uint8[ringStart + head] = type;
124 head = (head + 1) % NET_RING_SIZE;
125
126 // Write payload
127 for (let i = 0; i < payload.length; i++) {
128 this.uint8[ringStart + head] = payload[i];
129 head = (head + 1) % NET_RING_SIZE;
130 }
131
132 // Update head atomically and signal
133 Atomics.store(this.int32, NET_HEAD_INDEX, head);
134 Atomics.add(this.int32, IO_READY_INDEX, 1);
135 Atomics.notify(this.int32, IO_READY_INDEX);
136
137 return true;
138 }
139
140 /**
141 * Write TCP connected event

Callers 6

writeTcpConnectedMethod · 0.95
writeTcpDataMethod · 0.95
writeTcpEndMethod · 0.95
writeTcpErrorMethod · 0.95
writeTcpCloseMethod · 0.95
writeUdpRecvMethod · 0.95

Calls 1

availableSpaceMethod · 0.95

Tested by

no test coverage detected