Skip to content

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LitIO

简体中文

LitIO is a small C# library for writing value types, arrays, and UTF-8 strings to a byte buffer and reading them back in the same order.

LitIO cover

What LitIO does

  • Reads and writes unmanaged value-type data through ByteWriter.Write<T> and ByteReader.Read<T>.
  • Handles value-type arrays, UTF-8 strings, and UTF-8 string arrays.
  • Tracks a caller-owned offset instead of creating a stream object.
  • Provides ByteCounter helpers when the required buffer size must be calculated first.

LitIO does not define a self-describing file format. The writer and reader must use the same field order and types. Array and string lengths are stored with a ushort header.

Installation

In Unity, open Window → Package Manager, choose Add package from git URL, and enter:

https://github.com/onovich/LitIO.git?path=/Assets/com.mortise.litio#main

The package metadata declares Unity 2019.4 or later. Compatibility outside the included Unity sample has not been covered by automated tests.

Quick start

using MortiseFrame.LitIO;

byte[] buffer = new byte[256];
int offset = 0;

ByteWriter.Write(buffer, 42, ref offset);
ByteWriter.WriteUTF8String(buffer, "hello", ref offset);
ByteWriter.WriteArray(buffer, new int[] { 3, 5, 8 }, ref offset);

offset = 0;
int value = ByteReader.Read<int>(buffer, ref offset);
string text = ByteReader.ReadUTF8String(buffer, ref offset);
int[] numbers = ByteReader.ReadArray<int>(buffer, ref offset);

Calculate the exact buffer size when needed:

int size = ByteCounter.Count<int>()
         + ByteCounter.CountUTF8String("hello")
         + ByteCounter.CountArray(new int[] { 3, 5, 8 });

Status

The core read, write, array, string, and size-counting paths are implemented. LitIO is used by projects such as Rill and Capsule.

The current package version is 0.0.6. The repository does not include an automated test suite, schema versioning, bounds checks, or cross-version compatibility guarantees; callers own those boundaries.

Development

Runtime code lives in Assets/com.mortise.litio/Runtime/. A runnable usage example is available in Assets/com.mortise.litio/Sample/Sample.cs.

License

MIT

About

A compact C# binary serialization library.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages