code: def _writeblocks(cls, blocks, available, cont_size, padding_func):
          
  
          # write everything except padding
          data = bytearray()
          for block in blocks:
              if isinstance(block, Padding):
                  continue
              data += cls._writeblock(block)
          blockssize = len(data)
  
          # take the padding overhead into account. we always add one
          # to make things simple.
          padding_block = Padding()
          blockssize += len(cls._writeblock(padding_block))
  
          # finally add a padding block
          info = PaddingInfo(available - blockssize, cont_size)
          padding_block.length = min(info._get_padding(padding_func),
                                     cls._MAX_SIZE)
          data += cls._writeblock(padding_block, is_last=True)
  
          return data
docs: Render metadata block as a byte string.