BinaryBlockWriter (object)

バージョン 1.12.0 で追加.

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

BinaryBlockWriter BinaryBlockWriter BinaryBlockWriter

/*
** 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:5: error: must use parentheses to call methods
(stdin):21:5: error: must use parentheses to call methods
(stdin):22:5: error: must use parentheses to call methods
(stdin):22:5: error: must use parentheses to call methods
(stdin):32:5: error: must use parentheses to call methods
(stdin):32:5: error: must use parentheses to call methods
(stdin):33:5: error: must use parentheses to call methods
(stdin):33:5: error: must use parentheses to call methods
(stdin):45:5: error: must use parentheses to call methods
(stdin):45:5: error: must use parentheses to call methods
(stdin):46:5: error: must use parentheses to call methods
(stdin):46:5: 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 ()

Methods in detail

BinaryBlockWriter ( in BinaryBlockWriter other )

copy constructor


BinaryBlockWriter ( in String filePath )

standard constructor given a filepath


BinaryBlockWriter ( out BinaryWriter writer )

constructor taking an existing BinaryWriter


BinaryBlockWriter ( out BinaryWriter writer, in UInt32 numBlocks )

constructor taking an existing BinaryWriter and the number of blocks to write


BinaryBlockWriter ()

default constructor


BinaryBlockWriter BinaryBlockWriter.beginWriteBlock! ( in String name )

An overload of the previous method, using 0 subblocks.


BinaryBlockWriter BinaryBlockWriter.beginWriteBlock! ( in String name, in UInt32 numSubBlocks )

starts writing of one named block with a given number of sub blocks.


BinaryBlockWriter BinaryBlockWriter.clone? ()

clone method


BinaryBlockWriter.close! ()

closes the wrapped BinaryWriter and releases the file handle


BinaryWriter BinaryBlockWriter.getWriter? ()

returns the wrapped BinaryWriter object


BinaryBlockWriter.setNumBlocks! ( in UInt32 numBlocks )

sets the number of blocks this writer will be able to store


BinaryBlockWriter.write! ( in Data data, in UInt64 dataSize )

writes an array into the block

data The data pointer of the array
dataSize The dataSize result of the array


~ BinaryBlockWriter ()

standard destructor