src/tagforge

Search:
Group by:
Source   Edit  

Types

TagFormat = enum
  BE, LE
The fornat for parsing/dumping NBT Source   Edit  
TagNode {.acyclic.} = ref object
  case kind*: TagNodeKind
  of End:
      nil

  of Byte:
      byteVal*: int8

  of Short:
      shortVal*: int16

  of Int:
      intVal*: int32

  of Long:
      longVal*: int64

  of Float:
      floatVal*: float32

  of Double:
      doubleVal*: float64

  of ByteArray:
      byteArrVal*: seq[int8]

  of String:
      strVal*: string

  of List:
      typ*: TagNodeKind
      listVal*: seq[TagNode]

  of Compound:
      compoundVal*: Table[string, TagNode]

  of IntArray:
      intArrVal*: seq[int32]

  of LongArray:
      longArrVal*: seq[int64]

  
NBT node type Source   Edit  
TagNodeKind = enum
  End = 0, Byte = 1, Short = 2, Int = 3, Long = 4, Float = 5, Double = 6,
  ByteArray = 7, String = 8, List = 9, Compound = 10, IntArray = 11,
  LongArray = 12
NBT tags Source   Edit  
TagParsingError = object of ValueError
Source   Edit  
TagValidationError = object of ValueError
Source   Edit  

Procs

proc `$`(t: TagNode): string {....raises: [], tags: [], forbids: [].}
Converts Tag to a string for easier debugging/visualising Source   Edit  
func `==`(a, b: TagNode): bool {....raises: [Exception], tags: [RootEffect],
                                 forbids: [].}
Compares two tags Source   Edit  
func `[]`(node: TagNode; idx: int): TagNode {....raises: [TagValidationError],
    tags: [], forbids: [].}
Access a list tag Source   Edit  
func `[]`(node: TagNode; name: string): TagNode {.
    ...raises: [TagValidationError, KeyError], tags: [], forbids: [].}
Source   Edit  
func `[]=`(node: TagNode; idx: int; value: TagNode) {.
    ...raises: [TagValidationError], tags: [], forbids: [].}
Set a list tag Source   Edit  
func `[]=`(node: TagNode; name: string; value: TagNode) {.
    ...raises: [TagValidationError], tags: [], forbids: [].}
Set a named tag Source   Edit  
proc dumpNbt(s: TagNode; format = BE; network = true): string {.
    ...raises: [IOError, OSError, TagValidationError],
    tags: [WriteIOEffect, ReadIOEffect], forbids: [].}

Writes an NBT tag to a string.

format specifies the endianness of the data network specifies whether the data is sent over the network

Source   Edit  
func getByte(node: TagNode): int8 {....raises: [TagValidationError], tags: [],
                                    forbids: [].}
Get the byte value of a byte TagNode Source   Edit  
func getByteArray(node: TagNode): seq[int8] {....raises: [TagValidationError],
    tags: [], forbids: [].}
Get the byte array value of a byte array TagNode Source   Edit  
func getDouble(node: TagNode): float64 {....raises: [TagValidationError], tags: [],
    forbids: [].}
Get the double value of a double TagNode Source   Edit  
func getFloat(node: TagNode): float32 {....raises: [TagValidationError], tags: [],
                                        forbids: [].}
Get the float value of a float TagNode Source   Edit  
func getInt(node: TagNode): int32 {....raises: [TagValidationError], tags: [],
                                    forbids: [].}
Get the int value of an int TagNode Source   Edit  
func getIntArray(node: TagNode): seq[int32] {....raises: [TagValidationError],
    tags: [], forbids: [].}
Get the int array value of an int array TagNode Source   Edit  
func getLong(node: TagNode): int64 {....raises: [TagValidationError], tags: [],
                                     forbids: [].}
Get the long value of a long TagNode Source   Edit  
func getLongArray(node: TagNode): seq[int64] {....raises: [TagValidationError],
    tags: [], forbids: [].}
Get the long array value of a long array TagNode Source   Edit  
func getShort(node: TagNode): int16 {....raises: [TagValidationError], tags: [],
                                      forbids: [].}
Get the short value of a short TagNode Source   Edit  
func getString(node: TagNode): string {....raises: [TagValidationError], tags: [],
                                        forbids: [].}
Get the string value of a string TagNode Source   Edit  
func newTagByte(x: int8): TagNode {....raises: [], tags: [], forbids: [].}
Returns a byte TagNode with a signed byte as the value. Source   Edit  
func newTagByteArray(x = newSeq()): TagNode {....raises: [], tags: [], forbids: [].}
Returns a byte array TagNode with a seqint8 as the value. Source   Edit  
func newTagCompound(x = initTable()): TagNode {....raises: [], tags: [],
    forbids: [].}
Returns a compound TagNode with a Tablestring, TagNode as the value. Source   Edit  
func newTagDouble(x: float64): TagNode {....raises: [], tags: [], forbids: [].}
Returns a double TagNode with a double as the value. Source   Edit  
func newTagFloat(x: float32): TagNode {....raises: [], tags: [], forbids: [].}
Returns a float TagNode with a float as the value. Source   Edit  
func newTagInt(x: int32): TagNode {....raises: [], tags: [], forbids: [].}
Returns an int TagNode with a signed int as the value. Source   Edit  
func newTagIntArray(x = newSeq()): TagNode {....raises: [], tags: [], forbids: [].}
Returns an int array TagNode with a seqint32 as the value. Source   Edit  
func newTagList(typ: TagNodeKind; x = newSeq()): TagNode {.
    ...raises: [TagValidationError], tags: [], forbids: [].}
Returns a list TagNode with a seqTagNode as the value. Source   Edit  
func newTagLong(x: int64): TagNode {....raises: [], tags: [], forbids: [].}
Returns a long TagNode with a signed long as the value. Source   Edit  
func newTagLongArray(x = newSeq()): TagNode {....raises: [], tags: [], forbids: [].}
Returns a long array TagNode with a seqint64 as the value. Source   Edit  
func newTagShort(x: int16): TagNode {....raises: [], tags: [], forbids: [].}
Returns a short TagNode with a signed short as the value. Source   Edit  
func newTagString(x = ""): TagNode {....raises: [], tags: [], forbids: [].}
Returns a string TagNode with a string as the value. Source   Edit  
proc parseNbt(s: string; format = BE; network = false): TagNode {....raises: [
    TagValidationError, OSError, IOError, ModifiedUnicodeDecodeError, Exception],
    tags: [ReadIOEffect, RootEffect], forbids: [].}

Parses NBT data structure from the string s

format specifies the endianness of the data network specifies whether the data is sent over the network

Source   Edit  
proc toJson(s: TagNode): JsonNode {....raises: [], tags: [], forbids: [].}
Converts an NBT tag to the JSON for printing/serialization Source   Edit