Skip to content

Commit

Permalink
Merge pull request #11 from Cysharp/object-to-value
Browse files Browse the repository at this point in the history
Chagne ReadWriter method name, Write/ReadObject -> Write/ReadValue
  • Loading branch information
neuecc authored Sep 30, 2022
2 parents cbc70e0 + 8b0497b commit dd4ea81
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 180 deletions.
2 changes: 2 additions & 0 deletions sandbox/SandboxConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma warning disable CS8600
#pragma warning disable CS0169

using MemoryPack;
using MemoryPack.Formatters;
Expand All @@ -20,6 +21,7 @@
using System.Xml.Linq;


Console.WriteLine("foo");

// ---

Expand Down
18 changes: 9 additions & 9 deletions src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableList.Create(item);
return;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableQueue.Create(item);
return;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableStack.Create(item);
return;
}
Expand Down Expand Up @@ -398,7 +398,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableHashSet.Create(item);
return;
}
Expand Down Expand Up @@ -508,7 +508,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Immutab

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableSortedSet.Create(item);
return;
}
Expand Down Expand Up @@ -562,7 +562,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableList.Create(item);
return;
}
Expand Down Expand Up @@ -635,7 +635,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableQueue.Create(item);
return;
}
Expand Down Expand Up @@ -724,7 +724,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableStack.Create(item);
return;
}
Expand Down Expand Up @@ -850,7 +850,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref IImmuta

if (length == 1)
{
var item = reader.ReadObject<T>();
var item = reader.ReadValue<T>();
value = ImmutableHashSet.Create(item);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter
}

writer.WriteObjectHeader(2);
writer.WriteObject(value.Key);
writer.WriteObject<IEnumerable<TElement>>(value); // write as IEnumerable<TElement>
writer.WriteValue(value.Key);
writer.WriteValue<IEnumerable<TElement>>(value); // write as IEnumerable<TElement>
}

public override void Deserialize(ref MemoryPackReader reader, scoped ref IGrouping<TKey, TElement>? value)
Expand All @@ -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<TKey>();
var key = reader.ReadValue<TKey>();
var values = reader.ReadArray<TElement>() as IEnumerable<TElement>;

if (key == null) MemoryPackSerializationException.ThrowDeserializeObjectIsNull(nameof(key));
Expand Down
8 changes: 4 additions & 4 deletions src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter
}

writer.WriteObjectHeader(2);
writer.WriteObject(value.Key);
writer.WriteObject(value.Value);
writer.WriteValue(value.Key);
writer.WriteValue(value.Value);
}

public override void Deserialize(ref MemoryPackReader reader, scoped ref KeyValuePair<TKey?, TValue?> value)
Expand All @@ -32,8 +32,8 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref KeyValu
if (count != 2) MemoryPackSerializationException.ThrowInvalidPropertyCount(2, count);

value = new KeyValuePair<TKey?, TValue?>(
reader.ReadObject<TKey>(),
reader.ReadObject<TValue>()
reader.ReadValue<TKey>(),
reader.ReadValue<TValue>()
);
}
}
4 changes: 2 additions & 2 deletions src/MemoryPack.Core/Formatters/LazyFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter
}

writer.WriteObjectHeader(1);
writer.WriteObject(value.Value);
writer.WriteValue(value.Value);
}

public override void Deserialize(ref MemoryPackReader reader, scoped ref Lazy<T?>? value)
Expand All @@ -24,7 +24,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Lazy<T?

if (count != 1) MemoryPackSerializationException.ThrowInvalidPropertyCount(1, count);

var v = reader.ReadObject<T>();
var v = reader.ReadValue<T>();
value = new Lazy<T?>(v);
}
}
4 changes: 2 additions & 2 deletions src/MemoryPack.Core/Formatters/NullableFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter
writer.WriteObjectHeader(1);
}

writer.WriteObject(value.Value);
writer.WriteValue(value.Value);
}

public override void Deserialize(ref MemoryPackReader reader, scoped ref T? value)
Expand All @@ -45,6 +45,6 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref T? valu

if (count != 1) MemoryPackSerializationException.ThrowInvalidPropertyCount(1, count);

value = reader.ReadObject<T>();
value = reader.ReadValue<T>();
}
}
Loading

0 comments on commit dd4ea81

Please sign in to comment.