dratini0  committed aa00894

Finally done the YAML side of the things. Also simplified the parse for TAG_Int_Array.

  • Participants
  • Parent commits df97584

Comments (0)

Files changed (2)

File nbt2yaml/

         element_type = TAG_Int
         length = self._parse_length(TAG_Int, stream)
-        return (element_type, [
+        return [
             element_type._parse_impl(stream) for i in xrange(length)
-        ])
+        ]
     def _dump_impl(self, data, stream):
-        element_type, data = data
-        # element_type.to_stream(stream)
         self._dump_length(TAG_Int, len(data), stream)
         for elem in data:
-            element_type._dump_impl(elem, stream)
+            TAG_Int._dump_impl(elem, stream)
 TAG_End = EndTag('end', 0)
 TAG_Byte = FixedTag('byte', 1, 1, 'b')

File nbt2yaml/

 class ForceListOfType(ForceType):
+class ForceIntArray(ForceType):
+    pass
 def _type_representer(dumper, struct):
     if struct.type is parse.TAG_Byte_Array:
         representation = struct.value
 def _collection_representer(dumper, struct):
     return dumper.represent_sequence(u'!list_%s' %, struct.value)
+def _int_array_representer(dumper, struct):
+    return dumper.represent_sequence(u'!int_array', struct.value)
 yaml.add_representer(ForceType, _type_representer)
 yaml.add_representer(ForceListOfType, _collection_representer)
+yaml.add_representer(ForceIntArray, _int_array_representer)
 def _type_constructor(type_):
     def _constructor(loader, node):
         return ForceListOfType(type_, value)
     return _constructor
+def _int_array_constructor(loader, node):
+    value = loader.construct_sequence(node)
+    return ForceIntArray(parse.TAG_Int_Array, value)
 for type_ in _explicit_types:
     yaml.add_constructor(u'!%s' %, _type_constructor(type_))
 for type_ in _all_types:
     yaml.add_constructor(u'!list_%s' %, _list_constructor(type_))
+yaml.add_constructor(u'!int_array', _int_array_constructor)
 def _yaml_serialize(struct):
     tag, name, data = struct.type,,
     name = name.encode('utf-8')
     elif type_ is parse.TAG_List:
         element_type, data = value
         return ForceListOfType(element_type, [_value_as_yaml(element_type, d) for d in data])
+    elif type_ is parse.TAG_Int_Array:
+        return ForceIntArray(parse.TAG_Int, value)
         return value
     elif type_ is parse.TAG_List:
         ltype = value.type
         return (ltype, [_yaml_as_value(ltype, s) for s in value.value])
+    elif type_ is parse.TAG_Int_Array:
+        return value.value
         return value
 def _type_from_yaml(data):
     if isinstance(data, ForceListOfType):
         return parse.TAG_List
+    elif isinstance(data, ForceIntArray):
+        return parse.TAG_Int_Array
     elif isinstance(data, list):
         assert data and isinstance(data[0], dict)
         return parse.TAG_Compound