-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
static dynamic readValue(data) {
if (data is! BinaryData) {
return data;
}
if (data.isNullPtr) {
return null;
}
if (data.type.name.startsWith("char") && data.type.name != "char") {
return readNativeString(data);
} else {
var v = data.value;
if (v is List) {
v = v.map(readValue).toList();
} else if (v is Map) {
var out = {};
for (var k in v.keys) {
out[k] = readValue(v[k]);
}
return out;
}
return v;
}
}What is a puprose of dynamic readValue(data)?
In C langauge impossible to determine is data string or not.
char *str = "Hello";
char ca[512];
char *bytes = ca;char *str are string or not?
char *bytes are string or not?
Aslo this may not work.
if (data.type.name.startsWith("char") && data.type.name != "char") {This should work
helper.declare("typedef char SYMBOL;");
helper.declare("typedef SYMBOL MY_CHAR;");
print(types["MY_CHAR"].compatible(types["char"], true));I ask because once I planned add the support of binary wrappers and binary readers.
Eg.
typedef struct foo {
int i;
char *s;
} Foo;class Foo {
int i;
String s;
} With binary readers plain old Dart object (PODO) Foo can be filled (hydrated) from the typedef struct foo Foo without a requirements to implementing additional fillers.
var foo = reader.read(binaryData, Foo); // "Foo" is instance of "RuntimeType"
sendToEndUser(foo);Of course, with a reflection but not so slow (because information about the requested (to read) runtime types (PODO) are cached).
Binary wrappers allows work slightly easier with C structs (binary data).
Metadata
Metadata
Assignees
Labels
No labels