All Projects → deniszykov → Msgpack Unity3d

deniszykov / Msgpack Unity3d

Licence: mit
MessagePack and JSON serializer for Unity3D

Projects that are alternatives of or similar to Msgpack Unity3d

Savegamefree
Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.
Stars: ✭ 279 (+277.03%)
Mutual labels:  json-serialization, unity3d, unity-asset
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+812.16%)
Mutual labels:  json, unity3d, unity-asset
Json
JSON for Modern C++
Stars: ✭ 27,824 (+37500%)
Mutual labels:  json, messagepack, json-serialization
Jsoncons
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
Stars: ✭ 400 (+440.54%)
Mutual labels:  json, messagepack, json-serialization
Unitypcss
Nvidia's PCSS soft shadow algorithm implemented in Unity
Stars: ✭ 533 (+620.27%)
Mutual labels:  unity3d, unity-asset
Texturepanner
This repository hosts a shader for Unity3D whose main goal is to facilitate the creation of neon-like signs, conveyor belts and basically whatever based on scrolling textures
Stars: ✭ 528 (+613.51%)
Mutual labels:  unity3d, unity-asset
Fastjson
A fast JSON parser/generator for Java.
Stars: ✭ 23,997 (+32328.38%)
Mutual labels:  json, json-serialization
Radialprogressbar
Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc!
Stars: ✭ 714 (+864.86%)
Mutual labels:  unity3d, unity-asset
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+468.92%)
Mutual labels:  json, messagepack
Lunar Unity Console
High-performance Unity iOS/Android logger built with native platform UI
Stars: ✭ 628 (+748.65%)
Mutual labels:  unity3d, unity-asset
Spray Json
A lightweight, clean and simple JSON implementation in Scala
Stars: ✭ 917 (+1139.19%)
Mutual labels:  json, json-serialization
Unity3d Rainbow Folders
This asset allows you to set custom icons for any folder in unity project browser.
Stars: ✭ 519 (+601.35%)
Mutual labels:  unity3d, unity-asset
Element Api
Create a JSON API/Feed for your elements in Craft.
Stars: ✭ 493 (+566.22%)
Mutual labels:  json, json-serialization
Randomation Vehicle Physics
Vehicle physics system for the Unity engine.
Stars: ✭ 487 (+558.11%)
Mutual labels:  unity3d, unity-asset
Savegamepro
A Complete and Powerful Save Game Solution for Unity (Game Engine)
Stars: ✭ 30 (-59.46%)
Mutual labels:  unity3d, unity-asset
Jsondoc
JSON object for Delphi based on IUnknown and Variant
Stars: ✭ 20 (-72.97%)
Mutual labels:  json, json-serialization
Unity Assetpipeline Presentation
Unity project for "A Technical Deep-Dive into Unity's Asset Pipeline" presented at Develop: 2018
Stars: ✭ 31 (-58.11%)
Mutual labels:  unity3d, unity-asset
Eminim
JSON serialization framework for Nim, works from a Stream directly to any type and back. Depends only on stdlib.
Stars: ✭ 32 (-56.76%)
Mutual labels:  json, json-serialization
Holoshield
Highly customizable sci-fi shield / force field shader for Unity3D. Allows you to set edge power & color, inner texture scrolling, waviness, scale pulsation and procedural intensity noise. Implements tessellation for low-poly base meshes.
Stars: ✭ 401 (+441.89%)
Mutual labels:  unity3d, unity-asset
Uduino
Simple and easy connection between Arduino and Unity
Stars: ✭ 25 (-66.22%)
Mutual labels:  unity3d, unity-asset

Build Status

Introduction

This package provides API for data serialization/deserialization into MessagePack and JSON formats.

Supported Platforms:

  • PC/Mac
  • iOS
  • Android
  • WebGL

API

  • Json
    • Serialize
    • SerializeToString
    • Deserialize
  • MsgPack
    • Serialize
    • Deserialize

Installation

Nuget

PM> Install-Package GameDevWare.Serialization 

Unity3D

Json + MessagePack Serializer

Example

Serialize object into Stream using MessagePack serializer:

var outputStream = new MemoryStream();
MsgPack.Serialize(new { field1 = 1, field2 = 2 }, outputStream);
outputStream.Position = 0; // rewind stream before copying/read

Deserialize object from Stream using MessagePack serializer:

