nbtreader

package module
v0.0.0-...-cbb0448 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 11 Imported by: 0

README

nbtreader

Parse and show Minecrafts NBT files in the command-line.

Installing

Clone repo and build cli with Go

go build -o nbtreader ./cli

PS: For Windows its recommended to add a .exe to the filename:

go build -o nbtreader.exe ./cli

This produces an ready-to-use executable file named nbtreader (or nbtreader.exe). See next Section for using the command and its syntax.

You may want to add a symlink in your PATH to this file, so you can use this executable systemwide. In the following examples I call the command nbtreader to call the file.

Usage

After installation the binary can be used simply by passing a filename as argument:

nbtreader files/test.dat

produces

{
  name: "Bananrama"
}

and

nbtreader files/bigtest.nbt

produces

{
  longTest: 9223372036854775807l,
  shortTest: 32767s,
  stringTest: "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!",
  floatTest: 0.49823147f,
  intTest: 2147483647,
  nested compound test: {
    ham: {
      name: "Hampus",
      value: 0.75f
    },
    egg: {
      name: "Eggbert",
      value: 0.5f
    }
  },
  listTest (long): [11l, 12l, 13l, 14l, 15l],
  listTest (compound): [{
    name: "Compound tag #0",
    created-on: 1264099775885l
  }, {
    name: "Compound tag #1",
    created-on: 1264099775885l
  }],
  byteTest: 127b,
  byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...)): [B; 0b, 62b, <trimmed 996 values>, 6b, 48b],
  doubleTest: 0.4931287132182315d
}

If no file is given, nbtreader reads from stdin:

# e.g. with pipe
cat files/test.nbt | nbtreader
# or redirect
nbreader < files/test.nbt
Flags

Available flags are

  • -inType <string>
  • -outType <string>
  • uncompressed
  • -out <string>
Flag inType and outType

With theese flags you can specify the in- and output type.

Current valid values for inType:

  • NBT (default if ommited)

Current valid values for outType:

  • JSON
  • NBT
  • NJSON (see spec)
  • SNBT (default if ommited)

Example:

nbtreader -outType JSON files/test.nbt

produces

{
	"name": "Bananrama"
}
Flag uncompressed

When using the -outType NBT option the output file will be written in compressed format using GZip. However, you can pass in the -uncompressed flag to write the NBT data in raw without compressing them.

nbtreader -outType NBT -uncompressed -out files/output_raw.nbt files/test.nbt

Using -uncompressed without setting the outType to NBT has no effect and is silently igonred.

Flag out

To easily save the result in a file you could once again use redirecting:

nbtreader files/test.nbt > files output.txt

However, if you pass in the optional flag -out <filename> the output is instead written to the given filename:

nbtreader -out files/output.txt files/test.nbt

Documentation

Index

Constants

View Source
const (
	NONE compression = iota
	GZIP
	ZIP
	TAR
)

Variables

This section is empty.

Functions

func MarshalNJSON

func MarshalNJSON(v any) ([]byte, error)

Types

type Byte

type Byte int8

func (Byte) MarshalJSON

func (t Byte) MarshalJSON() ([]byte, error)

func (Byte) String

func (t Byte) String() string

func (Byte) Type

func (t Byte) Type() TagType

type ByteArray

type ByteArray []Byte

func (ByteArray) MarshalJSON

func (t ByteArray) MarshalJSON() ([]byte, error)

func (ByteArray) String

func (t ByteArray) String() string

func (ByteArray) Type

func (t ByteArray) Type() TagType

type Compound

type Compound map[String]struct {
	Index int
	Value NbtTag
}

func (Compound) MarshalJSON

func (t Compound) MarshalJSON() ([]byte, error)

func (Compound) MarshalNJSON

func (t Compound) MarshalNJSON() ([]byte, error)

func (Compound) String

func (t Compound) String() string

func (Compound) Type

func (t Compound) Type() TagType

type Double

type Double float64

func (Double) MarshalJSON

func (t Double) MarshalJSON() ([]byte, error)

func (Double) String

func (t Double) String() string

func (Double) Type

func (t Double) Type() TagType

type Float

type Float float32

func (Float) MarshalJSON

func (t Float) MarshalJSON() ([]byte, error)

func (Float) String

func (t Float) String() string

func (Float) Type

func (t Float) Type() TagType

type Int

type Int int32

func (Int) MarshalJSON

func (t Int) MarshalJSON() ([]byte, error)

func (Int) String

func (t Int) String() string

func (Int) Type

func (t Int) Type() TagType

type IntArray

type IntArray []Int

func (IntArray) MarshalJSON

func (t IntArray) MarshalJSON() ([]byte, error)

func (IntArray) String

func (t IntArray) String() string

func (IntArray) Type

func (t IntArray) Type() TagType

type List

type List struct {
	TagType  TagType
	Elements []NbtTag
}

func (List) MarshalJSON

func (t List) MarshalJSON() ([]byte, error)

func (List) String

func (t List) String() string

func (List) Type

func (t List) Type() TagType

type Long

type Long int64

func (Long) MarshalJSON

func (t Long) MarshalJSON() ([]byte, error)

func (Long) String

func (t Long) String() string

func (Long) Type

func (t Long) Type() TagType

type LongArray

type LongArray []Long

func (LongArray) MarshalJSON

func (t LongArray) MarshalJSON() ([]byte, error)

func (LongArray) String

func (t LongArray) String() string

func (LongArray) Type

func (t LongArray) Type() TagType

type Marshaler

type Marshaler interface {
	MarshalNJSON() ([]byte, error)
}

Marshaler is the interface implemented by types that can marshal themselves into valid NJSON.

type NBT

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

NBT is a go struct representation of a Minecraft NBT object.

func New

func New(r io.Reader, w io.Writer) (nbt *NBT, err error)

New creates a new NBT object. The given data will be completely parsed, including decompression (if compressed).

The resulting NBT object can be used to change or get single nbt values and compose it again.

func (*NBT) MarshalJSON

func (nbt *NBT) MarshalJSON() ([]byte, error)

func (*NBT) MarshalNJSON

func (nbt *NBT) MarshalNJSON() ([]byte, error)

func (*NBT) NBT

func (nbt *NBT) NBT(compressed bool) (err error)

NBT takes the NBT object and composes it to the nbt binary format. It also will be compressed using gzip if specified. The data will be written to the underlying io.Writer.

func (NBT) String

func (nbt NBT) String() string

String implements the fmt.Stringer interface. The given NBT object will be converted to a SNBT string, including linebreaks.

type NbtTag

type NbtTag interface {
	String() string
	Type() TagType
	// contains filtered or unexported methods
}

type Short

type Short int16

func (Short) MarshalJSON

func (t Short) MarshalJSON() ([]byte, error)

func (Short) String

func (t Short) String() string

func (Short) Type

func (t Short) Type() TagType

type String

type String string

func (String) Len

func (t String) Len() Short

func (String) MarshalJSON

func (t String) MarshalJSON() ([]byte, error)

func (String) String

func (t String) String() string

func (String) Type

func (t String) Type() TagType

type TagType

type TagType byte
const (
	Tag_End TagType = iota
	Tag_Byte
	Tag_Short
	Tag_Int
	Tag_Long
	Tag_Float
	Tag_Double
	Tag_Byte_Array
	Tag_String
	Tag_List
	Tag_Compound
	Tag_Int_Array
	Tag_Long_Array
)

func (TagType) Annotation

func (t TagType) Annotation() TypeAnnotation

func (TagType) String

func (t TagType) String() string

type TypeAnnotation

type TypeAnnotation uint8
const (
	NoAnnotation TypeAnnotation = iota
	InferenceAnnotation
	CompoundAnnotation
	ByteArrayAnnotation
	IntArrayAnnotation
	LongArrayAnnotation
	InferenceArrayAnnotation
	ByteAnnotation
	ShortAnnotation
	IntAnnotation
	LongAnnotation
	FloatAnnotation
	DoubleAnnotation
	StringAnnotation
)

func AnnotationOf

func AnnotationOf(v reflect.Value) TypeAnnotation

func (TypeAnnotation) Characters

func (ta TypeAnnotation) Characters() string

func (TypeAnnotation) String

func (ta TypeAnnotation) String() string

func (TypeAnnotation) StringSubtype

func (ta TypeAnnotation) StringSubtype(sub string) string

type UnsupportedValueError

type UnsupportedValueError struct {
	Str string
}

An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Error implements [[error]]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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