Skip to content

Byte Array serialization #150

@LorenzoRuggeri

Description

@LorenzoRuggeri

Hi rpgmaker,
first of all thanks for your great work!

I (ab)-used a lot of your work for an inter-server communication project and I appreciated it.
Now I'm facing again my caching project, which I pulled out 2 years ago.
Updated libraries via NUGet and... go for benchmarking.
Well, NetJSON won by a mile over Wire. :) At least on my simple DTOs. :)

The problem is when I pass an object with byte array as property. I don't catch an error until I deserialize the resulting bytes.
To do so I encapsulated the Serialize and Deserialize in those two methods (they both inherit from an interface I use on my project, which I wish to don't change):

    public byte[] Serialize<T>(T value)
    {
        return Encoding.UTF8.GetBytes(NetJSON.NetJSON.Serialize(value.GetType(), value));
    }


    public T Deserialize<T>(byte[] bytes)
    {
        return (T)NetJSON.NetJSON.Deserialize(typeof(T), Encoding.UTF8.GetString(bytes));
    }

Are they correct? Would you suggest another way to serialize/deserialize an object?

Are the byte arrays excluded from a re-work in NetJSON?
Do I need to serialize a byte array through NetJSON.NetJSON.RegisterTypeSerializer (Func <T, string> serializeFunc); ? And if yes how would you suggest it?

Thanks again 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions