SceneGate / Yarhl

Framework for the implementation of format converters like game assets or media files
https://scenegate.github.io/Yarhl/
MIT License
60 stars 10 forks source link

Implement reading and writing arrays of primitive types #210

Open pleonex opened 7 months ago

pleonex commented 7 months ago

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