Stream inputStream;
MsgPack.Deserialize(typeof(MyObject), inputStream); -> instance of MyObject
// or
MsgPack.Deserialize<MyObject>(inputStream); -> instance of MyObject

Breaking Change in v2.0

Message Pack Endianness

Message Pack serialization prior to v2.0 uses little-endian byte order for multi-byte integers. That doesn't correspond to specification. Data saved with little-endian formatting could be re-written to big-endian with following code:

var context = new SerializationContext { Options = SerializationOptions.SuppressTypeInformation };
using (var fileStream = File.Open("<path to file>", FileMode.Open, FileAccess.ReadWrite))
{
				
	var reader = new MsgPackReader(fileStream, context, Endianness.LittleEndian);
	var value = reader.ReadValue(typeof(object)); 
	fileStream.Position = 0;                                                      
	var writer = new MsgPackWriter(fileStream, context);
	writer.WriteValue(value, typeof(object)); 
	fileStream.SetLength(fileStream.Position);
}

Data Contract Attributes

  • The IgnoreDataMember attribute is only honored when used with unmarked types. This includes types that are not marked with DataContract attribute.
  • You can apply the DataMember attribute to PUBLIC fields, and properties.
  • The DataMember and IgnoreDataMember attributes are ignored if it is applied to static members.
  • The DataMember attribute is ignored if DataContract attribute is not applied.
  • During serialization, property-get code is called for property data members to get the value of the properties to be serialized.
  • During deserialization, an new object is first created, with calling an empty constructor on the type. Then all data members are deserialized.
  • During deserialization, property-set code is called for property data members to set the properties to the value being deserialized.

Mapping Types

MessagePack/Json serializer is guided by Data Contract rules. Its behaviour can be changed with DataContract, DataMember, IgnoreDataMember attributes.

Attributes can be from System.Runtime.Serialization.dll or your attributes with same names.

Supported Types

  • Primitives: Boolean, Byte, Double, Int16, Int32, Int64, SBytes, Single, UInt16, UInt32, UInt64, String
  • Standard Types: Decimal, DateTimeOffset, DateTime, TimeSpan, Guid, Uri, Version, DictionaryEntry
  • Unity3D Types: Bounds, Vector, Matrix4x4, Quaternion, Rect, Color ...
  • Binary: Stream, byte[]
  • Lists: Array, ArrayList, List, HashSet and any other IEnumerable types with Add method.
  • Maps: Hashtable, Dictionary<K,V>, and other IDictionary types
  • Nullable types
  • Enums
  • Custom classes

Custom Type Serializers

To implement a custom TypeSerializer you need to inherit it from TypeSerializer and override Deserialize and Serialize methods.

public sealed class GuidSerializer : TypeSerializer
{
	public override Type SerializedType { get { return typeof(Guid); } }

	public override object Deserialize(IJsonReader reader)
	{
		// General rule of 'Deserialize' is to leave reader on 
		// last token of deserialized value. It is EndOfObject or EndOfArray, or Value.
		
		// 'nextToken: true' will call 'reader.NextToken()' AFTER 'ReadString()'.
		// Since it is last token on de-serialized value we set 'nextToken: false'.
		var guidStr = reader.ReadString(nextToken: false);
		var value = new Guid(guidStr);
		return value;
	}

	public override void Serialize(IJsonWriter writer, object valueObj)
	{
		var value = (Guid)valueObj; // valueObj is not null
		var guidStr = value.ToString();
		writer.Write(guidStr);
	}
}

Then you need to register your class in Json.DefaultSerializers collection or mark it with TypeSerializerAttribute.

Extra Type Information

There is additional type information with each serialized object. It increases size of the serialized data. If you do not want to store object's type information, specify SuppressTypeInformation when calling Serialize method.

MsgPack.Serialize(value, stream, SerializationOptions.SuppressTypeInformation);

If you want to ignore type information when deserializing an object, specify SuppressTypeInformation when calling Deserialize method.

MsgPack.Deserialize(typeof(MyObject), stream, SerializationOptions.SuppressTypeInformation);

IL2CPP - AOT

❕ An additional preparation should be made for AOT execution platforms. A link.xml file should be added in project's root folder. This file should exclude System.Runtime.Serialization.dll assembly from IL stripping. Read more about IL code stripping in official documentation.

Contacts

Please send any questions at [email protected]

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].