def to_bytes(trait): out_stream = ABCFileOutputStream() out_stream.writeU30(trait.name) out_stream.writeU8(trait.kind) trait_type = trait.kind & 0x0f if trait_type in (TraitFactory.Trait_Slot, TraitFactory.Trait_Const): out_stream.writeU30(trait.slot_id) out_stream.writeU30(trait.type_name) out_stream.writeU30(trait.vindex) if trait.vindex != 0: out_stream.writeU8(trait.vkind) elif trait_type == TraitFactory.Trait_Class: out_stream.writeU30(trait.slot_id) out_stream.writeU30(trait.classi) elif trait_type == TraitFactory.Trait_Function: out_stream.writeU30(trait.slot_id) out_stream.writeU30(trait.function) elif trait_type in ( TraitFactory.Trait_Method, TraitFactory.Trait_Getter, TraitFactory.Trait_Setter): out_stream.writeU30(trait.disp_id) out_stream.writeU30(trait.method) if (trait.kind >> 4) & TraitFactory.ATTR_Metadata: count = len(trait.metadatas) out_stream.writeU30(count) for metadata in trait.metadatas: out_stream.writeU30(metadata) return out_stream.getvalue()
def to_bytes(instance): out_stream = ABCFileOutputStream() out_stream.writeU30(instance.name) out_stream.writeU30(instance.super_name) out_stream.writeU8(instance.flags) if instance.flags & StInstanceInfo.CONSTANT_ClassProtectedNs: out_stream.writeU30(instance.protectedNs) out_stream.writeU30(instance.intrf_count) for interf in instance.interfaces: out_stream.writeU30(interf) out_stream.writeU30(instance.iinit) # Trait out_stream.writeU30(instance.trait_count) for trait in instance.traits: trait_bytes = StTraitConverter.to_bytes(trait) out_stream.write(trait_bytes) return out_stream.getvalue()
def to_bytes(method_info): out_stream = ABCFileOutputStream() param_count = len(method_info.param_types) out_stream.writeU30(param_count) out_stream.writeU30(method_info.return_type) for param_type in method_info.param_types: out_stream.writeU30(param_type) out_stream.writeU30(method_info.name) out_stream.writeU8(method_info.flags) if method_info.flags & StMethodInfo.HAS_OPTIONAL: option_count = len(method_info.options) out_stream.writeU30(option_count) for option in method_info.options: out_stream.writeU30(option['val']) out_stream.writeU8(option['kind']) if method_info.flags & StMethodInfo.HAS_PARAM_NAMES: for param_name in method_info.param_names: out_stream.writeU30(param_name) return out_stream.getvalue()
def to_bytes(multiname): out_stream = ABCFileOutputStream() out_stream.writeU8(multiname.kind) if multiname.kind in (StMultiname.QName, StMultiname.QNameA): out_stream.writeU30(multiname.ns) out_stream.writeU30(multiname.name) elif multiname.kind in (StMultiname.RTQName, StMultiname.RTQNameA): out_stream.writeU30(multiname.name) elif multiname.kind in (StMultiname.RTQNameL, StMultiname.RTQNameLA): pass elif multiname.kind in (StMultiname.Multiname, StMultiname.MultinameA): out_stream.writeU30(multiname.name) out_stream.writeU30(multiname.ns_set) elif multiname.kind in (StMultiname.MultinameL, StMultiname.MultinameLA): out_stream.writeU30(multiname.ns_set) elif multiname.kind == StMultiname.TYPENAME: out_stream.writeU30(multiname.qname_index) params_length = len(multiname.params) out_stream.writeU30(params_length) for param in multiname.params: out_stream.writeU30(param) return out_stream.getvalue()
def to_bytes(pool): out_stream = ABCFileOutputStream() count = len(pool.integers) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for integer in pool.integers[1:]: out_stream.writeS32(integer) count = len(pool.uintegers) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for uinteger in pool.uintegers[1:]: out_stream.writeU32(uinteger) count = len(pool.doubles) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for d in pool.doubles[1:]: out_stream.writeD64(d) count = len(pool._strings) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for s in pool._strings[1:]: str_size = len(s) out_stream.writeU30(str_size) out_stream.write(s) count = len(pool._namespaces) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for kind, name in pool._namespaces[1:]: out_stream.writeU8(kind) out_stream.writeU30(name) count = len(pool._ns_sets) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for ns_set in pool._ns_sets[1:]: ns_count = len(ns_set) out_stream.writeU30(ns_count) for ns in ns_set: out_stream.writeU30(ns) count = len(pool._multinames) if count <= 1: out_stream.writeU30(0) else: out_stream.writeU30(count) for multiname in pool._multinames[1:]: m_bytes = MultinameConverter.to_bytes(multiname) out_stream.write(m_bytes) return out_stream.getvalue()