Uploaded image for project: 'OpenVDB'
  1. OpenVDB
  2. OVDB-104

Limit Metadata Values to 31-bits

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • None
    • Core
    • None

      Suggested by JeffLait, use the extra bit to indicate that Metadata that only fits in 64-bits follows as a future-proof mechanism. 

      This the non-ABI portion of this work, which simply ensures that going forward Metadata can't be written out which exceeds 31-bits. If the Metadata does exceed this limit, drop it (though I envision we'll need to add some kind of error/warning mechanism too). I think this can be done at a MetaMap level, looking for feedback on this idea. Implementation would look something like:

      void
      MetaMap::writeMeta(std::ostream &os) const
      {
          // Write out the number of metadata items we have in the map. Note that we
          // save as Index32 to save a 32-bit number. Using size_t would be platform
          // dependent.
          Index32 count = static_cast<Index32>(metaCount());
      
          // Disable writing of any metadata that does not fit into 31-bits
          std::vector<int8_t> valid(size_t(count), int8_t(1));
          for (ConstMetaIterator iter = beginMeta(), int i = 0; iter != endMeta(); ++iter, ++i) {
              if (iter->second->size() >= math::Pow(2, 31) - 1) {
                  valid[i] = false;
                  count--;
              }
          }
      
          os.write(reinterpret_cast<char*>(&count), sizeof(Index32));
      
          // Iterate through each metadata and write it out.
          for (ConstMetaIterator iter = beginMeta(), int i = 0; iter != endMeta(); ++iter, ++i) {
              // Don't write out metadata that doesn't fit into 32-bits
              if (!valid[i])  continue;
      
              // Write the name of the metadata.
              writeString(os, iter->first);
      
              // Write the type name of the metadata.
              writeString(os, iter->second->typeName());
      
              // Write out the metadata value.
              iter->second->write(os);
          }
      }
      

       

       

            Unassigned Unassigned
            danrbailey danrbailey
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: