javascript - mirrors in dart not working for all elements -


i using reflection (aka dart:mirrors) in dart. first: code seen here works in dartium (with dart native) partially when compiled dart2js , run in chrome.

i have class called binaryreader reads class bytestream. here code (stripped repetitive part) so:

  void readobject(dynamic obj) {     var inst = reflect(obj);     inst.type.declarations.foreach((symbol name, declarationmirror decl) {       if(decl variablemirror) {         var variable = decl;         if(variable.metadata.length == 0) {           return;         }          instancemirror attrib = variable.metadata.first;         if(attrib.hasreflectee == false) {           return;         }          if(attrib.reflectee field) {           var field = attrib.reflectee field;           var value;           switch(field.type) {             case i8:                value = getint8();               break;              // ...              case v3:               value = new vector3(getfloat(), getfloat(), getfloat());               break;              default:               value = null;               break;           }            if(value == null) {             return;           }            inst.setfield(name, value);         }       }     });   } 

importing mirrors done following way:

import 'model/m4submesh.dart'; import 'model/m4model.dart'; import 'package:vector_math/vector_math.dart'; @mirrorsused(targets: const["m4submesh", "m4model", "vector_math"], override: '*') import 'dart:mirrors'; 

m4submesh , m4model library names of respective dart files. vector_math 1 of vector_math.dart

at first read instance of m4header part of m4model library stream. values correct, here looks like:

class m4header {   @field(ui32)   int signature;   @field(ui32)   int version;   @field(ui32)   int numsubmeshes;   @field(ui32)   int ofssubmeshes;   } 

then later try read m4submeshheader looks this:

class m4submeshheader {   @field(ui32)   int gridx, gridy, gridz;   @field(f32)   num blocksize;   @field(v3)   vector3 bboxmin, bboxmax; } 

after reading, blocksize has random value. bboxmin , bboxmax null. going wrong here?

greetings cromon

found solution! annotation applies first element in declaration list. above example expanded to:

class m4submeshheader {   @field(ui32)   int gridx;   int gridy;   int gridz;   @field(f32)   num blocksize;   @field(v3)   vector3 bboxmin;   vector3 bboxmax; } 

in opinion can considered error, ill have @ documentation , if not mentioned there report it. in end blocksize became value should have been assigned gridy made random. - honest - have take blame. 'bboxmin , bboxmax null', wrong, bboxmin wasnt null, had invalid values left line in code used bboxmax before print-ing thought allready broke @ bboxmin.

greetings cromon


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -