BinaryBlockWriter.kl

Types

BinaryBlockWriter (object)

バージョン 1.12.0 で追加.

The BinaryBlockWriter provides a block based hierarchical binary file writing layer on top of the lower level BinaryWriter object.

/*
** Example: BinaryBlockWriter
*/

require FileIO;
  
operator entry() {

      FilePath path = FilePath('${TEMP}/binaryBlockWriter.bin').expandEnvVars();
      {
        BinaryBlockWriter blockWriter(path.string());
        blockWriter.setNumBlocks(3);
      
        BinaryBlockWriter section1Writer = blockWriter.beginWriteBlock('section1');
      
        String text = "some text";
        SInt32 textLength = text.length();
      
        report('section1:' + text);
        section1Writer.write(textLength.data, textLength.dataSize);
        section1Writer.write(text.data, text.dataSize);
      
        BinaryBlockWriter section2Writer = blockWriter.beginWriteBlock('section2');
        Float64 floats[];
        floats.resize(10);
        for(SInt32 i=0;i<floats.size();i++)
          floats[i] = Float64(i) * 17 + 1;
        SInt32 floatsSize = floats.size();
      
        report('section2:' + floats);
        section2Writer.write(floatsSize.data, floatsSize.dataSize);
        section2Writer.write(floats.data, floats.dataSize);
      
      
        BinaryBlockWriter section3Writer = blockWriter.beginWriteBlock('section3', 3);
        BinaryBlockWriter section3subSection1Writer = section3Writer.beginWriteBlock('subSection1');
        SInt32 ints[];
        ints.resize(10);
        for(SInt32 i=0;i<ints.size();i++)
          ints[i] = SInt32(i) * 17 + 1;
        SInt32 intsSize = ints.size();
      
        report('section3:' + ints);
        section2Writer.write(intsSize.data, intsSize.dataSize);
        section2Writer.write(ints.data, ints.dataSize);
      
        BinaryBlockWriter section3subSection2Writer = section3Writer.beginWriteBlock('subSection2');
        BinaryBlockWriter section3subSection3Writer = section3Writer.beginWriteBlock('subSection3');
      
        report('Binary file written.');
      }
  
}

/*
** Output:
(stdin):21:9: error: must use parentheses to call methods
(stdin):21:9: error: must use parentheses to call methods
(stdin):22:9: error: must use parentheses to call methods
(stdin):22:9: error: must use parentheses to call methods
(stdin):32:9: error: must use parentheses to call methods
(stdin):32:9: error: must use parentheses to call methods
(stdin):33:9: error: must use parentheses to call methods
(stdin):33:9: error: must use parentheses to call methods
(stdin):45:9: error: must use parentheses to call methods
(stdin):45:9: error: must use parentheses to call methods
(stdin):46:9: error: must use parentheses to call methods
(stdin):46:9: error: must use parentheses to call methods


*/

Methods

  BinaryBlockWriter ( in BinaryBlockWriter other )
  BinaryBlockWriter ( in String filePath )
  BinaryBlockWriter ( out BinaryWriter writer )
  BinaryBlockWriter ( out BinaryWriter writer, in UInt32 numBlocks )
  BinaryBlockWriter ()
BinaryBlockWriter beginWriteBlock ! ( in String name )
BinaryBlockWriter beginWriteBlock ! ( in String name, in UInt32 numSubBlocks )
BinaryBlockWriter clone ? ()
  close ! ()
BinaryWriter getWriter ? ()
  setNumBlocks ! ( in UInt32 numBlocks )
  write ! ( in Data data, in UInt64 dataSize )
  ~BinaryBlockWriter ()