{"id":18397136,"url":"https://github.com/hecomi/upacketdivision","last_synced_at":"2026-03-11T01:31:54.791Z","repository":{"id":39374612,"uuid":"432676556","full_name":"hecomi/uPacketDivision","owner":"hecomi","description":"A native plugin for Unity that provides simple packet division and restoration.","archived":false,"fork":false,"pushed_at":"2021-11-29T15:05:46.000Z","size":214,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-30T05:48:37.327Z","etag":null,"topics":["udp","unity"],"latest_commit_sha":null,"homepage":"https://tips.hecomi.com/entry/2021/11/29/234527","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hecomi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-28T10:05:24.000Z","updated_at":"2024-01-01T07:20:30.000Z","dependencies_parsed_at":"2022-09-12T21:23:46.965Z","dependency_job_id":null,"html_url":"https://github.com/hecomi/uPacketDivision","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hecomi/uPacketDivision","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuPacketDivision","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuPacketDivision/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuPacketDivision/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuPacketDivision/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hecomi","download_url":"https://codeload.github.com/hecomi/uPacketDivision/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuPacketDivision/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273430444,"owners_count":25104479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["udp","unity"],"created_at":"2024-11-06T02:15:54.827Z","updated_at":"2026-03-11T01:31:54.757Z","avatar_url":"https://github.com/hecomi.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"uPacketDivision\n===============\n\nThis is a native plug-in that divides a given data (`System.IntPtr` or array) into specified sizes and restores them regardless of the input order. It is intended for use cases such as sending large data via UDP.\n\nInstall\n-------\n\n- Unity Package\n  - Download the latest .unitypackage from [Release page](https://github.com/hecomi/uPacketDivision/releases).\n- Git URL (UPM)\n  - Add `https://github.com/hecomi/uPacketDivision.git#upm` to Package Manager.\n- Scoped Registry (UPM)\n  - Add a scoped registry to your project.\n    - URL: `https://registry.npmjs.com`\n    - Scope: `com.hecomi`\n  - Install uPacketDivision in Package Manager.\n\nPlatforms\n---------\n\nCurrently, it is only built for Windows.\n\nHow to use\n----------\n\n### Divide\n\nCreate a `Divider` and call `Divide\u003cT\u003e(T[])` with the array as input (or `Divide(System.IntPtr, int size)`). This will divide the packet internally.\n\n```cs\nDivider divider = new Divider();\n\nvoid Divide()\n{\n    Texture2D image;\n    var pixels = image.GetPixels32();\n    divider.maxPacketSize = packetSize;\n    divider.Divide(pixels);\n}\n```\n\nThen, send the split data to the remote in some way. The following functions are available.\n- `GetChunkCount()`.\n  - the number of chunks.\n- `GetChunk()`\n  - The `byte[]` array of the split data\n- `GetChunkSize(int index)`.\n  - The size of the split data.\n- `GetChunkData(int index)`.\n  - The pointer of the split data\nHere is an example of using [uOSC](https://github.com/hecomi/uOSC).\n\n```cs\nuOSC.uOscClient client;\n\nvoid Send(int width, int height)\n{\n    client.Send(\"/Size\", width, height);\n\n    for (uint i = 0; i \u003c divider.GetChunkCount(); ++i)\n    {\n        client.Send(\"/Data\", divider.GetChunk(i));\n    }\n}\n```\n\nIf you want to use the pointer and size directly, please use `GetChunkSize()` and `GetChunkData()` instead.\n\n### Assemble\n\nUse `Assembler` to assemble the data sent to you. Here is an example of the receiving part using uOSC.\n\n```cs\nAssembler assembler = new Assembler();\nTexture2D texture;\n\npublic void OnDataReceived(uOSC.Message message)\n{\n    if (message.address == \"/Size\")\n    {\n        var w = (int)message.values[0];\n        var h = (int)message.values[1];\n        OnSize(w, h);\n    }\n    else if (message.address == \"/Data\")\n    {\n        var data = (byte[])message.values[0];\n        OnData(data);\n        CheckEvent();\n    }\n}\n\nvoid OnSize(int w, int h)\n{\n    texture = new Texture2D(w, h);\n}\n\nvoid OnData(byte[] data)\n{\n    assembler.timeout = timeout;\n    assembler.Add(data);\n}\n```\n\nEach time you add data, check for the completion or loss as follows.\n\n```cs\nvoid CheckEvent()\n{\n    switch (assembler.GetEventType())\n    {\n        case EventType.FrameCompleted:\n        {\n            OnDataAssembled(assembler.GetAssembledData\u003cColor32\u003e());\n            break;\n        }\n        case EventType.PacketLoss:\n        {\n            var type = assembler.GetLossType();\n            Debug.LogWarning(\"Loss: \" + type);\n            break;\n        }\n        default:\n        {\n            break;\n        }\n    }\n}\n```\n\nIf you want to get a pointer and its size instead of an array, the following APIs are available.\n\n```cs\nvar index = assembler.GetAssembledFrameIndex();\nvar data = assembler.GetFrameData(index);\nvar size = assembler.GetFrameSize(index);\nOnDataAssembled(data, (int)size);\nassembler.RemoveFrame(index);\n```\n\nThen, the data reconstruction will be completed as follows.\n\n```cs\nvoid OnDataAssembled(Color32[] pixels)\n{\n    texture.SetPixels32(pixels);\n    texture.Apply();\n    GetComponent\u003cRenderer\u003e().material.mainTexture = texture;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhecomi%2Fupacketdivision","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhecomi%2Fupacketdivision","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhecomi%2Fupacketdivision/lists"}