{"id":"wobotomite/sendbufs","name":"sendbufs","scope":"wobotomite","platform":"roblox","description":"extensible networking lib with compression","version":"1.1.3","latest":"1.1.3","versions":["1.1.3"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"e658dc21f1746b0527644ff122737a42678e0239627fd7608bad6fe616618540","likes":0,"downloads":0,"install":"forest install wobotomite/sendbufs","url":"https://forest.dev/p/roblox/wobotomite/sendbufs","files":"https://api.forest.dev/ai/package/roblox/wobotomite/sendbufs/files","readme":"# Intro:\nsendbufs is a networking library with buffer compression and type validation via schemas.\n## Getting Started\n1. create a shared network definitions script (i.e. ReplicatedStorage/network-definitions.luau)\n2. export remotes out of it in a table:\n```lua\nconst remotes = table.freeze {\n  test_remote = sendbufs.event(),\n\tcore = {\n\t\tsend_alert = sendbufs.event(sendbufs.schema.struct {\n\n\t\t\tmessage = sendbufs.schema.str,\n\t\t\tsound = sendbufs.schema.maybe(sendbufs.schema.str),\n\t\t}),\n\t\tsync_charm = sendbufs.event(sendbufs.schema.ref),\n\t\tupdate_settings = sendbufs.event(sendbufs.schema.struct {\n\t\t\tid = sendbufs.schema.str,\n\t\t\tval = sendbufs.schema.ref,\n\t\t}),\n\t\tupdate_camera_focus = sendbufs.event(sendbufs.schema.vector(sendbufs.schema.f32)),\n\n\t\tget_group_rewards = sendbufs.event(),\n    test_fn = sendbufs.fn(), -- input: nil, output: nil because the args are empty.\n\t},\n}\nsendbufs.middleware(remotes.core.update_camera_focus, rate_limit(1 / 10))\nreturn remotes;\n```\n3. create a server & a client module to use the network definitions in:\n```lua\n-- CLIENT:\nconst network_definitions = require(...);\nreturn sendbufs.create_client(network_definitions)\n-- SERVER:\nconst network_definitions = require(...);\nreturn sendbufs.create_server(network_definitions, 4096) -- optional, 4096 by default. the max size of one packet a client can send to the server. clients split their batches to fit, so only a single message bigger than this gets dropped.\n```\n4. require & use:\n```lua\n-- CLIENT:\nnetwork.core.update_camera_focus:fire(Vector3.new(.7,0,.7))\nnetwork.core.test_fn:invoke();\n-- SERVER:\nconst dc = network.core.update_camera_focus:connect(function(plr, vec) -- types are inferred\nend)\n\nif \"no longer needed\" then\ndc() -- disconnect\nend\n\nnetwork.core.test_fn:set_callback(function(plr) -- one callback per remote function: calling set_callback again logs an error and keeps the first one.\nreturn true, nil -- 1st value is the success, second is the result. return false to tell the client the function failed.\nend)\n```\n","readmeTruncated":false}