nbtd 1.0.1

A lightweight NBT decoding/encoding library


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

nbtd

A small NBT encoding and decoding library for D.

It supports all Data TAGs in version 19133 and contains a simple API.

Examples

Hello World

import std.file;

import nbtd;

void main(string[] args)
{
	NBTString helloWorld = new NBTString("Hello World");
	write("helloWorld.nbt.gz", helloWorld.encode(true, false));
	// helloWorld.nbt.gz will now contain this binary string compressed:
	// 11               Hello World
	// String Length    UTF-8 string
	//
	// TAG-ID and Name are not written when hasName is false
}

Encoding & Decoding

import std.file;

import nbtd;

void main(string[] args)
{
	NBTCompound level = new NBTCompound();
	level.name = "Level";
	level["players"] = new NBTList([new NBTString("Foo"), new NBTString("Bar")]);
	level["seed"] = new NBTLong(48968643157);

	write("level.nbt.gz", level.encode());
	write("level.nbt", level.encode(false));

	NBTCompound imported = new NBTCompound();
	imported.decode(cast(ubyte[])read("level.nbt.gz"));
	assert(imported.name == "Level");
	assert(imported["players"].asList().length == 2);
	assert(imported["players"].asList()[0].asString().value == "Foo");
	assert(imported["players"].asList()[1].asString().value == "Bar");
	assert(imported["seed"].asLong().value == 48968643157);
}

TODO

  • [ ] Encoding/Decoding using class schemas
  • [ ] Easier interface for files
  • [x] Encoding/Decoding ubyte[]
  • [x] Encoding/Decoding gzip'd ubyte[]
  • [x] Support all 19133 TAGs
Authors:
  • WebFreak001
Dependencies:
none
Versions:
1.0.1 2015-Jun-07
1.0.0 2015-Jun-06
~master 2015-Jun-07
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 138 downloads total

Score:
0.7
Short URL:
nbtd.dub.pm