{"id":20500963,"url":"https://github.com/caesay/mpack","last_synced_at":"2025-07-13T05:33:51.259Z","repository":{"id":117004107,"uuid":"47306599","full_name":"caesay/MPack","owner":"caesay","description":"A lightweight MessagePack Implementation | msgpack.org[C#]","archived":false,"fork":false,"pushed_at":"2024-03-13T23:27:58.000Z","size":95,"stargazers_count":22,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-13T13:53:55.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/caesay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-12-03T04:01:00.000Z","updated_at":"2025-05-27T13:44:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8683ae5-d675-411d-ba8e-a649face9030","html_url":"https://github.com/caesay/MPack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/caesay/MPack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FMPack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FMPack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FMPack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FMPack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caesay","download_url":"https://codeload.github.com/caesay/MPack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caesay%2FMPack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265094544,"owners_count":23710499,"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","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":[],"created_at":"2024-11-15T18:23:35.324Z","updated_at":"2025-07-13T05:33:51.213Z","avatar_url":"https://github.com/caesay.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MPack\nThis library is a lightweight implementation of the [MessagePack](http://msgpack.org/) binary serialization format. MessagePack is a 1-to-1 binary representation of JSON, and the official specification can be found here: [https://github.com/msgpack...](https://github.com/msgpack/msgpack/blob/master/spec.md).\n\n## Implementation Notes\n* This library is designed to be super light weight.\n* Its easiest to understand how this library works if you think in terms of json. The type `MDict` represents a dictionary, and the type `MArray` represents an array. \n* Create MPack values with the static method `MToken.From(object);`. You can pass any simple type (such as string, integer, etc), or any Array composed of a simple type. MPack also has implicit conversions from most of the basic types built in.\n* Transform an MPack object back into a CLR type with the static method `MToken.To\u003cT\u003e();` or `MToken.To(type);`. MPack also has **explicit** converions going back to most basic types, you can do `string str = (string)mpack;` for instance.\n* MPack now supports native asynchrounous reading and cancellation tokens. It will *not* block a thread to wait on a stream.\n\n## NuGet\nMPack is available as a [NuGet package](https://www.nuget.org/packages/MPack)!\n```\nPM\u003e Install-Package MPack\n```\n\n## Usage\n-----\nCreate a object model that can be represented as MsgPack. Here we are creating a dictionary, but really it can be anything:\n```csharp\nusing MPack;\n\nvar dictionary = new MDict\n{\n    {\n        \"array1\", MToken.From(new[]\n        {\n            \"array1_value1\",  // implicitly converted string\n            MToken.From(\"array1_value2\"),\n        })\n    },\n    {\"bool1\", MToken.From(true)}, //boolean\n    {\"double1\", MToken.From(50.5)}, //single-precision float\n    {\"double2\", MToken.From(15.2)},\n    {\"int1\", 50505}, // implicitly converted integer\n    {\"int2\", MToken.From(50)} // integer\n};\n```\nSerialize the data to a byte array or to a stream to be saved, transmitted, etc:\n```csharp\nbyte[] encodedBytes = dictionary.EncodeToBytes();\n// -- or --\ndictionary.EncodeToStream(stream);\n```\nParse the binary data back into a MPack object model (you can also cast back to an MPackMap or MPackArray after reading if you want dictionary/array methods):\n```csharp\nvar reconstructed = MToken.ParseFromBytes(encodedBytes);\n// -- or --\nvar reconstructed = MToken.ParseFromStream(stream);\n```\nTurn MPack objects back into types that we understand with the generic `To\u003c\u003e()` method. Since we know the types of everything here we can just call `To\u003cbool\u003e()` to reconstruct our bool, but if you don't know you can access the instance enum `MToken.ValueType` to know what kind of value it is:\n```csharp\nbool bool1 = reconstructed[\"bool1\"].To\u003cbool\u003e();\nvar array1 = reconstructed[\"array1\"] as MArray;\nvar array1_value1 = array1[0];\ndouble double1 = reconstructed[\"double1\"].To\u003cdouble\u003e();\n//etc...\n```\n\n## Complex Types\n\nBeyond converting basic/primitive types, there is a very basic object serializer built in.\n\nIf your object has the `[DataContract]` attribute, all properties/fields with the `[DataMember]` attribute will be serialized.\n\n```csharp\n[DataContract]\nclass MyObject\n{\n    [DataMember]\n    public string Name { get; set; }\n\n    [DataMember]\n    public int Age { get; set; }\n\n    // following will NOT be serialized, because missing [DataMember] attribute\n    public List\u003cstring\u003e Friends { get; set; } \n}\n\n// ...\nvar token = MToken.From(new MyObject { Name = \"John\", Age = 25 });\nvar bytes = token.EncodeToBytes();\nvar reconstructed = MToken.ParseFromBytes(bytes);\nvar reconstructedObj = reconstructed.To\u003cMyObject\u003e();\n```\n\nIf your object does not have the `[DataContract]` attribute, all public properties will be serialized, \nand you can use the `[IgnoreDataMember]` attribute to exclude properties from serialization.\n\n```csharp\nclass MyObject\n{\n    public string Name { get; set; }\n\n    public int Age { get; set; }\n\n    [IgnoreDataMember] // will not be serialized\n    public List\u003cstring\u003e Friends { get; set; }\n}\n```\n\n## Disclaimer\nThis is a very basic/simple implementation of the MessagePack format.\nThis library is not optimized for performance, and the object serialization is very basic. It is not recommended for use in high-performance, \nhigh-throughput scenarios, or for serializing complex object models. For those scenarios, consider using a more robust library such as\n[MessagePack-CSharp](https://github.com/MessagePack-CSharp/MessagePack-CSharp).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesay%2Fmpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaesay%2Fmpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesay%2Fmpack/lists"}