210 likes | 366 Vues
The BinX API. eDIKT project team May 2003 Ted Wen tedwen@nesc.ac.uk Robert Carroll robertc@nesc.ac.uk. Contents. Format of the BinX document The binary data file BinX data types Format of the dataBinX document BinX library API. A BinX document. Root element.
E N D
The BinX API eDIKT project team May 2003 Ted Wen tedwen@nesc.ac.uk Robert Carroll robertc@nesc.ac.uk
Contents • Format of the BinX document • The binary data file • BinX data types • Format of the dataBinX document • BinX library API
A BinX document Root element • <dataset byteOrder=“bigEndian”> • <definitions> • <defineType typeName=“myTyp”> • <arrayFixed> • <character-8/> • <dim indexTo=“9”/> • </arrayFixed> • </defineType> • </definitions> • <filesrc=“myfile.bin”> • <useType typeName=“myTyp”/> • <integer-32 varName=“X” /> • </file> • </dataset> Data class section Abstract data type Data instance section
The BinX document <?xml version=“1.0”?> <dataset xmlns=“http://schema.nesc.ac.uk/binx”> <file src=“binary.bin” byteOrder=“littleEndian”> <short-16/> <integer-32/> <ieeeDouble-64/> </file> </dataset>
Another BinX document … … <definitions> <defineType typeName="array"> <arrayFixed> <byte-8/> <dim indexTo="15"/> </arrayFixed> </defineType > </definitions> <file src=“binary.bin” byteOrder=“littleEndian”> <useType typeName=“array”/> </dataset>
The binary data file DataBinX <short-16>100</short-16> <integer-32>10000</integer-32> Binary Data 1100100 10011100010000 Hexadecimal 00 64 00 00 27 10
<byte-8> <character-8> <short-16> <integer-32> <longInteger-64> <unsignedShort-16> <unsignedInteger-32> <unsignedLongInteger-64> <ieeeFloat-32> <ieeeDouble-64> <ieeeExtended-80> <ieeeQuadruple-128> BxByte8 BxCharacter8 BxShort16 BxInteger32 BxLong64 BxUnsignedShort16 BxUnsignedInteger32 BxUnsignedLong64 BxFloat32 BxDouble64 BxExtended80 BxQuadruple128 Primitive data types
<struct> <union> <arrayFixed> <arrayVariable> <arrayStreamed> BxDataset BxUnion BxArrayFixed BxArrayVariable BxArrayStreamed Complex data types
User type definition <defineType typeName=“myStruct”> <struct> </struct> </defineType> <defineType typeName=“myArray”> <arrayFixed> </arrayFixed> </defineType> <defineType typeName=“myUnion”> <union> </union> </defineType>
Primate types in DataBinX <?xml version=“1.0”?> <dataset xmlns:bx=“http://schema.nesc.ac.uk/binx”> <file> <short-16>32</short-16> <integer-32>100</integer-32> <ieeeDouble-64>50.5</ieeeDouble-64> </file> </dataset>
Struct in DataBinX … … <struct> <unicodeCharacter-16>0</unicodeCharacter-16> <longInteger-64>1</longInteger-64> <unicodeCharacter-16>2</unicodeCharacter-16> <unsignedInteger-32>3</unsignedInteger-32> <ieeeDouble-64>4</ieeeDouble-64> <short-16>5</short-16> <longInteger-64>6</longInteger-64> <ieeeExtended-80>7</ieeeExtended-80> <unicodeCharacter-32>8</unicodeCharacter-32> <ieeeExtended-80>9</ieeeExtended-80> </struct>
Array in DataBinX <arraydata> <dim index=“1” name=“i”> <dim index=“0” name=“j”> <byte-8>1</byte-8></dim> <dim index=“0” name=“j”> <byte-8>2</byte-8></dim> </dim> <dim index=“1” name=“i”> <dim index=“0” name=“j”> <byte-8>3</byte-8></dim> <dim index=“0” name=“j”> <byte-8>4</byte-8></dim> </dim> </arraydata> <arrayFixed> <byte-8/> <dim name=“j” indexTo=“1”/> <dim name=“i” indexTo=“1”/> </arrayFixed>
Parsing a BinX document BxBinxFile* pReader = new BxBinxFile(); If (pReader->parse(“mybinx.xml”)) { BxDataset* pDataset = pReader->getDataset(); }
Output from the library • DataBinX The combined data and BinX document • SchemaBinX • Binary data stream DataBinX = SchemaBinX + Binary data
Creating BinX document BxBinxFileWriter* pWriter=new BxBinxFileWriter(); • Create a object to write out the document BxDataset* pData = new BxDataset(); • Create a new dataset (in memory BinX document) BxShort16* i16 = new BxShort16(100); pData->addDataObject(i16); • Add data to the dataset
Creating BinX document BxBinaryFile* pbf = new BxBinaryFile(); • Create a new binary file pbf->setDatasetPointer(pData); • Create a link to the BinX document pWriter->setBinaryFilePtr(pbf); pWriter->save("TestDataset.xml"); • Save the BinX document
Merge binary data BxBinxFileReader * pFile1 = new BxBinxFileReader(“file1.xml”); BxBinxFileReader * pFile2 = new BxBinxFileReader(“file2.xml”); BxDataset * pDataset1 = pFile1->getDataset(); BxDataset * pDataset2 = pFile2->getDataset(); BxArray * pArray1 = pDataset1->getArray(0); BxArray * pArray2 = pDataset2->getArray(0); BxDataObject * pData1 = pArray1->getNext(); BxDataObject * pData2 = pArray2->getNext(); FILE * fo = fopen(“output.dat”,”wb”); pData1->toStreamBinary(fo); pData2->toStreamBinary(fo);
Summary • One BinX document can describe many binary files • Generate BinX document from code • Easy to use interfaces • Flexible