Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feature to send strings as index #1176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

James-Frowen
Copy link
Member

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

will save bandwidth when sending many strings that are the same
@James-Frowen
Copy link
Member Author

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
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant