Skip to content

Don't use names of binary types. Use binary kinds instead #5

@mezoni

Description

@mezoni
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions