int32 WriterImplBase::WritePackageAttributes( const PackageAttributeList& packageAttributes, uint32& _stringsLengthUncompressed) { // write the cached strings uint32 stringsCount = WriteCachedStrings(fPackageStringCache, 2); _stringsLengthUncompressed = DataWriter()->BytesWritten(); _WritePackageAttributes(packageAttributes); return stringsCount; }
int32 WriterImplBase::WritePackageAttributes( const PackageAttributeList& packageAttributes, uint32& _stringsLengthUncompressed) { // write the cached strings uint64 startOffset = fHeapWriter->UncompressedHeapSize(); uint32 stringsCount = WriteCachedStrings(fPackageStringCache, 2); _stringsLengthUncompressed = fHeapWriter->UncompressedHeapSize() - startOffset; _WritePackageAttributes(packageAttributes); return stringsCount; }
void WriterImplBase::_WritePackageAttributes( const PackageAttributeList& packageAttributes) { DoublyLinkedList<PackageAttribute>::ConstIterator it = packageAttributes.GetIterator(); while (PackageAttribute* attribute = it.Next()) { uint8 encoding = attribute->ApplicableEncoding(); // write tag WriteUnsignedLEB128(compose_attribute_tag( attribute->id, attribute->type, encoding, !attribute->children.IsEmpty())); // write value WriteAttributeValue(*attribute, encoding); if (!attribute->children.IsEmpty()) _WritePackageAttributes(attribute->children); } WriteUnsignedLEB128(0); }
status_t PackageWriter::_Finish() { // write entries for (EntryList::ConstIterator it = fRootEntry->ChildIterator(); Entry* entry = it.Next();) { _AddEntry(AT_FDCWD, entry, entry->Name()); } printf("header size: %lu\n", sizeof(hpkg_header)); printf("heap size: %lld\n", fHeapEnd - sizeof(hpkg_header)); hpkg_header header; // write the TOC and package attributes _WriteTOC(header); _WritePackageAttributes(header); off_t totalSize = fHeapEnd; printf("total size: %lld\n", totalSize); // prepare the header // general header.magic = B_HOST_TO_BENDIAN_INT32(B_HPKG_MAGIC); header.header_size = B_HOST_TO_BENDIAN_INT16( (uint16)sizeof(hpkg_header)); header.version = B_HOST_TO_BENDIAN_INT16(B_HPKG_VERSION); header.total_size = B_HOST_TO_BENDIAN_INT64(totalSize); // write the header _WriteBuffer(&header, sizeof(hpkg_header), 0); fFinished = true; return B_OK; }