BinaryBlockReader.kl¶
Types¶
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.
/*
** 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: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
(stdin):64:9: error: must use parentheses to call methods
(stdin):64:9: error: must use parentheses to call methods
(stdin):67:9: error: must use parentheses to call methods
(stdin):67:9: error: must use parentheses to call methods
(stdin):73:9: error: must use parentheses to call methods
(stdin):73:9: error: must use parentheses to call methods
(stdin):77:9: error: must use parentheses to call methods
(stdin):77:9: error: must use parentheses to call methods
(stdin):84:9: error: must use parentheses to call methods
(stdin):84:9: error: must use parentheses to call methods
(stdin):87:9: error: must use parentheses to call methods
(stdin):87:9: 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 ) |