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) {