I have the following (sample) binary template of nested structures:
typedef struct
{
int a;
int b;
int c;
} Vec <read=VecRead, write=VecWrite>;
string VecRead(Vec& v)
{
return Str("(%d, %d, %d)", v.a, v.b, v.c);
}
void VecWrite(Vec& v, string s)
{
SScanf(s, "(%d, %d, %d)", v.a, v.b, v.c);
}
typedef struct
{
Vec x;
Vec y;
} Mat <read=MatRead, write=MatWrite>;
string MatRead(Mat& m)
{
return Str("(%s, %s)", VecRead(m.x), VecRead(m.y));
}
void MatWrite(Mat& m, string s)
{
string x, y;
SScanf(s, "(%[^)]), %[^)]))", x, y); // ERROR (s. below)
VecWrite(m.x, x);
VecWrite(m.y, y);
}
// content of attached test file:
BigEndian();
Mat mat;
Mat includes two instances of Vec, and in the write function, I try to reuse the functionality of Vec just as I did in the read function.
However, it seems SScanf does not understand character classes to extract the Vec substrings %[^)] (read everything up to the next )). When trying to edit the value in 010, it will only print *ERROR: Argument 2 was an incompatible type for function ‘SScanf’.
Are character classes not supported in 010 or am I doing something wrong here?
(I’ve actually found the same usage in an older script that I should’ve tested thoroughly, so I wonder if this actually worked once and only broke in the latest v16.0.)
Attached a sample binary file together with the binary template for you to test:
sample.zip (577 Bytes)