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

Implement reading and writing arrays of primitive types #210

Open
pleonex opened this issue Jan 31, 2024 · 0 comments
Open

Implement reading and writing arrays of primitive types #210

pleonex opened this issue Jan 31, 2024 · 0 comments

Comments

@pleonex
Copy link
Member

pleonex commented Jan 31, 2024

Goal

Simple API to read an array of primitive types.
Simple API to write an array of primitive types.
Primitive types including: integers signed and unsigned, decimals (single and double).

Description

DataWriter and DataReader already have APIs to read and write primitive types. If we want to read a simple collection of them, we need to create a loop. The exception is a byte array.

The goal is to simplify these use cases:

// reading
for (int i = 0; i < count; i++) {
    myArray[i] = reader.ReadInt32();
}

// writing
for (int i = 0; i < count; i++) {
    writer.Write(myArray[i]);
}

Proposed solution

Support reading and writing arrays in DataReader and DataWriter, similar to the ReadBytes() and Write(byte[]) methods. Use spans in the writing side if possible.

Consider supporting strings and chars as well.

Acceptance criteria

  • One method to write array of primitive types
  • One method to read array of primitive types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant