{"id":14960639,"url":"https://github.com/deniszykov/msgpack-unity3d","last_synced_at":"2025-04-12T17:45:38.754Z","repository":{"id":48967246,"uuid":"55433521","full_name":"deniszykov/msgpack-unity3d","owner":"deniszykov","description":"MessagePack and JSON serializer for Unity3D","archived":false,"fork":false,"pushed_at":"2024-10-08T08:52:32.000Z","size":647,"stargazers_count":104,"open_issues_count":6,"forks_count":14,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-03T20:11:18.651Z","etag":null,"topics":["json","json-serialization","messagepack","messagepack-serializer","unity-asset","unity-plugin","unity3d"],"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/deniszykov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-04T18:07:30.000Z","updated_at":"2025-01-18T22:35:32.000Z","dependencies_parsed_at":"2024-12-17T11:02:11.332Z","dependency_job_id":null,"html_url":"https://github.com/deniszykov/msgpack-unity3d","commit_stats":{"total_commits":125,"total_committers":1,"mean_commits":125.0,"dds":0.0,"last_synced_commit":"3f0f9c4273706f43338ed9939135ed9408a41401"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniszykov%2Fmsgpack-unity3d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniszykov%2Fmsgpack-unity3d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniszykov%2Fmsgpack-unity3d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniszykov%2Fmsgpack-unity3d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deniszykov","download_url":"https://codeload.github.com/deniszykov/msgpack-unity3d/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248609545,"owners_count":21132915,"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":["json","json-serialization","messagepack","messagepack-serializer","unity-asset","unity-plugin","unity3d"],"created_at":"2024-09-24T13:22:39.421Z","updated_at":"2025-04-12T17:45:38.733Z","avatar_url":"https://github.com/deniszykov.png","language":"C#","readme":"[![Build Status](https://travis-ci.org/deniszykov/msgpack-unity3d.svg?branch=master)](https://travis-ci.org/deniszykov/msgpack-unity3d)\n\n# Introduction\n\nThis [package](https://assetstore.unity.com/packages/tools/network/json-messagepack-serialization-59918) provides an API for data serialization/deserialization into [MessagePack](https://en.wikipedia.org/wiki/MessagePack) and [JSON](https://en.wikipedia.org/wiki/JSON) formats.\n\nSupported Platforms:\n\n* PC/Mac\n* iOS\n* Android\n* WebGL\n\n**API**\n\n* JSON\n  * Serialize\n  * SerializeToString\n  * Deserialize\n* MsgPack\n  * Serialize\n  * Deserialize\n\n## Installation\n\n### NuGet\n\n```bash\nPM\u003e Install-Package GameDevWare.Serialization\n```\n\n### Unity3D\n\n[Json + MessagePack Serializer](https://assetstore.unity.com/packages/tools/network/json-messagepack-serialization-59918)\n\n## Example\n\nSerialize an object into a [Stream](https://msdn.microsoft.com/en-us/library/system.io.stream%28v=vs.90%29.aspx) using a MessagePack serializer:\n\n```csharp\nvar outputStream = new MemoryStream();\nMsgPack.Serialize(new { field1 = 1, field2 = 2 }, outputStream);\noutputStream.Position = 0; // rewind stream before copying/reading\n```\n\nDeserialize an object from a [Stream](https://msdn.microsoft.com/en-us/library/system.io.stream%28v=vs.90%29.aspx) using a MessagePack serializer:\n\n```csharp\nStream inputStream;\nMsgPack.Deserialize(typeof(MyObject), inputStream); // -\u003e instance of MyObject\n// or\nMsgPack.Deserialize\u003cMyObject\u003e(inputStream); // -\u003e instance of MyObject\n```\n\n## Breaking Change in v2.0\n\n### Message Pack Endianness\n\nMessage Pack serialization prior to v2.0 used a [little-endian](https://en.wikipedia.org/wiki/Endianness) byte order for multi-byte integers. That doesn't correspond to the [specification](https://github.com/msgpack/msgpack/blob/master/spec.md). Data saved with **little-endian** formatting could be re-written to **big-endian** with the following code:\n\n```csharp\nvar context = new SerializationContext { Options = SerializationOptions.SuppressTypeInformation };\nusing (var fileStream = File.Open(\"\u003cpath to file\u003e\", FileMode.Open, FileAccess.ReadWrite))\n{\n    var reader = new MsgPackReader(fileStream, context, Endianness.LittleEndian);\n    var value = reader.ReadValue(typeof(object));\n    fileStream.Position = 0;\n    var writer = new MsgPackWriter(fileStream, context);\n    writer.WriteValue(value, typeof(object));\n    fileStream.SetLength(fileStream.Position);\n}\n```\n\n### Data Contract Attributes\n\n* The [IgnoreDataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.ignoredatamemberattribute%28v=vs.110%29.aspx) attribute is only honored when used with unmarked types. This includes types that are not marked with the [DataContract](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute%28v=vs.110%29.aspx) attribute.\n* You can apply the [DataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute%28v=vs.110%29.aspx) attribute to **PUBLIC** fields and properties.\n* The [DataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute%28v=vs.110%29.aspx) and [IgnoreDataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.ignoredatamemberattribute%28v=vs.110%29.aspx) attributes are ignored if they are applied to static members.\n* The [DataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute%28v=vs.110%29.aspx) attribute is ignored if the [DataContract](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute%28v=vs.110%29.aspx) attribute is not applied.\n* During serialization, property-get code is called for property data members to get the value of the properties to be serialized.\n* During deserialization, a new object is first created by calling an empty constructor on the type. Then all data members are deserialized.\n* During deserialization, property-set code is called for property data members to set the properties to the value being deserialized.\n\n## Mapping Types\n\nThe MessagePack/Json serializer is guided by [Data Contract](https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx) rules. Its behavior can be changed with [DataContract](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute%28v=vs.110%29.aspx), [DataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute%28v=vs.110%29.aspx), and [IgnoreDataMember](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.ignoredatamemberattribute%28v=vs.110%29.aspx) attributes. Attributes can be from *System.Runtime.Serialization.dll* or your attributes with the same names.\n\n## Supported Types\n\n* Primitives: Boolean, Byte, Double, Int16, Int32, Int64, SByte, Single, UInt16, UInt32, UInt64, String\n* Standard Types: Decimal, DateTimeOffset, DateTime, TimeSpan, Guid, Uri, Version, DictionaryEntry\n* Unity3D Types: Bounds, Vector, Matrix4x4, Quaternion, Rect, Color\n* Binary: Stream, byte[]\n* Lists: Array, ArrayList, List\u003cT\u003e, HashSet\u003cT\u003e and any other [IEnumerable](https://msdn.microsoft.com/en-us/library/system.collections.ienumerable%28v=vs.110%29.aspx) types with an **Add** method.\n* Maps: Hashtable, Dictionary\u003cK,V\u003e, and other [IDictionary](https://msdn.microsoft.com/en-us/library/system.collections.idictionary%28v=vs.110%29.aspx) types\n* [Nullable](https://msdn.microsoft.com/en-us/library/b3h38hb0%28v=vs.110%29.aspx) types\n* Enums\n* Custom classes\n\n## Custom Type Serializers\n\nTo implement a custom [TypeSerializer](https://github.com/deniszykov/msgpack-unity3d/blob/master/Assets/Plugins/GameDevWare.Serialization/TypeSerializer.cs) you need to inherit from *TypeSerializer* and override the Deserialize and Serialize methods.\n\n```csharp\npublic sealed class GuidSerializer : TypeSerializer\n{\n    public override Type SerializedType { get { return typeof(Guid); } }\n    \n    public override object Deserialize(IJsonReader reader)\n    { \n        // General rule of 'Deserialize' is to leave reader on\n        // last token of deserialized value. It is EndOfObject or EndOfArray, or Value.\n        // 'nextToken: true' will call 'reader.NextToken()' AFTER 'ReadString()'.\n        // Since it is last token on de-serialized value we set 'nextToken: false'.\n        var guidStr = reader.ReadString(nextToken: false);\n        var value = new Guid(guidStr);\n        return value;\n    }\n\n    public override void Serialize(IJsonWriter writer, object valueObj)\n    {\n        var value = (Guid)valueObj; // valueObj is not null\n        var guidStr = value.ToString();\n        writer.Write(guidStr);\n    }\n}\n```\n\nThen you need to register your class in the *Json.DefaultSerializers* collection or mark it with the [TypeSerializerAttribute](https://github.com/deniszykov/msgpack-unity3d/blob/master/Assets/Plugins/GameDevWare.Serialization/TypeSerializerAttribute.cs).\n\n## Extra Type Information\n\nThere is additional type information with each serialized object. It increases the size of the serialized data. If you do not want to store object's type information, specify *SuppressTypeInformation* when calling the **Serialize** method.\n\n```csharp\nMsgPack.Serialize(value, stream, SerializationOptions.SuppressTypeInformation);\n```\n\nIf you want to ignore type information when deserializing an object, specify *SuppressTypeInformation* when calling the **Deserialize** method.\n\n```csharp\nMsgPack.Deserialize(typeof(MyObject), stream, SerializationOptions.SuppressTypeInformation);\n```\n\n## IL2CPP - AOT :grey_exclamation:\n\nAdditional preparation should be made for AOT execution platforms. A `link.xml` file should be added to the project's root folder. This file should exclude the _System.Runtime.Serialization.dll_ assembly from IL stripping. Read more about [IL code stripping](https://docs.unity3d.com/Manual/IL2CPP-BytecodeStripping.html) in the official documentation.\n\n## Contacts\nPlease send any questions at support@gamedevware.com\n\n## License\n[MIT](License.md)\n","funding_links":[],"categories":["Serialization"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniszykov%2Fmsgpack-unity3d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeniszykov%2Fmsgpack-unity3d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniszykov%2Fmsgpack-unity3d/lists"}