From cef89ad0c1c13f3b981bd8c6d1f3b0827d4f9372 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sun, 20 Jan 2019 02:18:52 +0900 Subject: [PATCH] Fixed IFormatter.Clear that JsonFormatter.Clear dose not called. --- .../UniJSON/Editor/Tests/Json/JsonFormatterTest.cs | 11 +++++++++++ Assets/VRM/UniJSON/Scripts/FormatterExtensions.cs | 5 ----- Assets/VRM/UniJSON/Scripts/IFormatter.cs | 1 + .../VRM/UniJSON/Scripts/MsgPack/MsgPackFormatter.cs | 6 +++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/JsonFormatterTest.cs b/Assets/VRM/UniJSON/Editor/Tests/Json/JsonFormatterTest.cs index 19f8de786..d8fcc52bf 100644 --- a/Assets/VRM/UniJSON/Editor/Tests/Json/JsonFormatterTest.cs +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/JsonFormatterTest.cs @@ -43,5 +43,16 @@ namespace UniJSON Assert.True(json.GetStoreBytes().ToEnumerable().SequenceEqual(bytes)); } } + + [Test] + public void ReUseFormatter() + { + IFormatter f = new JsonFormatter(); + f.Value(1); + + f.Clear(); + // fail + f.Value(2); + } } } diff --git a/Assets/VRM/UniJSON/Scripts/FormatterExtensions.cs b/Assets/VRM/UniJSON/Scripts/FormatterExtensions.cs index 85f464b5c..c934b5031 100644 --- a/Assets/VRM/UniJSON/Scripts/FormatterExtensions.cs +++ b/Assets/VRM/UniJSON/Scripts/FormatterExtensions.cs @@ -9,11 +9,6 @@ namespace UniJSON { public static partial class FormatterExtensions { - public static void Clear(this IFormatter f) - { - f.GetStore().Clear(); - } - public static ArraySegment GetStoreBytes(this IFormatter f) { return f.GetStore().Bytes; diff --git a/Assets/VRM/UniJSON/Scripts/IFormatter.cs b/Assets/VRM/UniJSON/Scripts/IFormatter.cs index 3fe99953e..101cfdd40 100644 --- a/Assets/VRM/UniJSON/Scripts/IFormatter.cs +++ b/Assets/VRM/UniJSON/Scripts/IFormatter.cs @@ -6,6 +6,7 @@ namespace UniJSON public interface IFormatter { IStore GetStore(); + void Clear(); void BeginList(int n); void EndList(); diff --git a/Assets/VRM/UniJSON/Scripts/MsgPack/MsgPackFormatter.cs b/Assets/VRM/UniJSON/Scripts/MsgPack/MsgPackFormatter.cs index eea676d69..47e4ff388 100644 --- a/Assets/VRM/UniJSON/Scripts/MsgPack/MsgPackFormatter.cs +++ b/Assets/VRM/UniJSON/Scripts/MsgPack/MsgPackFormatter.cs @@ -1,5 +1,4 @@ using System; -using System.Text; namespace UniJSON @@ -16,6 +15,11 @@ namespace UniJSON { } + public void Clear() + { + m_store.Clear(); + } + #if false public bool MsgPack_Ext(IList list) {