import protobuf from "npm:protobufjs"; import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts"; /** * Proof of Concept: Protocol Buffers (Gen 2) * * Demonstrates serializing and deserializing agent state using actual * protobufjs instead of a JSON stringifier mock, showing high-performance * I/O for vector math and state passing. */ const protoDefinition = ` syntax = "proto3"; message AgentState { string agentId = 1; string status = 2; int32 memoryUsage = 3; } `; if (import.meta.main) { console.log("Running Protocol Buffers PoC (Gen 2) tests..."); try { const root = protobuf.parse(protoDefinition).root; const AgentState = root.lookupType("AgentState"); const payload = { agentId: "adversary-01", status: "active", memoryUsage: 1024, }; const errMsg = AgentState.verify(payload); if (errMsg) throw Error(errMsg); const message = AgentState.create(payload); const buffer = AgentState.encode(message).finish(); console.log(`Original Data:`, payload); console.log(`Serialized Size: ${buffer.length} bytes (binary)`); const decodedMessage = AgentState.decode(buffer); const deserialized = AgentState.toObject(decodedMessage, { longs: String, enums: String, bytes: String, }); console.log("Deserialized Data:", deserialized); assertEquals(deserialized.agentId, payload.agentId); assertEquals(deserialized.status, payload.status); assertEquals(deserialized.memoryUsage, payload.memoryUsage); console.log( "✅ Protocol Buffers PoC (Gen 2) successful: Real protobuf serialization/deserialization worked.", ); } catch (err) { console.error("❌ Protocol Buffers PoC (Gen 2) failed:", err); Deno.exit(1); } }