{"id":"cg955gtr/switchnet2","name":"switchnet2","scope":"cg955gtr","platform":"roblox","description":"An efficient strictly-typed networking module for reducing bandwidth and overhead across remotes. Strictly-typed variant of original SwitchNet","version":"0.5.1","latest":"0.5.1","versions":["0.0.0","0.2.0","0.3.0","0.3.1","0.3.2","0.3.3","0.3.4","0.4.0","0.5.0","0.5.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"f5ed1a523305948b698336df17b83e9fbab37a000c207c2f9f298543d8787de0","likes":0,"downloads":0,"install":"forest install cg955gtr/switchnet2","url":"https://forest.dev/p/roblox/cg955gtr/switchnet2","files":"https://api.forest.dev/ai/package/roblox/cg955gtr/switchnet2/files","readme":"# SwitchNet2\n\nAn efficient strictly-typed networking module for reducing bandwidth and overhead across remotes.\nIt has similar syntax to ByteNet, except with proper --!strict compatibility and more efficient compression/decompression.\n> ^ Compression is especially much more efficient, most notably when dealing with complex type structures\n\n# Installation\n\n> SwitchNet2 can be installed via. Wally, or via the .rbxm in latest releases.\n\n# Documentation\n\n- **[Main](./docs/docs.md)**\n- **[Packet](./docs/packet.md)**\n- **[Query](./docs/query.md)**\n- **[Types](./docs/types.md)**\n\n```luau\nconst SwitchNet2 = require(path_to_switchnet_here)\n```\n\n# Overview & Basic Example Usage\n\nRemote bridges are defined/registered by creating namespaces with packets.\n\nAll schema types are stored in the `SwitchNet2.Types` dictionary.\n\n> Example namespace:\n```luau\nconst packets = SwitchNet2.RegisterNamespace(\"ExampleNamespace123\", {\n\n\ttestPacket1 = SwitchNet2.RegisterPacket({\n\t\tMode = \"Reliable\", --// can be \"Reliable\" or \"Unreliable\", unreliable communicates via UnreliableRemoteEvent\n\t\tType = SwitchNet2.Types.string, --// The actual type schema used to define the packet structure.\n\t}),\n\n\ttestPacket2 = SwitchNet2.RegisterPacket({\n\t\tMode = \"Unreliable\",\n\t\tType = SwitchNet2.Types.struct({\n\t\t\tid = SwitchNet2.Types.u32,\n\t\t\tmessage = SwitchNet2.Types.string,\n\t\t\tposition = SwitchNet2.Types.Vector3,\n\t\t\toptionalData = SwitchNet2.Types.optional(SwitchNet2.Types.auto),\n\t\t}),\n\t}),\n\n\n\ttestQuery1 = SwitchNet2.RegisterQuery({\n\t\tRequestType = SwitchNet2.Types.string, --// type schema for sending requests\n\t\tResponseType = SwitchNet2.Types.boolean, --// type schema for receiving responses\n\t}),\n\n\ttestQuery2 = SwitchNet2.RegisterQuery({\n\t\tRequestType = SwitchNet2.Types.string,\n\t\tResponseType = SwitchNet2.Types.u8,\n\t\tTimeout = 30, --// optional timeout parameter (in seconds), request is dropped if no response by then\n\t}),\n\n})\n```\n\nAdditionally, Each packet/query's schema will also automatically infer the argument/parameter types when you use their methods.\n\n```lua\npackets.testPacket2.ListenClient(function(data)\n\t--[=[\n\t\tThe 'data' parameter is automatically inferred as:\n\n\t\tdata: {\n\t\t\tid: number,\n\t\t\tmessage: string,\n\t\t\tposition: Vector3,\n\t\t\toptionalData: any?,\n\t\t}\n\t]=]\nend)\n```\n\n> Examples of utilizing packets:\n```luau\npackets.testPacket1.ListenServer(function(data: string, player: Player)\n\tprint(`Received {player.Name}'s message: {data}`)\n\tpackets.testPacket1.Send(`Hello {player.Name}!`, player) --// relay back to player\nend)\n\npackets.testPacket1.SendToAll(\"Hello everyone!\")\npackets.testPacket1.SendToAllExcept(\"Hello (nearly) everyone!\", other_player_here)\n\nlocal isConnected: boolean = packets.testQuery1.Invoke(\"IS_CONNECTED\", random_player_here)\nwarn(`{random_player_here.Name} is {if isConnected then \"connected\" else \"NOT connected\"}!`)\n```","readmeTruncated":false}