|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
SweetScape KnowledgebaseKB1014: Can templates jump around a file? (i.e. process data out of order)
Yes, templates can read data in any order from a file. Typically, when template variables are defined they are read sequentially from a file. For example: int a; // read from bytes 0..3 int b; // read from bytes 4..7 int c; // read from bytes 8..11 010 Editor keeps track of the current read position and the position can be modified by using the 'FSeek' function. For example, the following template reads data out of order: FSeek( 12 ); int d; // read from bytes 12..15 FSeek( 4 ); int e; // read from bytes 4..7 FSeek( 0 ); int f; // read from bytes 0..3 The 'FTell' function can be used to query the current read position (the read position is updated after every template variable is defined). The current read position can be stored in a local variable if you want to jump to a position and then jump back. For example: int addr; // read an address from a file local int64 pos = FTell(); // record current read position FSeek( addr ); // jump to the address int g; // variable read starting from addr FSeek( pos ); // jump back to original read position The 'FSkip' function can also be used to change the current read position. 'FSkip' moves the read position by a relative number of bytes - i.e. 'FSkip(4);' is equivalent to 'FSeek( FTell() + 4 );'. Use 'FSkip' to jump over bytes you would like to ignore. For example: FSeek( 12 ); int h; // read from bytes 12..15 FSkip( 4 ); // skip the next 4 bytes int i; // read from bytes 20..23 'FSkip' also accepts negative numbers to move the read position backwards. |
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
|