mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
Merge commit 'df5f79584312cf4f6cc7ec1d73a78f6ba475c9ad' as 'UniJSON'
Co-authored-by: Deatrathias <dmailsec@gmail.com> Co-authored-by: dj-kusuha <dj.kusuha+github@gmail.com> Co-authored-by: ousttrue <ousttrue@gmail.com> Co-authored-by: yutopp <yutopp@gmail.com>
This commit is contained in:
commit
df85433628
63
UniJSON/.circleci/config.yml
Normal file
63
UniJSON/.circleci/config.yml
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
version: 2
|
||||
jobs:
|
||||
update_unity_repo:
|
||||
docker:
|
||||
- image: circleci/buildpack-deps:latest
|
||||
|
||||
working_directory: ~/repo
|
||||
|
||||
environment:
|
||||
UniJSON_unity_REPO: "git@github.com:ousttrue/UniJSON-unity.git"
|
||||
|
||||
steps:
|
||||
- add_ssh_keys:
|
||||
fingerprints:
|
||||
- "5b:16:4a:8a:c9:a5:2c:80:37:d4:a5:b8:1b:0d:60:27"
|
||||
- run:
|
||||
name: Avoid hosts unknown for github
|
||||
command: echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
|
||||
- run:
|
||||
name: Clone UniJSON-unity (NOT UniJSON)
|
||||
command: |
|
||||
git clone ${UniJSON_unity_REPO}
|
||||
cd UniJSON-unity
|
||||
git submodule update --init
|
||||
|
||||
- run:
|
||||
name: Update submodule(UniJSON) in UniJSON-unity
|
||||
command: |
|
||||
cd UniJSON-unity/Assets/UniJSON
|
||||
git fetch && git checkout --force ${CIRCLE_SHA1}
|
||||
|
||||
- run:
|
||||
command: |
|
||||
cd UniJSON-unity
|
||||
git config user.email "yutopp+unijson-unity@users.noreply.github.com"
|
||||
git config user.name "unijson-unity job"
|
||||
|
||||
- run:
|
||||
command: |
|
||||
cd UniJSON-unity
|
||||
git add Assets/UniJSON
|
||||
git commit -m "[skip ci] Checkout UniJSON (${CIRCLE_SHA1})"
|
||||
|
||||
- run:
|
||||
command: |
|
||||
cd UniJSON-unity
|
||||
git status
|
||||
when: on_fail
|
||||
|
||||
- run:
|
||||
command: |
|
||||
cd UniJSON-unity
|
||||
git push origin master
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
build_test_deploy:
|
||||
jobs:
|
||||
- update_unity_repo:
|
||||
filters:
|
||||
branches:
|
||||
only: master
|
||||
9
UniJSON/Editor.meta
Normal file
9
UniJSON/Editor.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8feecbeea973dde4f944d365dc93e92c
|
||||
folderAsset: yes
|
||||
timeCreated: 1540820131
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Editor/Tests.meta
Normal file
9
UniJSON/Editor/Tests.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7288f19b28ff044ba00cefdb6458340
|
||||
folderAsset: yes
|
||||
timeCreated: 1526055787
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
UniJSON/Editor/Tests/IWriteStreamTest.cs
Normal file
44
UniJSON/Editor/Tests/IWriteStreamTest.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using NUnit.Framework;
|
||||
using UniJSON;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class StoreTests
|
||||
{
|
||||
[Test]
|
||||
public void StringBuilderStoreTest()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var stream = new StringBuilderStore(sb);
|
||||
|
||||
stream.Write("abc");
|
||||
Assert.AreEqual("abc", sb.ToString());
|
||||
|
||||
stream.Write("d");
|
||||
Assert.AreEqual("abcd", sb.ToString());
|
||||
|
||||
stream.Clear();
|
||||
stream.Write("e");
|
||||
Assert.AreEqual("e", sb.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArrayStoreTest()
|
||||
{
|
||||
var store = new BytesStore(1);
|
||||
|
||||
store.WriteValues(1, 2, 3);
|
||||
Assert.True(new Byte[] { 1, 2, 3 }.SequenceEqual(store.Bytes.ToEnumerable()));
|
||||
|
||||
store.Write(4);
|
||||
Assert.True(new Byte[] { 1, 2, 3, 4 }.SequenceEqual(store.Bytes.ToEnumerable()));
|
||||
|
||||
store.Clear();
|
||||
store.Write(5);
|
||||
Assert.True(new Byte[] { 5 }.SequenceEqual(store.Bytes.ToEnumerable()));
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/IWriteStreamTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/IWriteStreamTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bda1e03d682e63749a6b114fd6cc0add
|
||||
timeCreated: 1495517080
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Editor/Tests/Json.meta
Normal file
9
UniJSON/Editor/Tests/Json.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7467ac74a97f50646b5e954a34682bae
|
||||
folderAsset: yes
|
||||
timeCreated: 1543250519
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
UniJSON/Editor/Tests/Json/JsonDiffTests.cs
Normal file
71
UniJSON/Editor/Tests/Json/JsonDiffTests.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class JsonDiffTests
|
||||
{
|
||||
[Test]
|
||||
public void PathTest()
|
||||
{
|
||||
var json=@"
|
||||
{
|
||||
""a"": [
|
||||
{
|
||||
""aa"": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
";
|
||||
var root = JsonParser.Parse(json);
|
||||
|
||||
{
|
||||
var it = root.Traverse().GetEnumerator();
|
||||
it.MoveNext(); Assert.AreEqual("/", it.Current.Pointer().ToString());
|
||||
it.MoveNext(); Assert.AreEqual("/a", it.Current.Pointer().ToString());
|
||||
it.MoveNext(); Assert.AreEqual("/a/0", it.Current.Pointer().ToString());
|
||||
it.MoveNext(); Assert.AreEqual("/a/0/aa", it.Current.Pointer().ToString());
|
||||
Assert.False(it.MoveNext());
|
||||
}
|
||||
|
||||
{
|
||||
var it = root.Traverse().GetEnumerator();
|
||||
|
||||
var f = new JsonFormatter();
|
||||
f.Serialize("JsonPath");
|
||||
|
||||
root.SetValue(Utf8String.From("/a"), f.GetStoreBytes());
|
||||
it.MoveNext(); Assert.AreEqual("/", it.Current.Pointer().ToString());
|
||||
it.MoveNext(); Assert.AreEqual("/a", it.Current.Pointer().ToString());
|
||||
Assert.False(it.MoveNext());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiffTest()
|
||||
{
|
||||
var a = @"{
|
||||
""a"": 1
|
||||
}";
|
||||
|
||||
var b = @"{
|
||||
}";
|
||||
|
||||
var diff = JsonParser.Parse(a).Diff(JsonParser.Parse(b)).ToArray();
|
||||
Assert.AreEqual(1, diff.Length);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Test]
|
||||
public void Vector3()
|
||||
{
|
||||
var src = new UnityEngine.Vector3(1, 2, 3);
|
||||
var json = UnityEngine.JsonUtility.ToJson(src);
|
||||
Assert.AreEqual("{\"x\":1.0,\"y\":2.0,\"z\":3.0}", json);
|
||||
var dst = UnityEngine.JsonUtility.FromJson<UnityEngine.Vector3>(json);
|
||||
Assert.AreEqual(src, dst);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/JsonDiffTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/JsonDiffTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bafda51ddeeb2b84b920b119176499b8
|
||||
timeCreated: 1532154188
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
UniJSON/Editor/Tests/Json/JsonFormatterTest.cs
Normal file
47
UniJSON/Editor/Tests/Json/JsonFormatterTest.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class JsonFormatterTests
|
||||
{
|
||||
[Test]
|
||||
public void IndentTest()
|
||||
{
|
||||
var formatter = new JsonFormatter(2);
|
||||
formatter.BeginMap();
|
||||
formatter.Key("a"); formatter.Value(1);
|
||||
formatter.EndMap();
|
||||
|
||||
//var json = formatter.ToString();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullTest()
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes("null");
|
||||
var json = new JsonFormatter();
|
||||
json.Null();
|
||||
Assert.True(json.GetStoreBytes().ToEnumerable().SequenceEqual(bytes));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BooleanTest()
|
||||
{
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes("true");
|
||||
var json = new JsonFormatter();
|
||||
json.Value(true);
|
||||
Assert.True(json.GetStoreBytes().ToEnumerable().SequenceEqual(bytes));
|
||||
}
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes("false");
|
||||
var json = new JsonFormatter();
|
||||
json.Value(false);
|
||||
Assert.True(json.GetStoreBytes().ToEnumerable().SequenceEqual(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/JsonFormatterTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/JsonFormatterTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3defb263d8925164683447a978248b1d
|
||||
timeCreated: 1533569416
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
354
UniJSON/Editor/Tests/Json/JsonParserTest.cs
Normal file
354
UniJSON/Editor/Tests/Json/JsonParserTest.cs
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class JsonParserTest
|
||||
{
|
||||
[Test]
|
||||
public void Tests()
|
||||
{
|
||||
{
|
||||
var result = JsonParser.Parse("1");
|
||||
Assert.AreEqual(1, result.GetInt32());
|
||||
}
|
||||
|
||||
{
|
||||
var result = JsonParser.Parse("{ \"a\": { \"b\": 1 }}");
|
||||
Assert.True(result.ContainsKey("a"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullTest()
|
||||
{
|
||||
{
|
||||
var node = JsonParser.Parse("null");
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(4, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsNull());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BooleanTest()
|
||||
{
|
||||
{
|
||||
var node = JsonParser.Parse("true");
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(4, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsBoolean());
|
||||
Assert.AreEqual(true, node.GetBoolean());
|
||||
Assert.Catch(typeof(FormatException), () => node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse(" false ");
|
||||
Assert.AreEqual(1, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(5, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsBoolean());
|
||||
Assert.AreEqual(false, node.GetBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NumberTest()
|
||||
{
|
||||
{
|
||||
var node = JsonParser.Parse("1");
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(1, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsInteger());
|
||||
Assert.AreEqual(1, (int)node.GetDouble());
|
||||
Assert.Catch(typeof(DeserializationException), () => node.GetBoolean());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse(" 22 ");
|
||||
Assert.AreEqual(1, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(2, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsInteger());
|
||||
Assert.AreEqual(22, (int)node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse(" 3.3 ");
|
||||
Assert.AreEqual(1, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(3, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(3, (int)node.GetDouble());
|
||||
Assert.AreEqual(3.3f, (float)node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse(" -4.44444444444444444444 ");
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(-4, (int)node.GetDouble());
|
||||
Assert.AreEqual(-4.44444444444444444444, node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse(" -5e-4 ");
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(0, (int)node.GetDouble());
|
||||
Assert.AreEqual(-5e-4, node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse("NaN");
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(Double.NaN, node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse("Infinity");
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(Double.PositiveInfinity, node.GetDouble());
|
||||
}
|
||||
{
|
||||
var node = JsonParser.Parse("-Infinity");
|
||||
Assert.True(node.IsFloat());
|
||||
Assert.AreEqual(Double.NegativeInfinity, node.GetDouble());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StringTest()
|
||||
{
|
||||
{
|
||||
var value = "hoge";
|
||||
var quoted = "\"hoge\"";
|
||||
Assert.AreEqual(quoted, JsonString.Quote(value));
|
||||
var node = JsonParser.Parse(quoted);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(quoted.Length, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsString());
|
||||
Assert.AreEqual("hoge", node.GetString());
|
||||
}
|
||||
|
||||
{
|
||||
var value = "fuga\n hoge";
|
||||
var quoted = "\"fuga\\n hoge\"";
|
||||
Assert.AreEqual(quoted, JsonString.Quote(value));
|
||||
var node = JsonParser.Parse(quoted);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(quoted.Length, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsString());
|
||||
Assert.AreEqual(value, node.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StringEscapeTest()
|
||||
{
|
||||
{
|
||||
var value = "\"";
|
||||
var escaped = "\\\"";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\\";
|
||||
var escaped = "\\\\";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "/";
|
||||
var escaped = "\\/";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\b";
|
||||
var escaped = "\\b";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\f";
|
||||
var escaped = "\\f";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\n";
|
||||
var escaped = "\\n";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\r";
|
||||
var escaped = "\\r";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
{
|
||||
var value = "\t";
|
||||
var escaped = "\\t";
|
||||
Assert.AreEqual(escaped, JsonString.Escape(value));
|
||||
Assert.AreEqual(value, JsonString.Unescape(escaped));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ObjectTest()
|
||||
{
|
||||
{
|
||||
var json = "{}";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
|
||||
Assert.AreEqual(2, node.Value.Bytes.Count);
|
||||
|
||||
Assert.True(node.IsMap());
|
||||
Assert.AreEqual(0, node.ObjectItems().Count());
|
||||
}
|
||||
|
||||
{
|
||||
var json = "{\"key\":\"value\"}";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(json.Length, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsMap());
|
||||
|
||||
var it = node.ObjectItems().GetEnumerator();
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("key", it.Current.Key.GetString());
|
||||
Assert.AreEqual("value", it.Current.Value.GetString());
|
||||
|
||||
Assert.IsFalse(it.MoveNext());
|
||||
}
|
||||
|
||||
{
|
||||
var json = "{\"key\":\"value\"}";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
Assert.AreEqual(json.Length, node.Value.Bytes.Count);
|
||||
Assert.True(node.IsMap());
|
||||
|
||||
var it = node.ObjectItems().GetEnumerator();
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("key", it.Current.Key.GetString());
|
||||
Assert.AreEqual("value", it.Current.Value.GetString());
|
||||
|
||||
Assert.IsFalse(it.MoveNext());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedObjectTest()
|
||||
{
|
||||
{
|
||||
var json = "{\"key\":{ \"nestedKey\": \"nestedValue\" }, \"key2\": { \"nestedKey2\": \"nestedValue2\" } }";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.True(node.IsMap());
|
||||
|
||||
{
|
||||
var it = node.ObjectItems().GetEnumerator();
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("key", it.Current.Key.GetString());
|
||||
Assert.True(it.Current.Value.IsMap());
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("key2", it.Current.Key.GetString());
|
||||
Assert.True(it.Current.Value.IsMap());
|
||||
|
||||
Assert.IsFalse(it.MoveNext());
|
||||
}
|
||||
|
||||
var nested = node["key2"];
|
||||
|
||||
{
|
||||
var it = nested.ObjectItems().GetEnumerator();
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("nestedKey2", it.Current.Key.GetString());
|
||||
Assert.AreEqual("nestedValue2", it.Current.Value.GetString());
|
||||
|
||||
Assert.IsFalse(it.MoveNext());
|
||||
}
|
||||
|
||||
Assert.AreEqual("nestedValue2", node["key2"]["nestedKey2"].GetString());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArrayTest()
|
||||
{
|
||||
{
|
||||
var json = "[]";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
|
||||
//Assert.Catch(() => { var result = node.Value.Bytes.Count; }, "raise exception");
|
||||
Assert.AreEqual(2, node.Value.Bytes.Count);
|
||||
|
||||
Assert.True(node.IsArray());
|
||||
|
||||
Assert.AreEqual("[\n]", node.ToString(" "));
|
||||
}
|
||||
|
||||
{
|
||||
var json = "[1,2,3]";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
|
||||
//Assert.Catch(() => { var result = node.Value.Bytes.Count; }, "raise exception");
|
||||
|
||||
Assert.True(node.IsArray());
|
||||
Assert.AreEqual(1, node[0].GetDouble());
|
||||
Assert.AreEqual(2, node[1].GetDouble());
|
||||
Assert.AreEqual(3, node[2].GetDouble());
|
||||
|
||||
Assert.AreEqual("[\n 1,\n 2,\n 3\n]", node.ToString(" "));
|
||||
}
|
||||
|
||||
{
|
||||
var json = "[\"key\",1]";
|
||||
var node = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, node.Value.Bytes.Offset);
|
||||
|
||||
//Assert.Catch(() => { var result = node.Value.Bytes.Count; }, "raise exception");
|
||||
Assert.AreEqual(json.Length, node.Value.Bytes.Count);
|
||||
|
||||
Assert.True(node.IsArray());
|
||||
|
||||
var it = node.ArrayItems().GetEnumerator();
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual("key", it.Current.GetString());
|
||||
|
||||
Assert.IsTrue(it.MoveNext());
|
||||
Assert.AreEqual(1, it.Current.GetDouble());
|
||||
|
||||
Assert.IsFalse(it.MoveNext());
|
||||
|
||||
Assert.AreEqual("key", node[0].GetString());
|
||||
Assert.AreEqual(1, node[1].GetDouble());
|
||||
|
||||
Assert.AreEqual("[\n \"key\",\n 1\n]", node.ToString(" "));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseTest()
|
||||
{
|
||||
var json = "{";
|
||||
Assert.Catch(typeof(ParserException), () => JsonParser.Parse(json));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Utf8Test()
|
||||
{
|
||||
JsonParser.Parse("\"5\"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeTest()
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
f.Value(new DateTimeOffset());
|
||||
|
||||
Assert.AreEqual("\"0001-01-01T00:00:00Z\"", new Utf8String(f.GetStoreBytes()).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/JsonParserTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/JsonParserTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4af58e17f98c9a141b9fef25dabbd9ce
|
||||
timeCreated: 1495517074
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
152
UniJSON/Editor/Tests/Json/JsonSerializerTests.cs
Normal file
152
UniJSON/Editor/Tests/Json/JsonSerializerTests.cs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
#pragma warning disable 0649
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class JsonSerializerTests
|
||||
{
|
||||
struct Point
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
|
||||
public float[] Vector;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{X={0}, Y={1}, {2}}}", X, Y, Vector);
|
||||
}
|
||||
}
|
||||
|
||||
enum HogeFuga
|
||||
{
|
||||
Hoge,
|
||||
Fuga,
|
||||
}
|
||||
|
||||
struct EnumTest
|
||||
{
|
||||
public HogeFuga EnumDefault;
|
||||
|
||||
[JsonSchema(EnumSerializationType =EnumSerializationType.AsInt)]
|
||||
public HogeFuga EnumAsInt;
|
||||
|
||||
[JsonSchema(EnumSerializationType = EnumSerializationType.AsString)]
|
||||
public HogeFuga EnumAsString;
|
||||
|
||||
[JsonSchema(EnumSerializationType = EnumSerializationType.AsLowerString)]
|
||||
public HogeFuga EnumAsLowerString;
|
||||
}
|
||||
|
||||
#region Serializer
|
||||
static void SerializeValue<T>(T value, string json)
|
||||
{
|
||||
var b = new BytesStore();
|
||||
var f = new JsonFormatter(b);
|
||||
|
||||
f.Serialize(value);
|
||||
Assert.AreEqual(json, new Utf8String(b.Bytes).ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonSerializerTest()
|
||||
{
|
||||
SerializeValue(1, "1");
|
||||
SerializeValue(1.1f, "1.1");
|
||||
SerializeValue(1.2, "1.2");
|
||||
SerializeValue(Double.NaN, "NaN");
|
||||
SerializeValue(Double.PositiveInfinity, "Infinity");
|
||||
SerializeValue(Double.NegativeInfinity, "-Infinity");
|
||||
SerializeValue(true, "true");
|
||||
SerializeValue(false, "false");
|
||||
SerializeValue("ascii", "\"ascii\"");
|
||||
|
||||
SerializeValue(new[] { 1 }, "[1]");
|
||||
SerializeValue(new[] { 1.1f }, "[1.1]");
|
||||
SerializeValue(new[] { 1.2 }, "[1.2]");
|
||||
SerializeValue(new[] { true, false }, "[true,false]");
|
||||
SerializeValue(new[] { "ascii" }, "[\"ascii\"]");
|
||||
SerializeValue(new List<int> { 1 }, "[1]");
|
||||
//SerializeValue(new object[] { null, 1, "a" }, "[null,1,\"a\"]");
|
||||
|
||||
SerializeValue(new Dictionary<string, object> { }, "{}");
|
||||
SerializeValue(new Dictionary<string, object> { { "a", 1 } }, "{\"a\":1}");
|
||||
SerializeValue(new Dictionary<string, object> { { "a",
|
||||
new Dictionary<string, object>{
|
||||
} } }, "{\"a\":{}}");
|
||||
|
||||
SerializeValue(new Point { X = 1 }, "{\"X\":1,\"Y\":0}");
|
||||
|
||||
SerializeValue(HogeFuga.Fuga, "1");
|
||||
|
||||
SerializeValue(new EnumTest(), "{\"EnumDefault\":0,\"EnumAsInt\":0,\"EnumAsString\":\"Hoge\",\"EnumAsLowerString\":\"hoge\"}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KeyValue()
|
||||
{
|
||||
var p = new Point
|
||||
{
|
||||
X = 1,
|
||||
Vector = new float[] { 1, 2, 3 }
|
||||
};
|
||||
|
||||
var f = new JsonFormatter();
|
||||
f.BeginMap();
|
||||
f.KeyValue(() => p.Vector);
|
||||
f.EndMap();
|
||||
|
||||
var json = JsonParser.Parse(new Utf8String(f.GetStoreBytes()));
|
||||
|
||||
Assert.AreEqual(1, json.GetObjectCount());
|
||||
Assert.AreEqual(1, json["Vector"][0].GetInt32());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Deserialize
|
||||
static void DeserializeValue<T>(T value, string json)
|
||||
{
|
||||
var parsed = JsonParser.Parse(json);
|
||||
|
||||
var t = default(T);
|
||||
parsed.Deserialize(ref t);
|
||||
|
||||
Assert.AreEqual(value, t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonDeserializerTest()
|
||||
{
|
||||
DeserializeValue(1, "1");
|
||||
DeserializeValue(1.1f, "1.1");
|
||||
DeserializeValue(1.2, "1.2");
|
||||
DeserializeValue(true, "true");
|
||||
DeserializeValue(false, "false");
|
||||
DeserializeValue("ascii", "\"ascii\"");
|
||||
|
||||
DeserializeValue(new[] { 1 }, "[1]");
|
||||
DeserializeValue(new[] { 1.1f }, "[1.1]");
|
||||
DeserializeValue(new[] { 1.2 }, "[1.2]");
|
||||
DeserializeValue(new[] { true, false }, "[true,false]");
|
||||
DeserializeValue(new[] { "ascii" }, "[\"ascii\"]");
|
||||
DeserializeValue(new List<int> { 1 }, "[1]");
|
||||
//DeserializeValue(new object[] { null, 1, "a" }, "[null,1,\"a\"]");
|
||||
|
||||
DeserializeValue(new Dictionary<string, object> { }, "{}");
|
||||
DeserializeValue(new Dictionary<string, object> { { "a", 1 } }, "{\"a\":1}");
|
||||
DeserializeValue(new Dictionary<string, object> { { "a",
|
||||
new Dictionary<string, object>{
|
||||
} } }, "{\"a\":{}}");
|
||||
|
||||
DeserializeValue(new Point { X = 1 }, "{\"X\":1,\"Y\":0}");
|
||||
|
||||
DeserializeValue(HogeFuga.Fuga, "1");
|
||||
|
||||
DeserializeValue(new EnumTest(), "{\"EnumDefault\":0,\"EnumAsInt\":0,\"EnumAsString\":\"Hoge\",\"EnumAsLowerString\":\"hoge\"}");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/JsonSerializerTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/JsonSerializerTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b08b704c97f3bc54c8469f9f1822432d
|
||||
timeCreated: 1543256597
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
UniJSON/Editor/Tests/Json/JsonValueTests.cs
Normal file
41
UniJSON/Editor/Tests/Json/JsonValueTests.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class JsonValueTests
|
||||
{
|
||||
// TODO: Add tests for values which have other types
|
||||
|
||||
[Test]
|
||||
public void NaNTest()
|
||||
{
|
||||
{
|
||||
var v = new JsonValue(Utf8String.From("NaN"), ValueNodeType.NaN, -1);
|
||||
Assert.AreEqual("NaN", v.ToString());
|
||||
Assert.AreEqual(Double.NaN, v.GetValue<double>());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InfinityTest()
|
||||
{
|
||||
{
|
||||
var v = new JsonValue(Utf8String.From("Infinity"), ValueNodeType.Infinity, -1);
|
||||
Assert.AreEqual("Infinity", v.ToString());
|
||||
Assert.AreEqual(Double.PositiveInfinity, v.GetValue<double>());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinusInfinityTest()
|
||||
{
|
||||
{
|
||||
var v = new JsonValue(Utf8String.From("-Infinity"), ValueNodeType.MinusInfinity, -1);
|
||||
Assert.AreEqual("-Infinity", v.ToString());
|
||||
Assert.AreEqual(Double.NegativeInfinity, v.GetValue<double>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
UniJSON/Editor/Tests/Json/JsonValueTests.cs.meta
Normal file
3
UniJSON/Editor/Tests/Json/JsonValueTests.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b0dfab85f59470d8cba21b351fa766b
|
||||
timeCreated: 1545750553
|
||||
134
UniJSON/Editor/Tests/Json/SchemaTests.cs
Normal file
134
UniJSON/Editor/Tests/Json/SchemaTests.cs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
#pragma warning disable 0649
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class SchemaTests
|
||||
{
|
||||
/// <summary>
|
||||
/// http://json-schema.org/examples.html
|
||||
/// </summary>
|
||||
[JsonSchema(Title="Person")]
|
||||
public class Person
|
||||
{
|
||||
[JsonSchema(Required = true)]
|
||||
public string firstName;
|
||||
|
||||
[JsonSchema(Required = true)]
|
||||
public string lastName;
|
||||
|
||||
[JsonSchema(Description = "Age in years", Minimum = 0)]
|
||||
public int age;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateFromClass()
|
||||
{
|
||||
var s = JsonSchema.FromType<Person>();
|
||||
Assert.AreEqual("Person", s.Title);
|
||||
|
||||
var v = s.Validator as JsonObjectValidator;
|
||||
Assert.AreEqual("Age in years", v.Properties["age"].Description);
|
||||
Assert.AreEqual(new[] { "firstName", "lastName" }, v.Required);
|
||||
|
||||
var f = new JsonFormatter(2);
|
||||
s.ToJson(f);
|
||||
var json = f.ToString();
|
||||
|
||||
var parsed = JsonParser.Parse(json);
|
||||
Assert.AreEqual(0, parsed["properties"]["age"]["minimum"].GetInt32());
|
||||
}
|
||||
|
||||
public enum ProjectionType
|
||||
{
|
||||
Perspective,
|
||||
Orthographic
|
||||
}
|
||||
|
||||
class EnumStringTest
|
||||
{
|
||||
[JsonSchema(EnumSerializationType =EnumSerializationType.AsLowerString)]
|
||||
public ProjectionType type;
|
||||
}
|
||||
|
||||
class EnumIntTest
|
||||
{
|
||||
[JsonSchema(EnumSerializationType = EnumSerializationType.AsInt)]
|
||||
public ProjectionType type;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumAsString()
|
||||
{
|
||||
var json = @"
|
||||
{
|
||||
""type"": ""object"",
|
||||
""properties"": {
|
||||
|
||||
""type"": {
|
||||
|
||||
""anyOf"": [
|
||||
{
|
||||
""enum"": [ ""perspective"" ]
|
||||
},
|
||||
{
|
||||
""enum"": [ ""orthographic"" ]
|
||||
},
|
||||
{
|
||||
""type"": ""string""
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var fromJson = new JsonSchema();
|
||||
fromJson.Parse(null, JsonParser.Parse(json), "enum test");
|
||||
|
||||
var fromType = JsonSchema.FromType<EnumStringTest>();
|
||||
|
||||
Assert.AreEqual(fromJson, fromType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumAsInt()
|
||||
{
|
||||
var json = @"
|
||||
{
|
||||
""type"": ""object"",
|
||||
""properties"": {
|
||||
|
||||
""type"": {
|
||||
|
||||
""anyOf"": [
|
||||
{
|
||||
""enum"": [ 0 ]
|
||||
},
|
||||
{
|
||||
""enum"": [ 1 ]
|
||||
},
|
||||
{
|
||||
""type"": ""integer""
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var fromJson = new JsonSchema();
|
||||
fromJson.Parse(null, JsonParser.Parse(json), "enum test");
|
||||
|
||||
var fromType = JsonSchema.FromType<EnumIntTest>();
|
||||
|
||||
Assert.AreEqual(fromJson, fromType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/SchemaTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/SchemaTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d4dfd16b1b05c8640898b955df61c51b
|
||||
timeCreated: 1526055801
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
251
UniJSON/Editor/Tests/Json/ValidatorTests.cs
Normal file
251
UniJSON/Editor/Tests/Json/ValidatorTests.cs
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class ValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void IntValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = new JsonIntValidator();
|
||||
v.Maximum = 0;
|
||||
Assert.NotNull(v.Validate(c, 1));
|
||||
Assert.Null(v.Validate(c, 0));
|
||||
Assert.Null(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonIntValidator();
|
||||
v.Maximum = 0;
|
||||
v.ExclusiveMaximum = true;
|
||||
Assert.NotNull(v.Validate(c, 1));
|
||||
Assert.NotNull(v.Validate(c, 0));
|
||||
Assert.Null(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonIntValidator();
|
||||
v.Minimum = 0;
|
||||
Assert.Null(v.Validate(c, 1));
|
||||
Assert.Null(v.Validate(c, 0));
|
||||
Assert.NotNull(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonIntValidator();
|
||||
v.Minimum = 0;
|
||||
v.ExclusiveMinimum = true;
|
||||
Assert.Null(v.Validate(c, 1));
|
||||
Assert.NotNull(v.Validate(c, 0));
|
||||
Assert.NotNull(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonIntValidator();
|
||||
v.MultipleOf = 4;
|
||||
Assert.Null(v.Validate(c, 4));
|
||||
Assert.NotNull(v.Validate(c, 5));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NumberValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = new JsonNumberValidator();
|
||||
v.Maximum = 0.1;
|
||||
Assert.NotNull(v.Validate(c, 1));
|
||||
Assert.Null(v.Validate(c, 0.1));
|
||||
Assert.Null(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonNumberValidator();
|
||||
v.Maximum = 0.1;
|
||||
v.ExclusiveMaximum = true;
|
||||
Assert.NotNull(v.Validate(c, 1));
|
||||
Assert.NotNull(v.Validate(c, 0.1));
|
||||
Assert.Null(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonNumberValidator();
|
||||
v.Minimum = 0.1;
|
||||
Assert.Null(v.Validate(c, 1));
|
||||
Assert.Null(v.Validate(c, 0.1));
|
||||
Assert.NotNull(v.Validate(c, -1));
|
||||
}
|
||||
{
|
||||
var v = new JsonNumberValidator();
|
||||
v.Minimum = 0.1;
|
||||
v.ExclusiveMinimum = true;
|
||||
Assert.Null(v.Validate(c, 1));
|
||||
Assert.NotNull(v.Validate(c, 0.1));
|
||||
Assert.NotNull(v.Validate(c, -1));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BoolValidator()
|
||||
{
|
||||
// ???
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StringValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = new JsonStringValidator();
|
||||
v.MinLength = 1;
|
||||
Assert.Null(v.Validate(c, "a"));
|
||||
Assert.NotNull(v.Validate(c, ""));
|
||||
}
|
||||
{
|
||||
var v = new JsonStringValidator();
|
||||
v.MaxLength = 1;
|
||||
Assert.Null(v.Validate(c, "a"));
|
||||
Assert.NotNull(v.Validate(c, "ab"));
|
||||
}
|
||||
{
|
||||
var v = new JsonStringValidator();
|
||||
v.Pattern = new System.Text.RegularExpressions.Regex("abc");
|
||||
Assert.Null(v.Validate(c, "abc"));
|
||||
Assert.NotNull(v.Validate(c, "ab"));
|
||||
}
|
||||
{
|
||||
var v = new JsonStringValidator();
|
||||
v.Pattern = new System.Text.RegularExpressions.Regex("ab+");
|
||||
Assert.Null(v.Validate(c, "abb"));
|
||||
Assert.Null(v.Validate(c, "ab"));
|
||||
Assert.NotNull(v.Validate(c, "a"));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StringEnumValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = JsonStringEnumValidator.Create(new string[] { "a", "b" }, EnumSerializationType.AsString);
|
||||
Assert.Null(v.Validate(c, "a"));
|
||||
Assert.NotNull(v.Validate(c, "c"));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IntEnumValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = new JsonIntEnumValidator();
|
||||
v.Values = new int[] { 1, 2 };
|
||||
Assert.Null(v.Validate(c, 1));
|
||||
Assert.NotNull(v.Validate(c, 3));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArrayValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var v = new JsonArrayValidator();
|
||||
v.MaxItems = 1;
|
||||
Assert.Null(v.Validate(c, new object[] { 0 }));
|
||||
Assert.NotNull(v.Validate(c, new object[] { 0, 1 }));
|
||||
}
|
||||
|
||||
{
|
||||
var v = new JsonArrayValidator();
|
||||
v.MinItems = 1;
|
||||
Assert.Null(v.Validate(c, new object[] { 0 }));
|
||||
Assert.NotNull(v.Validate(c, new object[] { }));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
class Hoge
|
||||
{
|
||||
[JsonSchema(Required = true, Minimum = 1)]
|
||||
public int Value;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ObjectValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
{
|
||||
var s = JsonSchema.FromType<Hoge>();
|
||||
Assert.Null(s.Validator.Validate(c, new Hoge { Value = 1 }));
|
||||
Assert.NotNull(s.Validator.Validate(c, new Hoge { Value = 0 }));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var s = JsonSchema.FromType<Dictionary<string, int>>();
|
||||
Assert.True(s.Validator is JsonDictionaryValidator<int>);
|
||||
|
||||
var v = s.Validator as JsonDictionaryValidator<int>;
|
||||
v.MinProperties = 1;
|
||||
v.AdditionalProperties = JsonSchema.FromType<int>();
|
||||
(v.AdditionalProperties.Validator as JsonIntValidator).Minimum = 0;
|
||||
|
||||
Assert.Null(s.Validator.Validate(c, new Dictionary<string, int>
|
||||
{
|
||||
{"POSITION", 0}
|
||||
}));
|
||||
|
||||
var result = s.Validator.Validate(c, new Dictionary<string, int>
|
||||
{
|
||||
{"POSITION", -1}
|
||||
});
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
|
||||
class HasDictionary
|
||||
{
|
||||
public Dictionary<string, float> primitiveProperties = new Dictionary<string, float>();
|
||||
// TODO: fix
|
||||
// public Dictionary<string, Nested> nestedProperties = new Dictionary<string, Nested>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasDictionaryObjectValidator()
|
||||
{
|
||||
var c = new JsonSchemaValidationContext("test");
|
||||
|
||||
{
|
||||
var s = JsonSchema.FromType<HasDictionary>();
|
||||
Assert.Null(s.Validator.Validate(c, new HasDictionary()));
|
||||
}
|
||||
|
||||
Assert.True(c.IsEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/Json/ValidatorTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/Json/ValidatorTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 16d778a50d1c9374894ef42f892210dd
|
||||
timeCreated: 1531900562
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Editor/Tests/MsgPack.meta
Normal file
9
UniJSON/Editor/Tests/MsgPack.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0bcf0d9b7cba67c42ba04c530aa7cd38
|
||||
folderAsset: yes
|
||||
timeCreated: 1540812199
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
92
UniJSON/Editor/Tests/MsgPack/ArrayTest.cs
Normal file
92
UniJSON/Editor/Tests/MsgPack/ArrayTest.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class ArrayTest
|
||||
{
|
||||
[Test]
|
||||
public void fix_array()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
// Object[] not supported
|
||||
f.Serialize(new[] { 0, 1, false, (Object)null });
|
||||
var _bytes = f.GetStoreBytes();
|
||||
var bytes = _bytes.Array.Skip(_bytes.Offset).Take(_bytes.Count).ToArray();
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
(Byte)MsgPackType.FIX_ARRAY_0x4,
|
||||
(Byte)MsgPackType.POSITIVE_FIXNUM,
|
||||
(Byte)MsgPackType.POSITIVE_FIXNUM_0x01,
|
||||
(Byte)MsgPackType.FALSE,
|
||||
(Byte)MsgPackType.NIL
|
||||
}, bytes);
|
||||
|
||||
var parsed = MsgPackParser.Parse(bytes);
|
||||
|
||||
Assert.AreEqual(4, parsed.GetArrayCount());
|
||||
Assert.AreEqual(0, parsed[0].GetValue());
|
||||
Assert.AreEqual(1, parsed[1].GetValue());
|
||||
Assert.False((Boolean)parsed[2].GetValue());
|
||||
Assert.AreEqual(null, parsed[3].GetValue());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void array16()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
var data = Enumerable.Range(0, 20).Select(x => (Object)x).ToArray();
|
||||
f.Serialize(data);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
Assert.IsTrue(value.IsArray());
|
||||
Assert.AreEqual(20, value.GetArrayCount());
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
Assert.AreEqual(i, value[i].GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void array129()
|
||||
{
|
||||
{
|
||||
var i128 = Enumerable.Range(0, 128).ToArray();
|
||||
var f = new MsgPackFormatter();
|
||||
f.Serialize(i128);
|
||||
var bytes128 = f.GetStoreBytes();
|
||||
var deserialized = MsgPackParser.Parse(bytes128);
|
||||
Assert.AreEqual(128, deserialized.GetArrayCount());
|
||||
for (int i = 0; i < i128.Length; ++i)
|
||||
{
|
||||
Assert.AreEqual(i128[i], deserialized[i].GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var i129 = Enumerable.Range(0, 129).ToArray();
|
||||
var f = new MsgPackFormatter();
|
||||
f.Serialize(i129);
|
||||
var bytes129 = f.GetStoreBytes();
|
||||
var deserialized = MsgPackParser.Parse(bytes129);
|
||||
Assert.AreEqual(129, deserialized.GetArrayCount());
|
||||
for (int i = 0; i < i129.Length; ++i)
|
||||
{
|
||||
Assert.AreEqual(i129[i], deserialized[i].GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadTest()
|
||||
{
|
||||
var data = new int[] { -108, 0, 1, -90, 108, 111, 103, 103, 101, 114, -110, -91, 69, 114, 114, 111, 114, -94, 101, 50 }
|
||||
.Select(x => (Byte)x).ToArray();
|
||||
var parsed = MsgPackParser.Parse(data);
|
||||
Assert.True(parsed.IsArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/ArrayTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/ArrayTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b485b0360ebfd246ac90bbe8ad1895b
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
UniJSON/Editor/Tests/MsgPack/BooleanTest.cs
Normal file
50
UniJSON/Editor/Tests/MsgPack/BooleanTest.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class BooleanTest
|
||||
{
|
||||
[Test]
|
||||
public void nil()
|
||||
{
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Null();
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[] { 0xC0 }, bytes.ToEnumerable());
|
||||
|
||||
var parsed = MsgPackParser.Parse(bytes);
|
||||
Assert.True(parsed.IsNull());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void True()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(true);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[] { 0xC3 }, bytes.ToEnumerable());
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
var j = value.GetBoolean();
|
||||
Assert.AreEqual(true, j);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void False()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(false);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[] { 0xC2 }, bytes.ToEnumerable());
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
var j = value.GetBoolean();
|
||||
Assert.AreEqual(false, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/BooleanTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/BooleanTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0f19e48b365cd446982ed0b7ba6251e
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
UniJSON/Editor/Tests/MsgPack/FloatTest.cs
Normal file
50
UniJSON/Editor/Tests/MsgPack/FloatTest.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class FloatTest
|
||||
{
|
||||
[Test]
|
||||
public void Float32()
|
||||
{
|
||||
var i = 1.1f;
|
||||
var float_be = new byte[]
|
||||
{
|
||||
(Byte)MsgPackType.FLOAT, 0x3f, 0x8c, 0xcc, 0xcd
|
||||
};
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
var body = value.Value.Bytes;
|
||||
Assert.AreEqual(float_be, body.ToEnumerable().ToArray());
|
||||
|
||||
Assert.AreEqual(i, value.GetValue());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float64()
|
||||
{
|
||||
var i = 1.1;
|
||||
var double_be = new Byte[]{
|
||||
(Byte)MsgPackType.DOUBLE, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a,
|
||||
};
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
var body = value.Value.Bytes;
|
||||
Assert.AreEqual(double_be, body.ToEnumerable().ToArray());
|
||||
|
||||
Assert.AreEqual(i, value.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/FloatTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/FloatTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 51cdc6be3b73a34429cae41cd020c71c
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
220
UniJSON/Editor/Tests/MsgPack/IntTest.cs
Normal file
220
UniJSON/Editor/Tests/MsgPack/IntTest.cs
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class IntTest
|
||||
{
|
||||
[Test]
|
||||
public void positive_fixnum()
|
||||
{
|
||||
for (Byte i = 0; i < 128; ++i)
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[] { i }, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void negative_fixnum()
|
||||
{
|
||||
for (SByte i = -32; i < 0; ++i)
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void uint8()
|
||||
{
|
||||
{
|
||||
Byte i = 0x7F + 20;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xcc, 0x93,
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void cast_large_type()
|
||||
{
|
||||
{
|
||||
Byte i = 0x7F + 20;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xcc, 0x93,
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void uint16()
|
||||
{
|
||||
{
|
||||
UInt16 i = 0xFF + 20;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xcd, 0x01, 0x13
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void uint32()
|
||||
{
|
||||
{
|
||||
UInt32 i = 0xFFFF + 20;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xce, 0x00, 0x01, 0x00, 0x13
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void uint64()
|
||||
{
|
||||
{
|
||||
UInt64 i = 0xFFFFFFFF;
|
||||
i += 20;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void int8()
|
||||
{
|
||||
{
|
||||
SByte i = -64;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xd0, 0xc0,
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void int128Test()
|
||||
{
|
||||
int i = 128;
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xcc, 0x80,
|
||||
}, bytes.ToEnumerable());
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void int16()
|
||||
{
|
||||
{
|
||||
Int16 i = -150;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xd1, 0xFF, 0x6a
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void int32()
|
||||
{
|
||||
{
|
||||
Int32 i = -35000;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xd2, 0xff, 0xff, 0x77, 0x48
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void int64()
|
||||
{
|
||||
{
|
||||
Int64 i = -2147483650;
|
||||
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(i);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0xd3, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xfe
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var j = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/IntTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/IntTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8d6f5e40bc0825b449887d877c0ad5c5
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
120
UniJSON/Editor/Tests/MsgPack/MapTest.cs
Normal file
120
UniJSON/Editor/Tests/MsgPack/MapTest.cs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class MapTest
|
||||
{
|
||||
[Test]
|
||||
public void fix_map()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.BeginMap(2);
|
||||
f.Key("0"); f.Value(1);
|
||||
f.Key("2"); f.Value(3);
|
||||
f.EndMap();
|
||||
var bytes =
|
||||
f.GetStoreBytes();
|
||||
;
|
||||
|
||||
Assert.AreEqual(new Byte[]{
|
||||
0x82, // map2
|
||||
|
||||
0xa1, 0x30, // "0"
|
||||
0x01, // 1
|
||||
|
||||
0xa1, 0x32, // "2"
|
||||
0x03 // 3
|
||||
}, bytes.ToEnumerable());
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
|
||||
Assert.AreEqual(2, value.GetObjectCount());
|
||||
Assert.AreEqual(1, value["0"].GetValue());
|
||||
Assert.AreEqual(3, value["2"].GetValue());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void map16()
|
||||
{
|
||||
var w = new MsgPackFormatter();
|
||||
int size = 18;
|
||||
w.BeginMap(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
w.Value(i.ToString());
|
||||
w.Value(i + 5);
|
||||
}
|
||||
var bytes = w.GetStoreBytes().ToEnumerable().ToArray();
|
||||
|
||||
|
||||
var expected = new Byte[]{
|
||||
0xde, // map18
|
||||
0x0, 0x12, // 18
|
||||
|
||||
0xa1, 0x30, // "0"
|
||||
0x5,
|
||||
|
||||
0xa1, 0x31, // "1"
|
||||
0x6,
|
||||
|
||||
0xa1, 0x32, // "2"
|
||||
0x7,
|
||||
|
||||
0xa1, 0x33, // "3"
|
||||
0x8,
|
||||
|
||||
0xa1, 0x34, // "4"
|
||||
0x9,
|
||||
|
||||
0xa1, 0x35, // "5"
|
||||
0xa,
|
||||
|
||||
0xa1, 0x36, // "6"
|
||||
0xb,
|
||||
|
||||
0xa1, 0x37, // "7"
|
||||
0xc,
|
||||
|
||||
0xa1, 0x38, // "8"
|
||||
0xd,
|
||||
|
||||
0xa1, 0x39, // "9"
|
||||
0xe,
|
||||
|
||||
0xa2, 0x31, 0x30, // "10"
|
||||
0xf,
|
||||
|
||||
0xa2, 0x31, 0x31, // "11"
|
||||
0x10,
|
||||
|
||||
0xa2, 0x31, 0x32, // "12"
|
||||
0x11,
|
||||
|
||||
0xa2, 0x31, 0x33, // "13"
|
||||
0x12,
|
||||
|
||||
0xa2, 0x31, 0x34, // "14"
|
||||
0x13,
|
||||
|
||||
0xa2, 0x31, 0x35, // "15"
|
||||
0x14,
|
||||
|
||||
0xa2, 0x31, 0x36, // "16"
|
||||
0x15,
|
||||
|
||||
0xa2, 0x31, 0x37, // "17",
|
||||
0x16
|
||||
};
|
||||
|
||||
Assert.AreEqual(expected, bytes);
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
|
||||
Assert.AreEqual(15, value["10"].GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/MapTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/MapTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 87a626e93589db14fbe4526c9880b110
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
UniJSON/Editor/Tests/MsgPack/RawTest.cs
Normal file
34
UniJSON/Editor/Tests/MsgPack/RawTest.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class RawTest
|
||||
{
|
||||
[Test]
|
||||
public void fix_raw()
|
||||
{
|
||||
var src = new Byte[] { 0, 1, 2 };
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(src);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var v = MsgPackParser.Parse(bytes).Value.GetBody();
|
||||
Assert.True(src.SequenceEqual(v.ToEnumerable()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void raw16()
|
||||
{
|
||||
var src = Enumerable.Range(0, 50).Select(x => (Byte)x).ToArray();
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(src);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var v = MsgPackParser.Parse(bytes).Value.GetBody();
|
||||
Assert.True(src.SequenceEqual(v.ToEnumerable()));
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/RawTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/RawTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 331bd613923afe5438ef4ff3a59fc5b3
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
UniJSON/Editor/Tests/MsgPack/StringTest.cs
Normal file
36
UniJSON/Editor/Tests/MsgPack/StringTest.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
[TestFixture]
|
||||
public class StringTest
|
||||
{
|
||||
[Test]
|
||||
public void str()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value("文字列");
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var v = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual("文字列", v);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void fix_str()
|
||||
{
|
||||
for (int i = 1; i < 32; ++i)
|
||||
{
|
||||
var str = String.Join("", Enumerable.Range(0, i).Select(_ => "0").ToArray());
|
||||
var f = new MsgPackFormatter();
|
||||
f.Value(str);
|
||||
var bytes = f.GetStoreBytes();
|
||||
|
||||
var value = MsgPackParser.Parse(bytes);
|
||||
Assert.AreEqual(i, ((String)value.GetValue()).Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/StringTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/StringTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3942810073614d946a76d87cbbfb222c
|
||||
timeCreated: 1540812276
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
UniJSON/Editor/Tests/MsgPack/TimeTests.cs
Normal file
50
UniJSON/Editor/Tests/MsgPack/TimeTests.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
|
||||
namespace UniJSON.MsgPack
|
||||
{
|
||||
public class TimeTests
|
||||
{
|
||||
[Test]
|
||||
public void TimeTest()
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
|
||||
{
|
||||
f.GetStore().Clear();
|
||||
var time = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
|
||||
f.Value(time);
|
||||
|
||||
var bytes = f.GetStoreBytes().ArrayOrCopy();
|
||||
unchecked
|
||||
{
|
||||
Assert.AreEqual(new byte[]
|
||||
{
|
||||
(byte)MsgPackType.FIX_EXT_4, (byte)-1, 0, 0, 0, 0
|
||||
}, bytes);
|
||||
}
|
||||
var parsed = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(time, parsed);
|
||||
}
|
||||
|
||||
{
|
||||
var time = new DateTimeOffset(2018, 12, 8, 2, 12, 15, TimeSpan.Zero);
|
||||
Assert.AreEqual(1544235135, time.ToUnixTimeSeconds());
|
||||
f.GetStore().Clear();
|
||||
f.Value(time);
|
||||
var bytes = f.GetStoreBytes().ArrayOrCopy();
|
||||
var parsed = MsgPackParser.Parse(bytes).GetValue();
|
||||
Assert.AreEqual(time, parsed);
|
||||
}
|
||||
|
||||
{
|
||||
f.GetStore().Clear();
|
||||
Assert.Catch(() =>
|
||||
{
|
||||
f.Value(new DateTimeOffset());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/MsgPack/TimeTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/MsgPack/TimeTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0a025b475357b4d4aa104e839e6791be
|
||||
timeCreated: 1544154226
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
UniJSON/Editor/Tests/RPCTests.cs
Normal file
98
UniJSON/Editor/Tests/RPCTests.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using NUnit.Framework;
|
||||
using UniJSON.MsgPack;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class RPCTests
|
||||
{
|
||||
[Test]
|
||||
public void JsonRpcRequestTest()
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
|
||||
{
|
||||
f.Clear();
|
||||
var l = JsonParser.Parse("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"num1\",\"params\":[1]}");
|
||||
f.Request("num1", 1);
|
||||
var u = new Utf8String(f.GetStoreBytes());
|
||||
var r = JsonParser.Parse(u);
|
||||
Assert.AreEqual(
|
||||
l,
|
||||
r);
|
||||
}
|
||||
{
|
||||
f.Clear();
|
||||
f.Request("num2", 2, true);
|
||||
Assert.AreEqual(
|
||||
JsonParser.Parse("{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"num2\",\"params\":[2,true]}"),
|
||||
JsonParser.Parse(new Utf8String(f.GetStoreBytes())));
|
||||
}
|
||||
{
|
||||
f.Clear();
|
||||
f.Request("num3",
|
||||
3, true, "abc", false, (string)null, new[] { 1, 2 });
|
||||
Assert.AreEqual(
|
||||
JsonParser.Parse("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"num3\",\"params\":[3,true,\"abc\",false,null,[1,2]]}"),
|
||||
JsonParser.Parse(new Utf8String(f.GetStoreBytes())));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonRpcDispatcherTest()
|
||||
{
|
||||
var dispatcher = new RpcDispatcher<JsonValue>();
|
||||
var f = new JsonFormatter();
|
||||
|
||||
{
|
||||
f.Clear();
|
||||
dispatcher.Register("add", (int a, int b) => a + b);
|
||||
f.Request("add", 1, 2);
|
||||
|
||||
var parsed = JsonParser.Parse(new Utf8String(f.GetStoreBytes()));
|
||||
|
||||
f.Clear();
|
||||
dispatcher.Call(f, parsed["id"].GetInt32(), parsed["method"].GetString(), parsed["params"]);
|
||||
var response = JsonParser.Parse(new Utf8String(f.GetStoreBytes()));
|
||||
Assert.AreEqual(3, response["result"].GetInt32());
|
||||
}
|
||||
|
||||
{
|
||||
string msg = null;
|
||||
dispatcher.Register("print", (string _msg) => { msg = _msg; });
|
||||
f.Clear();
|
||||
f.Request("print", "hoge");
|
||||
|
||||
var parsed = JsonParser.Parse(new Utf8String(f.GetStoreBytes()));
|
||||
f.Clear();
|
||||
dispatcher.Call(f, parsed["id"].GetInt32(), parsed["method"].GetString(), parsed["params"]);
|
||||
|
||||
Assert.AreEqual("hoge", msg);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MsgPackRpcDispatcherTest()
|
||||
{
|
||||
var dispatcher = new RpcDispatcher<MsgPackValue>();
|
||||
var f = new MsgPackFormatter();
|
||||
|
||||
{
|
||||
f.GetStore().Clear();
|
||||
dispatcher.Register("add", (int a, int b) => a + b);
|
||||
f.Request("add", 1, 2);
|
||||
|
||||
var request = MsgPackParser.Parse(f.GetStoreBytes());
|
||||
Assert.AreEqual(4, request.GetArrayCount());
|
||||
Assert.AreEqual(MsgPackFormatter.REQUEST_TYPE, request[0].GetInt32());
|
||||
|
||||
f.GetStore().Clear();
|
||||
dispatcher.Call(f, request[1].GetInt32(), request[2].GetString(), request[3]);
|
||||
var response = MsgPackParser.Parse(f.GetStoreBytes());
|
||||
Assert.AreEqual(4, response.GetArrayCount());
|
||||
Assert.AreEqual(MsgPackFormatter.RESPONSE_TYPE, response[0].GetInt32());
|
||||
Assert.True(response[2].IsNull());
|
||||
Assert.AreEqual(3, response[3].GetInt32());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/RPCTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/RPCTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05698e8d4a5f5f64c8482d2d6899301d
|
||||
timeCreated: 1543250712
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Editor/Tests/Toml.meta
Normal file
9
UniJSON/Editor/Tests/Toml.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a719ea2a10120c48959e1fe817301af
|
||||
folderAsset: yes
|
||||
timeCreated: 1545735556
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
UniJSON/Editor/Tests/Toml/TomlParserTests.cs
Normal file
128
UniJSON/Editor/Tests/Toml/TomlParserTests.cs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
|
||||
/*
|
||||
namespace UniJSON.Toml
|
||||
{
|
||||
class TomlParserTests
|
||||
{
|
||||
[Test]
|
||||
public void BareKeyTests()
|
||||
{
|
||||
{
|
||||
var result = TomlParser.Parse(@"
|
||||
value = 1
|
||||
");
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["value"].GetInt32());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DottedKeyTests()
|
||||
{
|
||||
{
|
||||
var result = TomlParser.Parse(@"
|
||||
value.value2 = 1
|
||||
");
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["value"]["value2"].GetInt32());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DuplicatedKey()
|
||||
{
|
||||
{
|
||||
Assert.Catch(() => TomlParser.Parse(@"
|
||||
value = 1
|
||||
value = 2
|
||||
"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QuotedKeyTests()
|
||||
{
|
||||
{
|
||||
var result = TomlParser.Parse(@"
|
||||
""value"" = 1
|
||||
");
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["value"].GetInt32());
|
||||
}
|
||||
|
||||
{
|
||||
var result = TomlParser.Parse(@"
|
||||
""[key=value]"" = 1
|
||||
");
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["value"].GetInt32());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TableTests()
|
||||
{
|
||||
{
|
||||
var result = @"
|
||||
[table]
|
||||
value = 1
|
||||
".ParseAsToml();
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["table"]["value"].GetInt32());
|
||||
}
|
||||
|
||||
{
|
||||
var result = @"
|
||||
[table.table2]
|
||||
value = 1
|
||||
".ParseAsToml();
|
||||
Assert.True(result.IsMap());
|
||||
Assert.AreEqual(1, result["table"]["table2"]["value"].GetInt32());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TomlExample()
|
||||
{
|
||||
var result = @"
|
||||
# This is a TOML document.
|
||||
|
||||
title = ""TOML Example""
|
||||
|
||||
[owner]
|
||||
name = ""Tom Preston-Werner""
|
||||
dob = 1979 - 05 - 27T07: 32:00 - 08:00 # First class dates
|
||||
|
||||
[database]
|
||||
server = ""192.168.1.1""
|
||||
ports = [8001, 8001, 8002]
|
||||
connection_max = 5000
|
||||
enabled = true
|
||||
|
||||
[servers]
|
||||
|
||||
# Indentation (tabs and/or spaces) is allowed but not required
|
||||
[servers.alpha]
|
||||
ip = ""10.0.0.1""
|
||||
dc = ""eqdc10""
|
||||
|
||||
[servers.beta]
|
||||
ip = ""10.0.0.2""
|
||||
dc = ""eqdc10""
|
||||
|
||||
[clients]
|
||||
data = [ [""gamma"", ""delta""], [1, 2] ]
|
||||
|
||||
# Line breaks are OK when inside arrays
|
||||
hosts = [
|
||||
""alpha"",
|
||||
""omega""
|
||||
]
|
||||
".ParseAsToml();
|
||||
Assert.AreEqual("TOML Example", result["title"].GetString());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
12
UniJSON/Editor/Tests/Toml/TomlParserTests.cs.meta
Normal file
12
UniJSON/Editor/Tests/Toml/TomlParserTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7959f4764f02c5e4d9f191e794bc6101
|
||||
timeCreated: 1545735557
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
129
UniJSON/Editor/Tests/TreeTest.cs
Normal file
129
UniJSON/Editor/Tests/TreeTest.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace GenericTree
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic tree interface
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
interface ITreeNode<T, U>
|
||||
where T : ITreeNode<T, U>
|
||||
{
|
||||
bool IsValid { get; }
|
||||
int ValueIndex { get; }
|
||||
U Value { get; }
|
||||
|
||||
bool HasParent { get; }
|
||||
T Parent { get; }
|
||||
|
||||
IEnumerable<T> Children { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item has parent reference by list index
|
||||
/// </summary>
|
||||
public interface ITreeItem
|
||||
{
|
||||
int ParentIndex { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generic tree implementation
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
struct TreeNode<T> : ITreeNode<TreeNode<T>, T>
|
||||
where T : ITreeItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Whole tree ndoes
|
||||
/// </summary>
|
||||
public readonly List<T> Values;
|
||||
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
return Values != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This node index
|
||||
/// </summary>
|
||||
public int ValueIndex
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Values == null)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
return Values[ValueIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TreeNode<T>> Children
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < Values.Count; ++i)
|
||||
{
|
||||
if (Values[i].ParentIndex == ValueIndex)
|
||||
{
|
||||
yield return new TreeNode<T>(Values, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasParent
|
||||
{
|
||||
get
|
||||
{
|
||||
return Value.ParentIndex >= 0 && Value.ParentIndex < Values.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNode<T> Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Value.ParentIndex < 0)
|
||||
{
|
||||
throw new Exception("this may root node");
|
||||
}
|
||||
if (Value.ParentIndex >= Values.Count)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new TreeNode<T>(Values, Value.ParentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNode(List<T> values, int index) : this()
|
||||
{
|
||||
Values = values;
|
||||
ValueIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TreeTests
|
||||
{
|
||||
[Test]
|
||||
public void TreeTest()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Editor/Tests/TreeTest.cs.meta
Normal file
12
UniJSON/Editor/Tests/TreeTest.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 61f513d7f9bea254690ee01fcb70e843
|
||||
timeCreated: 1545735557
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
168
UniJSON/Editor/Tests/Utf8StringTest.cs
Normal file
168
UniJSON/Editor/Tests/Utf8StringTest.cs
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class Utf8StringTests
|
||||
{
|
||||
[Test]
|
||||
public void Utf8StringTest()
|
||||
{
|
||||
var abc = Utf8String.From("abc");
|
||||
var ab = Utf8String.From("ab");
|
||||
var bc = Utf8String.From("bc");
|
||||
|
||||
Assert.True(abc.StartsWith(ab));
|
||||
Assert.False(ab.StartsWith(abc));
|
||||
|
||||
Assert.True(abc.EndsWith(bc));
|
||||
Assert.False(bc.EndsWith(abc));
|
||||
|
||||
Assert.AreEqual(Utf8String.From("abbc"), ab.Concat(bc));
|
||||
|
||||
Assert.AreEqual(2, abc.IndexOf((byte)'c'));
|
||||
|
||||
int pos;
|
||||
abc.TrySearchAscii((byte)'c', 0, out pos);
|
||||
Assert.AreEqual(2, pos);
|
||||
|
||||
abc.TrySearchAscii((byte)'c', 1, out pos);
|
||||
Assert.AreEqual(2, pos);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShortUtf8Test()
|
||||
{
|
||||
var a0 = Utf8String4.Create("a");
|
||||
Assert.AreEqual("a", a0);
|
||||
var a1 = Utf8String4.Create(new byte[] { (byte)'a', 0x00 });
|
||||
Assert.AreEqual(a0, a1);
|
||||
var a2 = Utf8String4.Create("5");
|
||||
Assert.AreEqual(3, a2.ByteLength);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QuoteTest()
|
||||
{
|
||||
{
|
||||
var value = Utf8String.From("ho5日本語ge");
|
||||
var quoted = Utf8String.From("\"ho5日本語ge\"");
|
||||
Assert.AreEqual(quoted, JsonString.Quote(value));
|
||||
Assert.AreEqual(value, JsonString.Unquote(quoted));
|
||||
}
|
||||
|
||||
{
|
||||
var value = Utf8String.From("fuga\n ho5日本語ge");
|
||||
var quoted = Utf8String.From("\"fuga\\n ho5日本語ge\"");
|
||||
Assert.AreEqual(quoted, JsonString.Quote(value));
|
||||
Assert.AreEqual(value, JsonString.Unquote(quoted));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SplitTest()
|
||||
{
|
||||
{
|
||||
var value = Utf8String.From("a/5/c");
|
||||
var splited = value.Split((byte)'/').ToArray();
|
||||
Assert.AreEqual(3, splited.Length);
|
||||
Assert.AreEqual(splited[0], Utf8String.From("a"));
|
||||
Assert.AreEqual(splited[1], Utf8String.From("5"));
|
||||
Assert.AreEqual(splited[2], Utf8String.From("c"));
|
||||
}
|
||||
{
|
||||
var value = Utf8String.From("/a/5/c/");
|
||||
var splited = value.Split((byte)'/').ToArray();
|
||||
Assert.AreEqual(4, splited.Length);
|
||||
Assert.AreEqual(splited[0], Utf8String.From(""));
|
||||
Assert.AreEqual(splited[1], Utf8String.From("a"));
|
||||
Assert.AreEqual(splited[2], Utf8String.From("5"));
|
||||
Assert.AreEqual(splited[3], Utf8String.From("c"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SplitIntegerTest()
|
||||
{
|
||||
Assert.AreEqual("1", Utf8String.From("1 ").SplitInteger().ToString());
|
||||
Assert.AreEqual("123", Utf8String.From("123").SplitInteger().ToString());
|
||||
Assert.Catch(() => Utf8String.From(" 1").SplitInteger());
|
||||
Assert.AreEqual("+12", Utf8String.From("+12\n").SplitInteger().ToString());
|
||||
Assert.AreEqual("-123", Utf8String.From("-123\n").SplitInteger().ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtoiTest()
|
||||
{
|
||||
Assert.AreEqual(1234, Utf8String.From("1234").ToInt32());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToCharTest()
|
||||
{
|
||||
{
|
||||
// 1byte
|
||||
var c = 'A';
|
||||
Assert.AreEqual(1, Utf8String.From(c.ToString()).GetFirst().CurrentByteLength);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Unicode);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Char);
|
||||
}
|
||||
{
|
||||
// 2byte
|
||||
var c = '¢';
|
||||
Assert.AreEqual(2, Utf8String.From(c.ToString()).GetFirst().CurrentByteLength);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Unicode);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Char);
|
||||
}
|
||||
{
|
||||
// 3byte
|
||||
var c = '5';
|
||||
Assert.AreEqual(3, Utf8String.From(c.ToString()).GetFirst().CurrentByteLength);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Unicode);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Char);
|
||||
}
|
||||
{
|
||||
var c = '仡';
|
||||
Assert.AreEqual(3, Utf8String.From(c.ToString()).GetFirst().CurrentByteLength);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Unicode);
|
||||
Assert.AreEqual(c, Utf8String.From(c.ToString()).GetFirst().Char);
|
||||
}
|
||||
{
|
||||
// emoji
|
||||
var s = "😃";
|
||||
Assert.AreEqual(4, Utf8String.From(s).GetFirst().CurrentByteLength);
|
||||
Assert.AreEqual(0x1F603, Utf8String.From(s).GetFirst().Unicode);
|
||||
Assert.Catch(() =>
|
||||
{
|
||||
var a = Utf8String.From(s).GetFirst().Char;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromStringTest()
|
||||
{
|
||||
var buffer = new byte[12];
|
||||
|
||||
{
|
||||
var src = "abc";
|
||||
var utf8 = Utf8String.From(src, buffer);
|
||||
Assert.AreEqual(3, utf8.ByteLength);
|
||||
Assert.AreEqual(src, utf8.ToString());
|
||||
}
|
||||
{
|
||||
var src = "¢";
|
||||
var utf8 = Utf8String.From(src, buffer);
|
||||
Assert.AreEqual(2, utf8.ByteLength);
|
||||
Assert.AreEqual(src, utf8.ToString());
|
||||
}
|
||||
{
|
||||
var src = "5";
|
||||
var utf8 = Utf8String.From(src, buffer);
|
||||
Assert.AreEqual(3, utf8.ByteLength);
|
||||
Assert.AreEqual(src, utf8.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
UniJSON/Editor/Tests/Utf8StringTest.cs.meta
Normal file
11
UniJSON/Editor/Tests/Utf8StringTest.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c8821be74ee9054d81e25151e023015
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
UniJSON/LICENSE
Normal file
21
UniJSON/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 ousttrue
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
8
UniJSON/LICENSE.meta
Normal file
8
UniJSON/LICENSE.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0cd28905c8909143a42de7256c727e7
|
||||
timeCreated: 1526055773
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Profiling.meta
Normal file
9
UniJSON/Profiling.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 92f8492893093234995cd80054d69cdd
|
||||
folderAsset: yes
|
||||
timeCreated: 1535530113
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
UniJSON/Profiling/.gitignore
vendored
Normal file
15
UniJSON/Profiling/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/.vs
|
||||
/bin
|
||||
/bin.meta
|
||||
/obj
|
||||
/obj.meta
|
||||
*.csproj.user
|
||||
*.csproj.user.meta
|
||||
*.psess
|
||||
*.psess.meta
|
||||
*.vsp
|
||||
*.vsp.meta
|
||||
*.vspx
|
||||
*.vspx.meta
|
||||
App.config.meta
|
||||
|
||||
6
UniJSON/Profiling/App.config
Normal file
6
UniJSON/Profiling/App.config
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
16
UniJSON/Profiling/Program.cs
Normal file
16
UniJSON/Profiling/Program.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
#if UNIJSON_PROFILING
|
||||
namespace UniJSONPRofiling
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var json = File.ReadAllText(args[0], Encoding.UTF8);
|
||||
var parsed = UniJSON.JsonParser.Parse(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
12
UniJSON/Profiling/Program.cs.meta
Normal file
12
UniJSON/Profiling/Program.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a9e570967f10a8b4bb492b9dde8366a9
|
||||
timeCreated: 1533801169
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Profiling/Properties.meta
Normal file
9
UniJSON/Profiling/Properties.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 281449d948b75bf438f20f57379e18fb
|
||||
folderAsset: yes
|
||||
timeCreated: 1533801167
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
UniJSON/Profiling/Properties/AssemblyInfo.cs
Normal file
36
UniJSON/Profiling/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
|
||||
// アセンブリに関連付けられている情報を変更するには、
|
||||
// これらの属性値を変更してください。
|
||||
[assembly: AssemblyTitle("UniJSONPRofiling")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("UniJSONPRofiling")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
|
||||
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
|
||||
// その型の ComVisible 属性を true に設定してください。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
|
||||
[assembly: Guid("59cc2d5e-d4c5-4118-b6db-d6a9d9ba01f1")]
|
||||
|
||||
// アセンブリのバージョン情報は次の 4 つの値で構成されています:
|
||||
//
|
||||
// メジャー バージョン
|
||||
// マイナー バージョン
|
||||
// ビルド番号
|
||||
// Revision
|
||||
//
|
||||
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
|
||||
// 既定値にすることができます:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
12
UniJSON/Profiling/Properties/AssemblyInfo.cs.meta
Normal file
12
UniJSON/Profiling/Properties/AssemblyInfo.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08ef0de807abd6a47b854bd0e546d64e
|
||||
timeCreated: 1533801169
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
UniJSON/Profiling/UniJSONPRofiling.csproj
Normal file
80
UniJSON/Profiling/UniJSONPRofiling.csproj
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>UniJSONPRofiling</RootNamespace>
|
||||
<AssemblyName>UniJSONPRofiling</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;UNIJSON_PROFILING</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="..\Scripts\**\*.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 および x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
8
UniJSON/Profiling/UniJSONPRofiling.csproj.meta
Normal file
8
UniJSON/Profiling/UniJSONPRofiling.csproj.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 442d08a1c2a1c1045a9e56364fefbc22
|
||||
timeCreated: 1533801167
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
UniJSON/Profiling/UniJSONPRofiling.sln
Normal file
28
UniJSON/Profiling/UniJSONPRofiling.sln
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27703.2042
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniJSONPRofiling", "UniJSONPRofiling.csproj", "{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{59CC2D5E-D4C5-4118-B6DB-D6A9D9BA01F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9524149F-AB76-43F8-8F93-D198D87C95C5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
8
UniJSON/Profiling/UniJSONPRofiling.sln.meta
Normal file
8
UniJSON/Profiling/UniJSONPRofiling.sln.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 920f66a990de731479c5bc11d2a3b420
|
||||
timeCreated: 1533801168
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
138
UniJSON/README.md
Normal file
138
UniJSON/README.md
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
# UniJSON
|
||||
JSON serializer and deserializer and schema utilities for Unity(.Net3.5)
|
||||
|
||||
## Usage
|
||||
|
||||
### JSON Create
|
||||
|
||||
```cs
|
||||
var f = new JsonFormatter();
|
||||
f.BeginMap();
|
||||
f.Key("X"); f.Value(1);
|
||||
f.Key("Y"); f.Value(1);
|
||||
f.Key("Z"); f.Value(1);
|
||||
f.EndMap();
|
||||
var json = f.ToString();
|
||||
// {"X":1,"Y":2,"Z":3}
|
||||
```
|
||||
|
||||
### JSON Serialize
|
||||
|
||||
Serialize public fields automatically.
|
||||
|
||||
```cs
|
||||
var f = new JsonFormatter();
|
||||
f.Serialize(new Vector3(1, 2, 3));
|
||||
var json = f.ToString();
|
||||
// {"X":1,"Y":2,"Z":3}
|
||||
```
|
||||
|
||||
### JSON Parse
|
||||
|
||||
```cs
|
||||
var json = "{\"X\":1,\"Y\":2,\"Z\":3}";
|
||||
var parsed = json.ParseAsJson();
|
||||
var x = parsed["X"].GetInt32();
|
||||
```
|
||||
|
||||
### JSON Deserialize
|
||||
|
||||
```cs
|
||||
var v = default(Vector3);
|
||||
json.Deserialize(ref v);
|
||||
```
|
||||
|
||||
### JSON Schema
|
||||
|
||||
```cs
|
||||
[Serializable]
|
||||
public class glTFSparseIndices
|
||||
{
|
||||
[JsonSchema(Minimum = 0)]
|
||||
public int bufferView;
|
||||
|
||||
[JsonSchema(Minimum = 0)]
|
||||
public int byteOffset;
|
||||
|
||||
[JsonSchema(EnumSerializationType = EnumSerializationType.AsInt)]
|
||||
public glComponentType componentType;
|
||||
|
||||
// empty schemas
|
||||
public object extensions;
|
||||
public object extras;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void AccessorSparseIndices()
|
||||
{
|
||||
// from JSON schema
|
||||
var path = Path.GetFullPath(Application.dataPath + "/../glTF/specification/2.0/schema");
|
||||
var SchemaDir = new FileSystemAccessor(path);
|
||||
var fromSchema = JsonSchema.ParseFromPath(SchemaDir.Get("accessor.sparse.indices.schema.json"));
|
||||
|
||||
// from C# type definition
|
||||
var fromClass = JsonSchema.FromType<glTFSparseIndices>();
|
||||
|
||||
Assert.AreEqual(fromSchema, fromClass);
|
||||
}
|
||||
```
|
||||
|
||||
### MsgPack
|
||||
|
||||
Same as json interface
|
||||
|
||||
```cs
|
||||
var f = new MsgPackFormatter();
|
||||
f.Serialize(new Vector3(1, 2, 3));
|
||||
ArraySegment<byte> msgpack = f.GetStoreBytes();
|
||||
|
||||
var parsed = msgpack.ParseAsMsgPack();
|
||||
var x = parsed["X"].GetInt32();
|
||||
```
|
||||
|
||||
### TOML
|
||||
|
||||
WIP
|
||||
|
||||
```cs
|
||||
var toml =@"
|
||||
X = 1
|
||||
Y = 2
|
||||
Z = 3
|
||||
";
|
||||
var parsed = toml.ParseAsToml();
|
||||
var x = parsed["X"].GetInt32();
|
||||
```
|
||||
|
||||
## Reference
|
||||
### JSON
|
||||
|
||||
* https://www.json.org/
|
||||
|
||||
### JSON Schema
|
||||
|
||||
* http://json-schema.org/
|
||||
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0/schema
|
||||
|
||||
### JSON Patch
|
||||
|
||||
* http://jsonpatch.com/
|
||||
|
||||
### JSON RPC
|
||||
|
||||
* https://www.jsonrpc.org/specification
|
||||
|
||||
|
||||
### MsgPack
|
||||
|
||||
* https://github.com/msgpack/msgpack/blob/master/spec.md
|
||||
|
||||
### MsgPack-RPC
|
||||
|
||||
* https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
|
||||
|
||||
### TOML
|
||||
|
||||
* https://github.com/toml-lang/toml
|
||||
|
||||
8
UniJSON/README.md.meta
Normal file
8
UniJSON/README.md.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aacd90cc96ffbef4bb472bcb90b2620d
|
||||
timeCreated: 1526055773
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Scripts.meta
Normal file
9
UniJSON/Scripts.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 817581cb4547fa04e877a77b4888dcc8
|
||||
folderAsset: yes
|
||||
timeCreated: 1526055856
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
UniJSON/Scripts/ActionDisposer.cs
Normal file
20
UniJSON/Scripts/ActionDisposer.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public struct ActionDisposer : IDisposable
|
||||
{
|
||||
Action m_action;
|
||||
|
||||
public ActionDisposer(Action action)
|
||||
{
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_action();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/ActionDisposer.cs.meta
Normal file
12
UniJSON/Scripts/ActionDisposer.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ff15446e31b14ac409251c931b7c2038
|
||||
timeCreated: 1531893103
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
UniJSON/Scripts/ByteBuffer.cs
Normal file
90
UniJSON/Scripts/ByteBuffer.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class ByteBuffer
|
||||
{
|
||||
Byte[] m_buffer;
|
||||
public ArraySegment<Byte> Bytes
|
||||
{
|
||||
get { return new ArraySegment<byte>(m_buffer, 0, Count); }
|
||||
}
|
||||
|
||||
public ByteBuffer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ByteBuffer(Byte[] buffer)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
}
|
||||
|
||||
int m_used;
|
||||
public int Count
|
||||
{
|
||||
get { return m_used; }
|
||||
}
|
||||
|
||||
public int Remain
|
||||
{
|
||||
get {
|
||||
if (m_buffer == null) return 0;
|
||||
return m_buffer.Length - m_used;
|
||||
}
|
||||
}
|
||||
|
||||
void Ensure(int size)
|
||||
{
|
||||
if (m_buffer != null && size < m_buffer.Length - m_used)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var buffer = new Byte[m_used + size];
|
||||
if (m_buffer != null && m_used > 0)
|
||||
{
|
||||
Buffer.BlockCopy(m_buffer, 0, buffer, 0, m_used);
|
||||
}
|
||||
m_buffer = buffer;
|
||||
}
|
||||
|
||||
public void Push(Byte b)
|
||||
{
|
||||
Ensure(1);
|
||||
m_buffer[m_used++] = b;
|
||||
}
|
||||
|
||||
public void Push(Byte[] buffer)
|
||||
{
|
||||
Push(new ArraySegment<Byte>(buffer));
|
||||
}
|
||||
|
||||
public void Push(ArraySegment<Byte> buffer)
|
||||
{
|
||||
Ensure(buffer.Count);
|
||||
Buffer.BlockCopy(buffer.Array, buffer.Offset, m_buffer, m_used, buffer.Count);
|
||||
m_used += buffer.Count;
|
||||
}
|
||||
|
||||
public void Unshift(int size)
|
||||
{
|
||||
if (size > m_used)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
if (m_used - size < size)
|
||||
{
|
||||
Buffer.BlockCopy(m_buffer, m_used, m_buffer, 0, m_used - size);
|
||||
m_used = m_used - size;
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = new Byte[m_used];
|
||||
Buffer.BlockCopy(m_buffer, size, buffer, 0, m_used - size);
|
||||
m_buffer = buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
UniJSON/Scripts/ByteBuffer.cs.meta
Normal file
11
UniJSON/Scripts/ByteBuffer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5de1b9c915ceb8d41b95bdc432680fc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
UniJSON/Scripts/Exceptions.cs
Normal file
34
UniJSON/Scripts/Exceptions.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class TreeValueException : ArgumentException
|
||||
{
|
||||
protected TreeValueException(string msg) : base(msg) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Exception failure
|
||||
/// </summary>
|
||||
public class ParserException : TreeValueException
|
||||
{
|
||||
public ParserException(string msg) : base(msg) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Successfully parsed, but fail to getValue
|
||||
/// </summary>
|
||||
public class DeserializationException : TreeValueException
|
||||
{
|
||||
public DeserializationException(string msg) : base(msg) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formatter exception. key value violation
|
||||
/// </summary>
|
||||
public class FormatterException : TreeValueException
|
||||
{
|
||||
public FormatterException(string msg) : base(msg) { }
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Exceptions.cs.meta
Normal file
12
UniJSON/Scripts/Exceptions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d854b575d2e031f40b37a49e1bff8656
|
||||
timeCreated: 1545735558
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Scripts/Extensions.meta
Normal file
9
UniJSON/Scripts/Extensions.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64b77fe68ca869c40b77ae2f19862579
|
||||
folderAsset: yes
|
||||
timeCreated: 1526057063
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
UniJSON/Scripts/Extensions/ArraySegmentExtensions.cs
Normal file
85
UniJSON/Scripts/Extensions/ArraySegmentExtensions.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class ArraySegmentExtensions
|
||||
{
|
||||
public static T[] ArrayOrCopy<T>(this ArraySegment<T> self)
|
||||
{
|
||||
if (self.Array == null || self.Count==0)
|
||||
{
|
||||
return new T[] { };
|
||||
}
|
||||
else if(self.Offset==0 && self.Count==self.Array.Length)
|
||||
{
|
||||
return self.Array;
|
||||
}
|
||||
else
|
||||
{
|
||||
var array = new T[self.Count];
|
||||
Array.Copy(self.Array, self.Offset, array, 0, self.Count);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<T> ToEnumerable<T>(this ArraySegment<T> self)
|
||||
{
|
||||
return self.Array.Skip(self.Offset).Take(self.Count);
|
||||
}
|
||||
|
||||
public static void Set<T>(this ArraySegment<T> self, int index, T value)
|
||||
{
|
||||
if (index < 0 || index >= self.Count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
self.Array[self.Offset + index] = value;
|
||||
}
|
||||
|
||||
public static T Get<T>(this ArraySegment<T> self, int index)
|
||||
{
|
||||
if (index < 0 || index >= self.Count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
return self.Array[self.Offset + index];
|
||||
}
|
||||
|
||||
public static ArraySegment<T> Advance<T>(this ArraySegment<T> self, Int32 n)
|
||||
{
|
||||
return new ArraySegment<T>(self.Array, self.Offset + n, self.Count - n);
|
||||
}
|
||||
|
||||
public static ArraySegment<T> Take<T>(this ArraySegment<T> self, Int32 n)
|
||||
{
|
||||
return new ArraySegment<T>(self.Array, self.Offset, n);
|
||||
}
|
||||
|
||||
public static T[] TakeReversedArray<T>(this ArraySegment<T> self, Int32 n)
|
||||
{
|
||||
var array = new T[n];
|
||||
var x = n - 1;
|
||||
for (int i = 0; i < n; ++i, --x)
|
||||
{
|
||||
array[i] = self.Get(x);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static byte[] Concat(this byte[] lhs, ArraySegment<byte> rhs)
|
||||
{
|
||||
return new ArraySegment<byte>(lhs).Concat(rhs);
|
||||
}
|
||||
|
||||
public static byte[] Concat(this ArraySegment<byte> lhs, ArraySegment<byte> rhs)
|
||||
{
|
||||
var bytes = new byte[lhs.Count + rhs.Count];
|
||||
Buffer.BlockCopy(lhs.Array, lhs.Offset, bytes, 0, lhs.Count);
|
||||
Buffer.BlockCopy(rhs.Array, rhs.Offset, bytes, lhs.Count, rhs.Count);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/ArraySegmentExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/ArraySegmentExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 12d3e22e2e62d4948a5aff4bc42208e9
|
||||
timeCreated: 1495517072
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
UniJSON/Scripts/Extensions/ByteExtensions.cs
Normal file
60
UniJSON/Scripts/Extensions/ByteExtensions.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class ByteExtensions
|
||||
{
|
||||
public static Byte GetHexDigit(this UInt16 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
public static Byte GetHexDigit(this UInt32 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
public static Byte GetHexDigit(this UInt64 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
public static Byte GetHexDigit(this Int16 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
public static Byte GetHexDigit(this Int32 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
public static Byte GetHexDigit(this Int64 n, int index)
|
||||
{
|
||||
return (Byte)(n >> 8 * index & 0xff);
|
||||
}
|
||||
|
||||
public static UInt32 ToUint32(this Single n, Byte[] buffer)
|
||||
{
|
||||
if (buffer.Length < 4)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
using (var ms = new MemoryStream(buffer))
|
||||
using (var w = new BinaryWriter(ms))
|
||||
{
|
||||
w.Write(n);
|
||||
}
|
||||
return BitConverter.ToUInt32(buffer, 0);
|
||||
}
|
||||
public static UInt64 ToUint64(this Double n, Byte[] buffer)
|
||||
{
|
||||
if (buffer.Length < 8)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
using (var ms = new MemoryStream(buffer))
|
||||
using (var w = new BinaryWriter(ms))
|
||||
{
|
||||
w.Write(n);
|
||||
}
|
||||
return BitConverter.ToUInt64(buffer, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/ByteExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/ByteExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aa32ad3ea4c1ec540a03225c0d520af9
|
||||
timeCreated: 1495517078
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
UniJSON/Scripts/Extensions/DateTimeOffsetExtensions.cs
Normal file
21
UniJSON/Scripts/Extensions/DateTimeOffsetExtensions.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class DateTimeOffsetExtensions
|
||||
{
|
||||
public const long TicksPerSecond = 10000000;
|
||||
public readonly static DateTimeOffset EpocTime = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
|
||||
#if !NET_4_6 && !NET_STANDARD_2_0
|
||||
public static long ToUnixTimeSeconds(this DateTimeOffset now)
|
||||
{
|
||||
if (now < EpocTime)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
return (now - EpocTime).Ticks / TicksPerSecond;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/DateTimeOffsetExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/DateTimeOffsetExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d2fd687914fcde848ab36867817cb873
|
||||
timeCreated: 1544155597
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
UniJSON/Scripts/Extensions/EnumExtensions.cs
Normal file
15
UniJSON/Scripts/Extensions/EnumExtensions.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static bool HasFlag(this Enum keys, Enum flag)
|
||||
{
|
||||
if (keys.GetType() != flag.GetType())
|
||||
throw new ArgumentException("Type Mismatch");
|
||||
return (Convert.ToUInt64(keys) & Convert.ToUInt64(flag)) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/EnumExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/EnumExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d8691eccccb3e214db8bc5b86179f428
|
||||
timeCreated: 1526057070
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
UniJSON/Scripts/Extensions/ParserExtensions.cs
Normal file
52
UniJSON/Scripts/Extensions/ParserExtensions.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static ListTreeNode<JsonValue> ParseAsJson(this string json)
|
||||
{
|
||||
return JsonParser.Parse(json);
|
||||
}
|
||||
public static ListTreeNode<JsonValue> ParseAsJson(this Utf8String json)
|
||||
{
|
||||
return JsonParser.Parse(json);
|
||||
}
|
||||
public static ListTreeNode<JsonValue> ParseAsJson(this byte[] bytes)
|
||||
{
|
||||
return JsonParser.Parse(new Utf8String(bytes));
|
||||
}
|
||||
public static ListTreeNode<JsonValue> ParseAsJson(this ArraySegment<byte> bytes)
|
||||
{
|
||||
return JsonParser.Parse(new Utf8String(bytes));
|
||||
}
|
||||
|
||||
public static ListTreeNode<MsgPackValue> ParseAsMsgPack(this byte[] bytes)
|
||||
{
|
||||
return MsgPackParser.Parse(bytes);
|
||||
}
|
||||
public static ListTreeNode<MsgPackValue> ParseAsMsgPack(this ArraySegment<byte> bytes)
|
||||
{
|
||||
return MsgPackParser.Parse(bytes);
|
||||
}
|
||||
|
||||
public static ListTreeNode<TomlValue> ParseAsToml(this string toml)
|
||||
{
|
||||
return TomlParser.Parse(toml);
|
||||
}
|
||||
public static ListTreeNode<TomlValue> ParseAsToml(this Utf8String toml)
|
||||
{
|
||||
return TomlParser.Parse(toml);
|
||||
}
|
||||
public static ListTreeNode<TomlValue> ParseAsToml(this byte[] bytes)
|
||||
{
|
||||
return TomlParser.Parse(new Utf8String(bytes));
|
||||
}
|
||||
public static ListTreeNode<TomlValue> ParseAsToml(this ArraySegment<byte> bytes)
|
||||
{
|
||||
return TomlParser.Parse(new Utf8String(bytes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/ParserExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/ParserExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c25e655e5dc993145a70d9ddde6a6034
|
||||
timeCreated: 1545735557
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
UniJSON/Scripts/Extensions/TypeExtensions.cs
Normal file
28
UniJSON/Scripts/Extensions/TypeExtensions.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class TypeExtensions
|
||||
{
|
||||
public static bool GetIsGenericList(this Type t)
|
||||
{
|
||||
if (t == null) return false;
|
||||
|
||||
return t.IsGenericType
|
||||
&& (t.GetGenericTypeDefinition() == typeof(List<>));
|
||||
}
|
||||
|
||||
public static bool GetIsGenericDictionary(this Type t)
|
||||
{
|
||||
if (t == null) return false;
|
||||
|
||||
return t.IsGenericType
|
||||
&& (t.GetGenericTypeDefinition() == typeof(Dictionary<,>)
|
||||
&& t.GetGenericArguments().FirstOrDefault() == typeof(string)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/Extensions/TypeExtensions.cs.meta
Normal file
12
UniJSON/Scripts/Extensions/TypeExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fb728ca27f90c947890313df5f94d4d
|
||||
timeCreated: 1531634657
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
UniJSON/Scripts/FormatterExtensions.cs
Normal file
71
UniJSON/Scripts/FormatterExtensions.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class FormatterExtensions
|
||||
{
|
||||
public static void Clear(this IFormatter f)
|
||||
{
|
||||
f.GetStore().Clear();
|
||||
}
|
||||
|
||||
public static ArraySegment<Byte> GetStoreBytes(this IFormatter f)
|
||||
{
|
||||
return f.GetStore().Bytes;
|
||||
}
|
||||
|
||||
public static void Key(this IFormatter f, string x)
|
||||
{
|
||||
f.Key(Utf8String.From(x));
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, IEnumerable<byte> raw, int count)
|
||||
{
|
||||
f.Value(new ArraySegment<byte>(raw.Take(count).ToArray()));
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, Byte[] bytes)
|
||||
{
|
||||
f.Value(new ArraySegment<Byte>(bytes));
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, UnityEngine.Vector3 v)
|
||||
{
|
||||
//CommaCheck();
|
||||
f.BeginMap(3);
|
||||
f.Key("x"); f.Value(v.x);
|
||||
f.Key("y"); f.Value(v.y);
|
||||
f.Key("z"); f.Value(v.z);
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
static MethodInfo GetMethod<T>(Expression<Func<T>> expression)
|
||||
{
|
||||
var method = typeof(FormatterExtensions).GetMethod("Serialize");
|
||||
return method.MakeGenericMethod(typeof(T));
|
||||
}
|
||||
|
||||
public static void KeyValue<T>(this IFormatter f, Expression<Func<T>> expression)
|
||||
{
|
||||
var func = expression.Compile();
|
||||
var value = func();
|
||||
if (value != null)
|
||||
{
|
||||
var body = expression.Body as MemberExpression;
|
||||
if (body == null)
|
||||
{
|
||||
body = ((UnaryExpression)expression.Body).Operand as MemberExpression;
|
||||
}
|
||||
f.Key(body.Member.Name);
|
||||
f.Serialize(expression.Compile()());
|
||||
//var method = GetMethod(expression);
|
||||
//method.Invoke(this, new object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/FormatterExtensions.cs.meta
Normal file
12
UniJSON/Scripts/FormatterExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb87cc122742d7544b818c171b15f746
|
||||
timeCreated: 1540812583
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
186
UniJSON/Scripts/FormatterExtensionsSerializer.cs
Normal file
186
UniJSON/Scripts/FormatterExtensionsSerializer.cs
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class FormatterExtensionsSerializer
|
||||
{
|
||||
public static void SerializeDictionary(this IFormatter f, IDictionary<string, object> dictionary)
|
||||
{
|
||||
f.BeginMap(dictionary.Count);
|
||||
foreach (var kv in dictionary)
|
||||
{
|
||||
f.Key(kv.Key);
|
||||
f.SerializeObject(kv.Value);
|
||||
}
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
public static void SerializeArray<T>(this IFormatter f, IEnumerable<T> values)
|
||||
{
|
||||
f.BeginList(values.Count());
|
||||
foreach (var value in values)
|
||||
{
|
||||
f.Serialize(value);
|
||||
}
|
||||
f.EndList();
|
||||
}
|
||||
|
||||
public static void SerializeObjectArray(this IFormatter f, object[] array)
|
||||
{
|
||||
f.BeginList(array.Length);
|
||||
foreach (var x in array)
|
||||
{
|
||||
f.SerializeObject(x);
|
||||
}
|
||||
f.EndList();
|
||||
}
|
||||
|
||||
public static void SerializeObject(this IFormatter f, object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
f.Null();
|
||||
}
|
||||
else
|
||||
{
|
||||
typeof(FormatterExtensionsSerializer).GetMethod("Serialize").MakeGenericMethod(value.GetType()).Invoke(null, new object[] { f, value });
|
||||
}
|
||||
}
|
||||
|
||||
public static void Serialize<T>(this IFormatter f, T arg)
|
||||
{
|
||||
if (arg == null)
|
||||
{
|
||||
f.Null();
|
||||
return;
|
||||
}
|
||||
|
||||
GenericSerializer<T>.Serialize(f, arg);
|
||||
}
|
||||
|
||||
public static void SetCustomSerializer<T>(Action<IFormatter, T> serializer)
|
||||
{
|
||||
GenericSerializer<T>.Set(serializer);
|
||||
}
|
||||
}
|
||||
|
||||
static class GenericSerializer<T>
|
||||
{
|
||||
delegate void Serializer(IFormatter f, T t);
|
||||
|
||||
static Action<IFormatter, T> GetSerializer(Type t)
|
||||
{
|
||||
// object
|
||||
if (typeof(T) == typeof(object) && t.GetType() != typeof(object))
|
||||
{
|
||||
var self = Expression.Parameter(typeof(IFormatter), "f");
|
||||
var arg = Expression.Parameter(t, "value");
|
||||
var call = Expression.Call(typeof(FormatterExtensionsSerializer), "SerializeObject",
|
||||
new Type[] { },
|
||||
self, arg);
|
||||
var lambda = Expression.Lambda(call, self, arg);
|
||||
return (Action<IFormatter, T>)lambda.Compile();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// primitive
|
||||
var mi = typeof(IFormatter).GetMethod("Value", new Type[] { t });
|
||||
if (mi != null)
|
||||
{
|
||||
// premitives
|
||||
var self = Expression.Parameter(typeof(IFormatter), "f");
|
||||
var arg = Expression.Parameter(t, "value");
|
||||
var call = Expression.Call(self, mi, arg);
|
||||
|
||||
var lambda = Expression.Lambda(call, self, arg);
|
||||
return (Action<IFormatter, T>)lambda.Compile();
|
||||
}
|
||||
}
|
||||
catch (AmbiguousMatchException)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
{
|
||||
// dictionary
|
||||
var idictionary = t.GetInterfaces().FirstOrDefault(x =>
|
||||
x.IsGenericType
|
||||
&& x.GetGenericTypeDefinition() == typeof(IDictionary<,>)
|
||||
&& x.GetGenericArguments()[0] == typeof(string)
|
||||
);
|
||||
if (idictionary != null)
|
||||
{
|
||||
//var mi = typeof(IFormatter).GetMethod("SerializeDictionary", new Type[] { t });
|
||||
var self = Expression.Parameter(typeof(IFormatter), "f");
|
||||
var arg = Expression.Parameter(t, "value");
|
||||
var call = Expression.Call(typeof(FormatterExtensionsSerializer), "SerializeDictionary",
|
||||
new Type[] { },
|
||||
self, arg);
|
||||
var lambda = Expression.Lambda(call, self, arg);
|
||||
return (Action<IFormatter, T>)lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// object[]
|
||||
if (t == typeof(object[]))
|
||||
{
|
||||
var self = Expression.Parameter(typeof(IFormatter), "f");
|
||||
var arg = Expression.Parameter(t, "value");
|
||||
var call = Expression.Call(typeof(FormatterExtensionsSerializer), "SerializeObjectArray",
|
||||
new Type[] { },
|
||||
self, arg);
|
||||
var lambda = Expression.Lambda(call, self, arg);
|
||||
return (Action<IFormatter, T>)lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// list
|
||||
var ienumerable = t.GetInterfaces().FirstOrDefault(x =>
|
||||
x.IsGenericType
|
||||
&& x.GetGenericTypeDefinition() == typeof(IEnumerable<>)
|
||||
);
|
||||
if (ienumerable != null)
|
||||
{
|
||||
var self = Expression.Parameter(typeof(IFormatter), "f");
|
||||
var arg = Expression.Parameter(t, "value");
|
||||
var call = Expression.Call(typeof(FormatterExtensionsSerializer), "SerializeArray",
|
||||
ienumerable.GetGenericArguments(),
|
||||
self, arg);
|
||||
var lambda = Expression.Lambda(call, self, arg);
|
||||
return (Action<IFormatter, T>)lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// reflection
|
||||
var schema = JsonSchema.FromType<T>();
|
||||
return (IFormatter f, T value) => schema.Serialize(f, value);
|
||||
}
|
||||
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
static Serializer s_serializer;
|
||||
|
||||
public static void Set(Action<IFormatter, T> serializer)
|
||||
{
|
||||
s_serializer = new Serializer(serializer);
|
||||
}
|
||||
|
||||
public static void Serialize(IFormatter f, T t)
|
||||
{
|
||||
if (s_serializer == null)
|
||||
{
|
||||
s_serializer = new Serializer(GetSerializer(typeof(T)));
|
||||
}
|
||||
s_serializer(f, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/FormatterExtensionsSerializer.cs.meta
Normal file
12
UniJSON/Scripts/FormatterExtensionsSerializer.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 11342b30ed6802d4ebccbcf85663c6a0
|
||||
timeCreated: 1543520703
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
UniJSON/Scripts/GenericCast.cs
Normal file
79
UniJSON/Scripts/GenericCast.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
struct GenericCast<S, T>
|
||||
{
|
||||
public static T Null()
|
||||
{
|
||||
if (typeof(T).IsClass)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MsgPackTypeException("can not null");
|
||||
}
|
||||
}
|
||||
|
||||
delegate T CastFunc(S value);
|
||||
static CastFunc s_cast;
|
||||
|
||||
delegate Func<T> ConstFuncCreator(S value);
|
||||
static ConstFuncCreator s_const;
|
||||
|
||||
public static Func<T> Const(S value)
|
||||
{
|
||||
if (s_const == null)
|
||||
{
|
||||
s_const = new ConstFuncCreator(GenericCast.CreateConst<S, T>());
|
||||
}
|
||||
return s_const(value);
|
||||
}
|
||||
|
||||
public static T Cast(S value)
|
||||
{
|
||||
if (s_cast == null)
|
||||
{
|
||||
s_cast = new CastFunc(GenericCast.CreateCast<S, T>());
|
||||
}
|
||||
return s_cast(value);
|
||||
}
|
||||
}
|
||||
|
||||
static class GenericCast
|
||||
{
|
||||
public static Func<S, T> CreateCast<S, T>()
|
||||
{
|
||||
if (typeof(S) == typeof(T))
|
||||
{
|
||||
// through
|
||||
var src = Expression.Parameter(typeof(S), "src");
|
||||
var lambda = Expression.Lambda(src, src);
|
||||
return (Func<S, T>)lambda.Compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// cast
|
||||
var src = Expression.Parameter(typeof(S), "src");
|
||||
var cast = Expression.Convert(src, typeof(T));
|
||||
var lambda = Expression.Lambda(cast, src);
|
||||
return (Func<S, T>)lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
public static Func<S, Func<T>> CreateConst<S, T>()
|
||||
{
|
||||
var src = Expression.Parameter(typeof(S), "src");
|
||||
var convert = Expression.Convert(src, typeof(T));
|
||||
var lambda = (Func<S, T>)Expression.Lambda(convert, src).Compile();
|
||||
return s =>
|
||||
{
|
||||
var t = lambda(s);
|
||||
return () => t;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/GenericCast.cs.meta
Normal file
12
UniJSON/Scripts/GenericCast.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e1cb5b0419b4a04da69e90f4890c349
|
||||
timeCreated: 1545134074
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
UniJSON/Scripts/IFileSystemAccessor.cs
Normal file
53
UniJSON/Scripts/IFileSystemAccessor.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public interface IFileSystemAccessor
|
||||
{
|
||||
string ReadAllText();
|
||||
string ReadAllText(string relativePath);
|
||||
IFileSystemAccessor Get(string relativePath);
|
||||
}
|
||||
|
||||
public class FileSystemAccessor : IFileSystemAccessor
|
||||
{
|
||||
string m_path;
|
||||
string m_baseDir;
|
||||
public FileSystemAccessor(string path)
|
||||
{
|
||||
m_path = path;
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
m_baseDir = path;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_baseDir = Path.GetDirectoryName(path);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "<" + Path.GetFileName(m_path) + ">";
|
||||
}
|
||||
|
||||
public string ReadAllText()
|
||||
{
|
||||
return File.ReadAllText(m_path, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public string ReadAllText(string relativePath)
|
||||
{
|
||||
var path = Path.Combine(m_baseDir, relativePath);
|
||||
return File.ReadAllText(path, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public IFileSystemAccessor Get(string relativePath)
|
||||
{
|
||||
var path = Path.Combine(m_baseDir, relativePath);
|
||||
return new FileSystemAccessor(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/IFileSystemAccessor.cs.meta
Normal file
12
UniJSON/Scripts/IFileSystemAccessor.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 865a0727ffe095a40abbb2b8d799e720
|
||||
timeCreated: 1531504314
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
UniJSON/Scripts/IFormatter.cs
Normal file
42
UniJSON/Scripts/IFormatter.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public interface IFormatter
|
||||
{
|
||||
IStore GetStore();
|
||||
|
||||
void BeginList(int n);
|
||||
void EndList();
|
||||
|
||||
void BeginMap(int n);
|
||||
void EndMap();
|
||||
|
||||
void Key(Utf8String x);
|
||||
|
||||
void Null();
|
||||
|
||||
void Value(Utf8String x);
|
||||
void Value(String x);
|
||||
|
||||
void Value(ArraySegment<Byte> bytes);
|
||||
|
||||
void Value(Boolean x);
|
||||
|
||||
void Value(Byte x);
|
||||
void Value(UInt16 x);
|
||||
void Value(UInt32 x);
|
||||
void Value(UInt64 x);
|
||||
|
||||
void Value(SByte x);
|
||||
void Value(Int16 x);
|
||||
void Value(Int32 x);
|
||||
void Value(Int64 x);
|
||||
|
||||
void Value(Single x);
|
||||
void Value(Double x);
|
||||
|
||||
void Value(DateTimeOffset x);
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/IFormatter.cs.meta
Normal file
12
UniJSON/Scripts/IFormatter.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5fb858fc98e29c54d87df97ead98608e
|
||||
timeCreated: 1540812551
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
UniJSON/Scripts/IStore.meta
Normal file
9
UniJSON/Scripts/IStore.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2596156c052e9eb4d888f01f13445446
|
||||
folderAsset: yes
|
||||
timeCreated: 1531806172
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
UniJSON/Scripts/IStore/ByteUnion.cs
Normal file
109
UniJSON/Scripts/IStore/ByteUnion.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class ByteUnion
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct WordValue
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Int16 Signed;
|
||||
[FieldOffset(0)]
|
||||
public UInt16 Unsigned;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public byte Byte0;
|
||||
[FieldOffset(1)]
|
||||
public byte Byte1;
|
||||
|
||||
public WordValue HostToNetworkOrder() { return new WordValue { Signed = IPAddress.HostToNetworkOrder(Signed) }; }
|
||||
|
||||
public static WordValue Create(Int16 value) { return new WordValue { Signed = value }; }
|
||||
public static WordValue Create(UInt16 value) { return new WordValue { Unsigned = value }; }
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct DWordValue
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Int32 Signed;
|
||||
[FieldOffset(0)]
|
||||
public UInt32 Unsigned;
|
||||
[FieldOffset(0)]
|
||||
public Single Float;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public byte Byte0;
|
||||
[FieldOffset(1)]
|
||||
public byte Byte1;
|
||||
[FieldOffset(2)]
|
||||
public byte Byte2;
|
||||
[FieldOffset(3)]
|
||||
public byte Byte3;
|
||||
|
||||
public DWordValue HostToNetworkOrder() { return new DWordValue { Signed = IPAddress.HostToNetworkOrder(Signed) }; }
|
||||
|
||||
public static DWordValue Create(Int32 value) { return new DWordValue { Signed = value }; }
|
||||
public static DWordValue Create(UInt32 value) { return new DWordValue { Unsigned = value }; }
|
||||
public static DWordValue Create(Single value) { return new DWordValue { Float = value }; }
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct QWordValue
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Int64 Signed;
|
||||
[FieldOffset(0)]
|
||||
public UInt64 Unsigned;
|
||||
[FieldOffset(0)]
|
||||
public Double Float;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public byte Byte0;
|
||||
[FieldOffset(1)]
|
||||
public byte Byte1;
|
||||
[FieldOffset(2)]
|
||||
public byte Byte2;
|
||||
[FieldOffset(3)]
|
||||
public byte Byte3;
|
||||
[FieldOffset(4)]
|
||||
public byte Byte4;
|
||||
[FieldOffset(5)]
|
||||
public byte Byte5;
|
||||
[FieldOffset(6)]
|
||||
public byte Byte6;
|
||||
[FieldOffset(7)]
|
||||
public byte Byte7;
|
||||
|
||||
public QWordValue HostToNetworkOrder()
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
return new QWordValue
|
||||
{
|
||||
Byte0 = Byte7,
|
||||
Byte1 = Byte6,
|
||||
Byte2 = Byte5,
|
||||
Byte3 = Byte4,
|
||||
Byte4 = Byte3,
|
||||
Byte5 = Byte2,
|
||||
Byte6 = Byte1,
|
||||
Byte7 = Byte0,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static QWordValue Create(Int64 value) { return new QWordValue { Signed = value }; }
|
||||
public static QWordValue Create(UInt64 value) { return new QWordValue { Unsigned = value }; }
|
||||
public static QWordValue Create(Double value) { return new QWordValue { Float = value }; }
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/IStore/ByteUnion.cs.meta
Normal file
12
UniJSON/Scripts/IStore/ByteUnion.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 90602a3805f09cb46a2e25d5e9cb3cf4
|
||||
timeCreated: 1540907585
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
288
UniJSON/Scripts/IStore/BytesStore.cs
Normal file
288
UniJSON/Scripts/IStore/BytesStore.cs
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class BytesStore : IStore
|
||||
{
|
||||
public BytesStore() : this(64)
|
||||
{ }
|
||||
|
||||
public BytesStore(int size) : this(new Byte[size])
|
||||
{ }
|
||||
|
||||
public BytesStore(Byte[] buffer)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
}
|
||||
|
||||
Byte[] m_buffer;
|
||||
void Require(int size)
|
||||
{
|
||||
if (m_buffer == null)
|
||||
{
|
||||
m_buffer = new Byte[Math.Max(size, 1024)];
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pos + size < m_buffer.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var newSize = Math.Max(m_pos + size, m_buffer.Length * 2);
|
||||
//Console.WriteLine(newSize);
|
||||
var old = m_buffer;
|
||||
m_buffer = new Byte[newSize];
|
||||
Buffer.BlockCopy(old, 0
|
||||
, m_buffer, 0, m_pos);
|
||||
}
|
||||
|
||||
int m_pos;
|
||||
|
||||
public ArraySegment<byte> Bytes
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ArraySegment<byte>(m_buffer, 0, m_pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
char[] m_c = new char[1];
|
||||
public void Write(char c)
|
||||
{
|
||||
if (c <= 0x7F)
|
||||
{
|
||||
// ascii
|
||||
Require(1);
|
||||
m_buffer[m_pos++] = (Byte)c;
|
||||
return;
|
||||
}
|
||||
|
||||
Require(3);
|
||||
m_c[0] = c;
|
||||
var size = Encoding.UTF8.GetBytes(m_c, 0, 1, m_buffer, m_pos);
|
||||
m_pos += size;
|
||||
}
|
||||
|
||||
public void Write(string src)
|
||||
{
|
||||
var size = Encoding.UTF8.GetByteCount(src);
|
||||
Require(size);
|
||||
var byteSize = Encoding.UTF8.GetBytes(src, 0, src.Length
|
||||
, m_buffer, m_pos);
|
||||
if (size != byteSize)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
m_pos += byteSize;
|
||||
}
|
||||
|
||||
public void Write(ArraySegment<byte> bytes)
|
||||
{
|
||||
Require(bytes.Count);
|
||||
Array.Copy(bytes.Array, bytes.Offset
|
||||
, m_buffer, m_pos, bytes.Count);
|
||||
m_pos += bytes.Count;
|
||||
}
|
||||
|
||||
public void Write(sbyte value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
m_buffer[m_pos++] = (Byte)value;
|
||||
}
|
||||
|
||||
public void Write(byte value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
m_buffer[m_pos++] = value;
|
||||
}
|
||||
|
||||
#region LittleEndian
|
||||
public void WriteLittleEndian(short value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.WordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(int value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(long value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(ushort value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.WordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(uint value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(ulong value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(float value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(double value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region BigEndian
|
||||
public void WriteBigEndian(short value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.WordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(int value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(long value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(ushort value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.WordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(uint value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(ulong value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(float value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.DWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
|
||||
public void WriteBigEndian(double value)
|
||||
{
|
||||
Require(Marshal.SizeOf(value));
|
||||
var u = ByteUnion.QWordValue.Create(value);
|
||||
m_buffer[m_pos++] = u.Byte7;
|
||||
m_buffer[m_pos++] = u.Byte6;
|
||||
m_buffer[m_pos++] = u.Byte5;
|
||||
m_buffer[m_pos++] = u.Byte4;
|
||||
m_buffer[m_pos++] = u.Byte3;
|
||||
m_buffer[m_pos++] = u.Byte2;
|
||||
m_buffer[m_pos++] = u.Byte1;
|
||||
m_buffer[m_pos++] = u.Byte0;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/IStore/BytesStore.cs.meta
Normal file
12
UniJSON/Scripts/IStore/BytesStore.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d49a52418427394499c901cb23f13d30
|
||||
timeCreated: 1540907458
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
UniJSON/Scripts/IStore/IStore.cs
Normal file
63
UniJSON/Scripts/IStore/IStore.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public interface IStore
|
||||
{
|
||||
void Clear();
|
||||
ArraySegment<Byte> Bytes { get; }
|
||||
|
||||
void Write(Byte value);
|
||||
void Write(SByte value);
|
||||
|
||||
// network
|
||||
void WriteBigEndian(UInt16 value);
|
||||
void WriteBigEndian(UInt32 value);
|
||||
void WriteBigEndian(UInt64 value);
|
||||
void WriteBigEndian(Int16 value);
|
||||
void WriteBigEndian(Int32 value);
|
||||
void WriteBigEndian(Int64 value);
|
||||
void WriteBigEndian(Single value);
|
||||
void WriteBigEndian(Double value);
|
||||
|
||||
// intel cpu
|
||||
void WriteLittleEndian(UInt16 value);
|
||||
void WriteLittleEndian(UInt32 value);
|
||||
void WriteLittleEndian(UInt64 value);
|
||||
void WriteLittleEndian(Int16 value);
|
||||
void WriteLittleEndian(Int32 value);
|
||||
void WriteLittleEndian(Int64 value);
|
||||
void WriteLittleEndian(Single value);
|
||||
void WriteLittleEndian(Double value);
|
||||
|
||||
void Write(ArraySegment<Byte> bytes);
|
||||
|
||||
void Write(string src);
|
||||
void Write(char c);
|
||||
}
|
||||
|
||||
public static class IStoreExtensions
|
||||
{
|
||||
public static void WriteValues(this IStore s, params Byte[] bytes)
|
||||
{
|
||||
s.Write(new ArraySegment<Byte>(bytes));
|
||||
}
|
||||
|
||||
public static void Write(this IStore s, Byte[] bytes)
|
||||
{
|
||||
s.Write(new ArraySegment<Byte>(bytes));
|
||||
}
|
||||
|
||||
public static void Write(this IStore s, IEnumerable<Byte> bytes)
|
||||
{
|
||||
s.Write(new ArraySegment<Byte>(bytes.ToArray()));
|
||||
}
|
||||
|
||||
public static Utf8String ToUtf8String(this IStore s)
|
||||
{
|
||||
return new Utf8String(s.Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UniJSON/Scripts/IStore/IStore.cs.meta
Normal file
12
UniJSON/Scripts/IStore/IStore.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 558419bba2d829e4884fca9c2046fc3c
|
||||
timeCreated: 1495517075
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
149
UniJSON/Scripts/IStore/StreamStore.cs
Normal file
149
UniJSON/Scripts/IStore/StreamStore.cs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class StreamStore: IStore
|
||||
{
|
||||
Stream m_s;
|
||||
BinaryWriter m_w;
|
||||
|
||||
public StreamStore(Stream s)
|
||||
{
|
||||
m_s = s;
|
||||
m_w = new BinaryWriter(m_s);
|
||||
}
|
||||
|
||||
public ArraySegment<byte> Bytes
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NETFX_CORE
|
||||
throw new NotImplementedException();
|
||||
#else
|
||||
var ms = m_s as MemoryStream;
|
||||
if (ms == null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return new ArraySegment<byte>(ms.GetBuffer(), 0, (int)ms.Position);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_s.SetLength(0);
|
||||
}
|
||||
|
||||
public void Write(sbyte value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void Write(byte value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void Write(char c)
|
||||
{
|
||||
m_w.Write(c);
|
||||
}
|
||||
|
||||
public void Write(string src)
|
||||
{
|
||||
m_w.Write(Encoding.UTF8.GetBytes(src));
|
||||
}
|
||||
|
||||
public void Write(ArraySegment<byte> bytes)
|
||||
{
|
||||
m_w.Write(bytes.Array, bytes.Offset, bytes.Count);
|
||||
}
|
||||
|
||||
#region BigEndian
|
||||
public void WriteBigEndian(int value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(float value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(double value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(long value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(short value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(uint value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(ulong value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void WriteBigEndian(ushort value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LittleEndian
|
||||
public void WriteLittleEndian(long value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(uint value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(short value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(ulong value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(double value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(float value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(int value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
|
||||
public void WriteLittleEndian(ushort value)
|
||||
{
|
||||
m_w.Write(value);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user