BinaryBlockReader (object)

バージョン 1.12.0 で追加.

The BinaryBlockReader provides a block based hierarchical binary file writing layer on top of the lower level BinaryReader object. It should be used to read files written using the BinaryBlockWriter.

BinaryBlockReader BinaryBlockReader BinaryBlockReader

/*
** Example: BinaryBlockReader
*/

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.');
  }
  
  if(path.exists())
  {
    BinaryBlockReader blockReader(path.string());
    report("blocks:" + blockReader.getBlockNames());
    // Now read the data back in in an arbitrary order. 
  
    BinaryBlockReader section3Reader = blockReader.beginReadBlock('section3');
    report("blocks:" + section3Reader.getBlockNames());
    BinaryBlockReader section3subSection1Reader = section3Reader.beginReadBlock('subSection1');
    SInt32 intsSize = 0;
    section3subSection1Reader.read(intsSize.data, intsSize.dataSize);
    SInt32 ints[];
    ints.resize(intsSize);
    section3subSection1Reader.read(ints.data, ints.dataSize);
  
    report('section3:' + ints);
  
    BinaryBlockReader section1Reader = blockReader.beginReadBlock('section1');
    SInt32 textLength;
    section1Reader.read(textLength.data, textLength.dataSize);
    String text = '';
    for(Size i=0;i<textLength;i++)
      text += ' ';
    section1Reader.read(text.data, text.dataSize);
    report('section1:' + text);
  
    BinaryBlockReader section2Reader = blockReader.beginReadBlock('section2');
  
    Float64 floats[];
    SInt32 floatsSize = 0;
    section2Reader.read(floatsSize.data, floatsSize.dataSize);
    floats.resize(0);
    floats.resize(floatsSize);
    section2Reader.read(floats.data, floats.dataSize);
    report('section2:' + floats);
  
    report('Binary file read.');
  }
  
}

/*
** 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
(stdin):64:5: error: must use parentheses to call methods
(stdin):64:5: error: must use parentheses to call methods
(stdin):67:5: error: must use parentheses to call methods
(stdin):67:5: error: must use parentheses to call methods
(stdin):73:5: error: must use parentheses to call methods
(stdin):73:5: error: must use parentheses to call methods
(stdin):77:5: error: must use parentheses to call methods
(stdin):77:5: error: must use parentheses to call methods
(stdin):84:5: error: must use parentheses to call methods
(stdin):84:5: error: must use parentheses to call methods
(stdin):87:5: error: must use parentheses to call methods
(stdin):87:5: error: must use parentheses to call methods


*/

Methods

  BinaryBlockReader ( in BinaryBlockReader other )
  BinaryBlockReader ( in String filePath )
  BinaryBlockReader ( out BinaryReader reader )
  BinaryBlockReader ()
BinaryBlockReader beginReadBlock ! ( in String name )
BinaryBlockReader clone ? ()
  close ! ()
String[] getBlockNames ? ()
UInt64 getNumBlocks ? ()
BinaryReader getReader ? ()
  read ! ( in Data data, in UInt64 dataSize )

Methods in detail

BinaryBlockReader ( in BinaryBlockReader other )

copy constructor


BinaryBlockReader ( in String filePath )

standard constructor from filePath


BinaryBlockReader ( out BinaryReader reader )

constructor taking an existing BinaryReader


BinaryBlockReader ()

default constructor


BinaryBlockReader BinaryBlockReader.beginReadBlock! ( in String name )

returns a new BinaryBlockReader which is initialized at the right place for a given block.


BinaryBlockReader BinaryBlockReader.clone? ()

clone method


BinaryBlockReader.close! ()

closes the BinaryBlockReader and releases the file handle


String[] BinaryBlockReader.getBlockNames? ()

returns all of the binary block names


UInt64 BinaryBlockReader.getNumBlocks? ()

returns the numbers of blocks this reader contains


BinaryReader BinaryBlockReader.getReader? ()

returns the wrapped BinaryReader


BinaryBlockReader.read! ( in Data data, in UInt64 dataSize )

reads all of the binary content of a block into a prepared array

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