diff --git a/sandbox/SandboxConsoleApp/Program.cs b/sandbox/SandboxConsoleApp/Program.cs index 667be9b7..e4b468a8 100644 --- a/sandbox/SandboxConsoleApp/Program.cs +++ b/sandbox/SandboxConsoleApp/Program.cs @@ -1,4 +1,5 @@ #pragma warning disable CS8600 +#pragma warning disable CS0169 using MemoryPack; using MemoryPack.Formatters; @@ -20,6 +21,7 @@ using System.Xml.Linq; +Console.WriteLine("foo"); // --- diff --git a/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs b/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs index 75692eb1..78b222d4 100644 --- a/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs +++ b/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs @@ -110,7 +110,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableList.Create(item); return; } @@ -183,7 +183,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableQueue.Create(item); return; } @@ -272,7 +272,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableStack.Create(item); return; } @@ -398,7 +398,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableHashSet.Create(item); return; } @@ -508,7 +508,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableSortedSet.Create(item); return; } @@ -562,7 +562,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableList.Create(item); return; } @@ -635,7 +635,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableQueue.Create(item); return; } @@ -724,7 +724,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableStack.Create(item); return; } @@ -850,7 +850,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta if (length == 1) { - var item = reader.ReadObject(); + var item = reader.ReadValue(); value = ImmutableHashSet.Create(item); return; } diff --git a/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs b/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs index a85516a5..55306ac8 100644 --- a/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs +++ b/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs @@ -414,8 +414,8 @@ public override void Serialize(ref MemoryPackWriter>(value); // write as IEnumerable + writer.WriteValue(value.Key); + writer.WriteValue>(value); // write as IEnumerable } public override void Deserialize(ref MemoryPackReader reader, scoped ref IGrouping? value) @@ -428,7 +428,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IGroupi if (count != 2) MemoryPackSerializationException.ThrowInvalidPropertyCount(2, count); - var key = reader.ReadObject(); + var key = reader.ReadValue(); var values = reader.ReadArray() as IEnumerable; if (key == null) MemoryPackSerializationException.ThrowDeserializeObjectIsNull(nameof(key)); diff --git a/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs b/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs index 569ed874..4d83acba 100644 --- a/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs +++ b/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs @@ -11,8 +11,8 @@ public override void Serialize(ref MemoryPackWriter value) @@ -32,8 +32,8 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref KeyValu if (count != 2) MemoryPackSerializationException.ThrowInvalidPropertyCount(2, count); value = new KeyValuePair( - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue() ); } } diff --git a/src/MemoryPack.Core/Formatters/LazyFormatter.cs b/src/MemoryPack.Core/Formatters/LazyFormatter.cs index c90dfa25..1d679404 100644 --- a/src/MemoryPack.Core/Formatters/LazyFormatter.cs +++ b/src/MemoryPack.Core/Formatters/LazyFormatter.cs @@ -11,7 +11,7 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -24,7 +24,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Lazy(); + var v = reader.ReadValue(); value = new Lazy(v); } } diff --git a/src/MemoryPack.Core/Formatters/NullableFormatter.cs b/src/MemoryPack.Core/Formatters/NullableFormatter.cs index 141a88de..290afc9a 100644 --- a/src/MemoryPack.Core/Formatters/NullableFormatter.cs +++ b/src/MemoryPack.Core/Formatters/NullableFormatter.cs @@ -26,7 +26,7 @@ public override void Serialize(ref MemoryPackWriter(); + value = reader.ReadValue(); } } diff --git a/src/MemoryPack.Core/Formatters/TupleFormatter.cs b/src/MemoryPack.Core/Formatters/TupleFormatter.cs index 4d084cd6..50d1d7b9 100644 --- a/src/MemoryPack.Core/Formatters/TupleFormatter.cs +++ b/src/MemoryPack.Core/Formatters/TupleFormatter.cs @@ -35,7 +35,7 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -49,7 +49,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject() + reader.ReadValue() ); } } @@ -65,8 +65,8 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -80,8 +80,8 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue() ); } } @@ -97,9 +97,9 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -113,9 +113,9 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -131,10 +131,10 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -148,10 +148,10 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -167,11 +167,11 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -185,11 +185,11 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -205,12 +205,12 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -224,12 +224,12 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -245,13 +245,13 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -265,13 +265,13 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -288,14 +288,14 @@ public override void Serialize(ref MemoryPackWriter? value) @@ -309,14 +309,14 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Tuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject()! + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue()! ); } } @@ -333,7 +333,7 @@ public override void Serialize(ref MemoryPackWriter value) @@ -353,7 +353,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 1) MemoryPackSerializationException.ThrowInvalidPropertyCount(1, count); value = new ValueTuple( - reader.ReadObject() + reader.ReadValue() ); } } @@ -369,8 +369,8 @@ public override void Serialize(ref MemoryPackWriter value) @@ -390,8 +390,8 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 2) MemoryPackSerializationException.ThrowInvalidPropertyCount(2, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue() ); } } @@ -407,9 +407,9 @@ public override void Serialize(ref MemoryPackWriter value) @@ -429,9 +429,9 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 3) MemoryPackSerializationException.ThrowInvalidPropertyCount(3, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -447,10 +447,10 @@ public override void Serialize(ref MemoryPackWriter value) @@ -470,10 +470,10 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 4) MemoryPackSerializationException.ThrowInvalidPropertyCount(4, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -489,11 +489,11 @@ public override void Serialize(ref MemoryPackWriter value) @@ -513,11 +513,11 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 5) MemoryPackSerializationException.ThrowInvalidPropertyCount(5, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -533,12 +533,12 @@ public override void Serialize(ref MemoryPackWriter value) @@ -558,12 +558,12 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 6) MemoryPackSerializationException.ThrowInvalidPropertyCount(6, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -579,13 +579,13 @@ public override void Serialize(ref MemoryPackWriter value) @@ -605,13 +605,13 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 7) MemoryPackSerializationException.ThrowInvalidPropertyCount(7, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject() + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue() ); } } @@ -628,14 +628,14 @@ public override void Serialize(ref MemoryPackWriter value) @@ -655,14 +655,14 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ValueTu if (count != 8) MemoryPackSerializationException.ThrowInvalidPropertyCount(8, count); value = new ValueTuple( - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject(), - reader.ReadObject()! + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue(), + reader.ReadValue()! ); } } diff --git a/src/MemoryPack.Core/MemoryPackReader.cs b/src/MemoryPack.Core/MemoryPackReader.cs index d0518936..34567f3a 100644 --- a/src/MemoryPack.Core/MemoryPackReader.cs +++ b/src/MemoryPack.Core/MemoryPackReader.cs @@ -227,13 +227,13 @@ public void ReadPackable(scoped ref T? value) // non packable, get formatter dynamically. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ReadObject(scoped ref T? value) + public void ReadValue(scoped ref T? value) { GetFormatter().Deserialize(ref this, ref value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T? ReadObject() + public T? ReadValue() { T? value = default; GetFormatter().Deserialize(ref this, ref value); diff --git a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs index a3562d78..8659a785 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs @@ -30,7 +30,7 @@ public static void Deserialize(ReadOnlySpan buffer, ref T? value) var reader = new MemoryPackReader(buffer); try { - reader.ReadObject(ref value); + reader.ReadValue(ref value); } finally { @@ -50,7 +50,7 @@ public static void Deserialize(in ReadOnlySequence buffer, ref T? value var reader = new MemoryPackReader(buffer); try { - reader.ReadObject(ref value); + reader.ReadValue(ref value); } finally { diff --git a/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs b/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs index 4d10d713..22e619d2 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs @@ -108,7 +108,7 @@ public static unsafe void Serialize(in TBufferWriter bufferWri public static void Serialize(ref MemoryPackWriter writer, in T? value) where TBufferWriter : IBufferWriter { - writer.WriteObject(value); + writer.WriteValue(value); writer.Flush(); } diff --git a/src/MemoryPack.Core/MemoryPackWriter.cs b/src/MemoryPack.Core/MemoryPackWriter.cs index 4316af49..f485b891 100644 --- a/src/MemoryPack.Core/MemoryPackWriter.cs +++ b/src/MemoryPack.Core/MemoryPackWriter.cs @@ -191,7 +191,7 @@ public void WritePackable(scoped in T? value) // non packable, get formatter dynamically. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void WriteObject(scoped in T? value) + public void WriteValue(scoped in T? value) { depth++; if (depth == DepthLimit) MemoryPackSerializationException.ThrowReachedDepthLimit(typeof(T)); diff --git a/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs b/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs index 94fc26a2..f321b0d2 100644 --- a/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs +++ b/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs @@ -615,7 +615,7 @@ string EmitUnionSerializeBody() { var method = x.Type.IsWillImplementIMemoryPackable(reference) ? "WritePackable" - : "WriteObject"; + : "WriteValue"; return $" case {x.Tag}: writer.{method}(System.Runtime.CompilerServices.Unsafe.As<{TypeName}?, {ToUnionTagTypeFullyQualifiedToString(x.Type)}>(ref value)); break;"; }) .NewLine(); @@ -652,7 +652,7 @@ string EmitUnionDeserializeBody() { var method = x.Type.IsWillImplementIMemoryPackable(reference) ? "ReadPackable" - : "ReadObject"; + : "ReadValue"; return $$""" case {{x.Tag}}: if (value is {{ToUnionTagTypeFullyQualifiedToString(x.Type)}}) @@ -760,7 +760,7 @@ public string EmitSerialize() case MemberKind.Array: return $"writer.WritedArray(value.{Name});"; default: - return $"writer.WriteObject(value.{Name});"; + return $"writer.WriteValue(value.{Name});"; } } @@ -779,7 +779,7 @@ public string EmitReadToDeserialize() case MemberKind.Array: return $"__{Name} = reader.ReadArray<{(MemberType as IArrayTypeSymbol)!.ElementType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>();"; default: - return $"__{Name} = reader.ReadObject<{MemberType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>();"; + return $"__{Name} = reader.ReadValue<{MemberType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>();"; } } @@ -798,7 +798,7 @@ public string EmitReadRefDeserialize() case MemberKind.Array: return $"reader.ReadArray(ref __{Name});"; default: - return $"reader.ReadObject(ref __{Name});"; + return $"reader.ReadValue(ref __{Name});"; } } } diff --git a/src/MemoryPack.Streaming/MemoryPackStreamingSerializer.cs b/src/MemoryPack.Streaming/MemoryPackStreamingSerializer.cs index b6c9c236..6198ec38 100644 --- a/src/MemoryPack.Streaming/MemoryPackStreamingSerializer.cs +++ b/src/MemoryPack.Streaming/MemoryPackStreamingSerializer.cs @@ -21,7 +21,7 @@ static bool WriteWhileReachFlushRate(PipeWriter pipeWriter, IEnumerator enume var writer = new MemoryPackWriter(ref pipeWriter); while (enumerator.MoveNext()) { - writer.WriteObject(enumerator.Current); + writer.WriteValue(enumerator.Current); if (flushRate < writer.WrittenCount) { writer.Flush(); @@ -59,7 +59,7 @@ static bool WriteWhileReachFlushRate(ReusableLinkedArrayBufferWriter bufferWrite var writer = new MemoryPackWriter(ref bufferWriter); while (enumerator.MoveNext()) { - writer.WriteObject(enumerator.Current); + writer.WriteValue(enumerator.Current); if (flushRate < writer.WrittenCount) { writer.Flush(); @@ -111,7 +111,7 @@ static int Deserialize(in ReadOnlySequence buffer, int bufferAtLeast, List return reader.Consumed; } - itemBuffer.Add(reader.ReadObject()); + itemBuffer.Add(reader.ReadValue()); remain.Value--; } diff --git a/tests/MemoryPack.Tests/ProviderTest.cs b/tests/MemoryPack.Tests/ProviderTest.cs index 4a23a533..4842b6c4 100644 --- a/tests/MemoryPack.Tests/ProviderTest.cs +++ b/tests/MemoryPack.Tests/ProviderTest.cs @@ -57,7 +57,7 @@ public override void Serialize(ref MemoryPackWriter(value.Value); + writer.WriteValue(value.Value); } public override void Deserialize(ref MemoryPackReader reader, scoped ref CustomType? value) @@ -69,7 +69,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref CustomT } if (count != 1) MemoryPackSerializationException.ThrowInvalidPropertyCount(1, count); - value = new CustomType { Value = reader.ReadObject() }; + value = new CustomType { Value = reader.ReadValue() }; } }