Help us shape the future of Go! Take the 2026 Go Developer Survey

nbt2json

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2018 License: MIT Imports: 6 Imported by: 3

README

nbt2json

A command line utitlity and module that reads NBT data and converts it to JSON for editing and then back to NBT.

Features

  • Command line utility will auto-detect and decompress gzipped files
  • Can read both MCPE/Win10 and Java-based NBT data
    • Does not auto-detect which
    • Utility defaults to MCPE / little endian
  • --skip parameter allows skipping headers. e.g. nbt2json --skip 8 /path/to/level.dat for MCPE's level.dat

Why?

<sigh> Out of all the NBT tools out there, none of them seem to do what I want:

  • Read MCPE (phones, tablets and Win10 app store edition) NBT data which use little endian encoding where the PC Java version uses big endian
  • Convert back and forth to a human readable REST-API-able format
  • Be includeable or as portable as my Go code

There are some Go options I could adapt for little endian, but I'll have to do enough work to make it convert to JSON and back that it's probably simpler to start from scratch, and I'm pretty sure I know how I want to do it.

Dev notes

  • The Json2Nbt function uses an interface{} and encode based on the tagType fields. I had originally hoped to Marshal and Unmarshal to and from JSON and NBT, but my goal was to export to JSON, edit and then reencode. This way the struct doesn't have to match the data schema.
  • My main motivation for this project is to convert to/from JSON and use any JSON editor to modify Minecraft PE data with McpeTool, and to keep the read/write primitives in Go code while letting a client browser manage any validation to avoid having to re-release the read/write tools every time Minecraft changes formats.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Json2Nbt

func Json2Nbt(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

Json2Nbt converts JSON byte array to uncompressed NBT byte array

func Nbt2Json

func Nbt2Json(b []byte, byteOrder binary.ByteOrder) ([]byte, error)

Nbt2Json converts uncompressed NBT byte array to JSON byte array

Types

type JsonParseError

type JsonParseError struct {
	// contains filtered or unexported fields
}

JsonParseError is when the data does not match an expected pattern. Pass it message string and downstream error

func (JsonParseError) Error

func (e JsonParseError) Error() string

type NbtParseError

type NbtParseError struct {
	// contains filtered or unexported fields
}

NbtParseError is when the data does not match an expected pattern. Pass it message string and downstream error

func (NbtParseError) Error

func (e NbtParseError) Error() string

type NbtTag

type NbtTag struct {
	TagType byte        `json:"tagType"`
	Name    string      `json:"name"`
	Value   interface{} `json:"value,omitempty"`
}

NbtTag represents one NBT tag for each struct

type NbtTagList

type NbtTagList struct {
	TagListType byte          `json:"tagListType"`
	List        []interface{} `json:"list"`
}

NbtTagList represents an NBT tag list

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL