diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 13:24:17 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 13:24:17 +0200 |
commit | 5a12f9e05c7cc608ba9685e50eabab21f7fc1f51 (patch) | |
tree | 5f0818ed492c80805c3df6c8fb4d1f46041583f7 | |
parent | e4f89ff0bbd93e355e4431264dee2b10b3ac27d1 (diff) | |
download | gonbt-5a12f9e05c7cc608ba9685e50eabab21f7fc1f51.tar.gz gonbt-5a12f9e05c7cc608ba9685e50eabab21f7fc1f51.tar.bz2 gonbt-5a12f9e05c7cc608ba9685e50eabab21f7fc1f51.zip |
Adding some documentation
-rw-r--r-- | nbt/compressed.go | 4 | ||||
-rw-r--r-- | nbt/nbt.go | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/nbt/compressed.go b/nbt/compressed.go index 3ca31f5..a16308f 100644 --- a/nbt/compressed.go +++ b/nbt/compressed.go @@ -8,6 +8,7 @@ import ( // Some helpers for reading / writing compressed NBT data, since NBT data is often compressed. +// ReadGzipdNamedTag reads a gzip compressed named tag. See ReadNamedTags for more info. func ReadGzipdNamedTag(r io.Reader) (Tag, string, error) { decomp, err := gzip.NewReader(r) if err != nil { @@ -17,11 +18,13 @@ func ReadGzipdNamedTag(r io.Reader) (Tag, string, error) { return ReadNamedTag(decomp) } +// WriteGzipdNamedTag writes a gzip compressed named tag. See WriteNamedTag for more info. func WriteGzipdNamedTag(w io.Writer, name string, tag Tag) error { comp := gzip.NewWriter(w) return WriteNamedTag(comp, name, tag) } +// ReadZlibdNamedTag reads a zlib compressed named tag. See ReadNamedTags for more info. func ReadZlibdNamedTag(r io.Reader) (Tag, string, error) { decomp, err := zlib.NewReader(r) if err != nil { @@ -31,6 +34,7 @@ func ReadZlibdNamedTag(r io.Reader) (Tag, string, error) { return ReadNamedTag(decomp) } +// WriteZlibdNamedTag writes a zlib compressed named tag. See WriteNamedTag for more info. func WriteZlibdNamedTag(w io.Writer, name string, tag Tag) error { comp := zlib.NewWriter(w) return WriteNamedTag(comp, name, tag) @@ -1,3 +1,4 @@ +// Package nbt provides functions for reading and writing NBT encoded data. package nbt import ( @@ -10,11 +11,27 @@ import ( "strconv" ) +// Tag holds the data of an NBT tag. Type is a TAG_* value. +// +// The type of Payload depends on Type: +// +// TAG_Byte -- byte +// TAG_Short -- int16 +// TAG_Int -- int32 +// TAG_Long -- int64 +// TAG_Float -- float32 +// TAG_Double -- float64 +// TAG_Byte_Array -- []byte +// TAG_String -- string +// TAG_List -- TagList +// TAG_Compound -- TagCompound +// TAG_Int_Array -- []int32 type Tag struct { Type TagType Payload interface{} } +// TagList is the payload of a TAG_List Tag. The type of the Elems depends on Type (see docu of Tag). type TagList struct { Type TagType Elems []interface{} @@ -65,6 +82,7 @@ func (t Tag) String() string { return s } +// TagCompund is the payload of a TAG_Compound. type TagCompound map[string]Tag func readTagData(r io.Reader, tt TagType) (interface{}, error) { @@ -176,6 +194,7 @@ func readTagData(r io.Reader, tt TagType) (interface{}, error) { return nil, errors.New("Unknown tag type") } +// ReadNamedTag reads a named Tag from an io.Reader. It returns the Tag, the tags Name and an error. func ReadNamedTag(r io.Reader) (Tag, string, error) { _tt, err := kagus.ReadByte(r) if err != nil { @@ -273,6 +292,7 @@ func writeTagData(w io.Writer, tt TagType, data interface{}) error { return errors.New("Unknown tage type") } +// WriteNamedTag writes a named Tag to an io.Writer. func WriteNamedTag(w io.Writer, name string, tag Tag) error { if err := writeByte(w, byte(tag.Type)); err != nil { return err |