MirageNet / Mirage

Easy to use high performance Network library for Unity 3d
https://miragenet.github.io/Mirage/
MIT License
507 stars 63 forks source link

feat: feature to send strings as index #1176

Open James-Frowen opened 3 months ago

James-Frowen commented 3 months ago

will save bandwidth when sending many strings that are the same

This works, but requires test and a better way to use it before merging

James-Frowen commented 3 months ago

example use

public static void WriteMission(this NetworkWriter finalWriter, Mission mission)
{
    var writer = finalWriter;
    var stringStore = new StringStore();
    var writer = new NetworkWriter(64_000, true);
    writer.StringStore = stringStore;

    // write large message with lots of strings here
    // ...

    // write strings then large message 
    finalWriter.WriteStringStore(stringStore);
    finalWriter.WriteBytesAndSizeSegment(writer.ToArraySegment());
}

public static Mission ReadMission(this NetworkReader finalReader)
{
    // read strings, then set it on the inner reader
    var stringStore = finalReader.ReadStringStore();
    var reader = new NetworkReader();
    reader.Reset(finalReader.ReadBytesAndSizeSegment());
    reader.StringStore = stringStore;

    // read large message, reader will use the stringStore we read above
    // ...
}
github-actions[bot] commented 1 month ago

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.