Skip to content

Repository files navigation

🏷️ Ink.Nbt

Simple, JSON-like and high-performance NBT serialization library, inspired by the API of System.Text.Json.

MIT LicenseNuGet Version

🔍 Usage

  • Serializing and deserializing (Only handwritten converters support at this moment for AOT):
usingInk.Nbt;usingInk.Nbt.Serialization;usingInk.Nbt.Tags;usingSystem.Diagnostics;NbtTagtag=NbtTag.Compound(new(){{"SByte?",NbtTag.SByte(-1)},{"String?",NbtTag.String("Yes")}});{usingFileStreamfile=File.OpenWrite("nbt.nbt.nbt");NbtSerializer.Serialize<JavaNbtDatatypeWriter,NbtTag>(file,"Too much nbt",tag,NbtTag.TypeInfo);}// ...byte[]nbtNbtNbt=File.ReadAllBytes("nbt.nbt.nbt");NbtTagtagAgain=NbtSerializer.Deserialize<JavaNbtDatatypeReader,NbtTag>(nbtNbtNbt,NbtTag.TypeInfo);if(tagAgain["SByte?"].AsInt8()!=-1||tagAgain["String?"].AsString()!="Yes")thrownewUnreachableException();
  • Writing raw nbt data:
usingInk.Nbt;usingFileStreamfile=File.OpenWrite("nbt.nbt.nbt");usingNbtWriter<JavaNbtDatatypeWriter>writer=new(file);writer.WriteCompoundStart("Too much nbt");writer.WriteSByte("SByte?",-1);writer.WriteString("String?","Yes");writer.WriteCompoundEnd();
  • Reading raw nbt data:
usingInk.Nbt;byte[]rawData=[0x0A,0x01,0x00,0x00,0xFF,0x00];NbtReader<JavaNbtDatatypeReader>reader=new(rawData,new(NoRootName:true));while(reader.Read()){}// TokenType: StartCompound -> PropertyName (string.Empty) -> SByte (-1) -> EndCompound -> End (return false)

❓ FAQ

Why do readers and writers need a generic argument?

This library wants to achieve maximum performance while supporting every kind of nbt that exists. The generic argument allows specifying the kind of NBT to be read or written.

Does this handle decompression and compression of NBT?

No, this library is primarily intended for working with raw NBT data. You should decompress it before and compress it after, if you want it compressed.

📜 License

MIT

📝 TODO

  • Allow skipping data while reading
  • Proper exception messages and info
  • Proper tests with NUnit
  • Refine serialization
  • Support continuation while reading?

About

Simple, JSON-like and high-performance NBT serialization library, inspired by the API of System.Text.Json.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages