AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
97 stars 27 forks source link

How to replace an existing object item from an existing list of objects? #144

Closed LyttleG closed 2 months ago

LyttleG commented 6 months ago

Describe the solution you'd like I create a list of Test object like this:

public class Test
{
    public int Id { get; set; }
    public string Name { get; set; }
}

var testList = new List<Test>(capacity: 100_000);
for (int i = 0; i < 100_000; i++)
    testList.Add(new Test { Name = $"Name_{i}", Id = i });

byte[] avroObject = AvroConvert.Serialize(testList, CodecType.Brotli);

How can I modify an existing object atomically from the avrObject?

// Deserialize each object
using (var reader = AvroConvert.OpenDeserializer<Test>(new MemoryStream(avroObject)))
{
    while (reader.HasNext())
    {
        var item = reader.ReadNext();
        // Modify value here
        item.Name = "Modified";
        // How can i re-ineject the modified value into avroObject?
    }
}

Thanks for any help

AdrianStrugala commented 6 months ago

Hello @LyttleG, I am afraid that currently there is no solution similar to your suggestion. At the moment this result could be achieved by deserializing the whole object, modyfing and serializing again. Any implementation suggestions are warm welomed 👍 Adrian

github-actions[bot] commented 2 months ago

Closed due to inactivity.