Coder Social home page Coder Social logo

pigeon_map's Issues

draft

I use this ISSUE simply as a draft copy of posts I'm going to send elsewhere.

Support for missing NameSet entries

Alex, thanks for this extremely useful package, it is working very well right out of the box. I wanted to echo Andrés Viedma's comments from the Dart-Misc mailing list and ask if it would be easy for you to add support for missing fields in Pigeon Structs.

I'm not sure about Andrés but I would be alright with these fields deserializing into uninitialized null values. I took a quick try at hacking it in but I was unable to cope with all the downstream effects of my edits. During serialization, it would be preferable for me to have null struct fields disappear entirely, although your package may be doing this already, I have not tested.

The use case for me is with wrapper messages that can hold a number of different content types. My current workaround is to use a list for each field but If I need to store a large number of these structs as JSON, having all of these fields with no values will get expensive. However, if null fields disappear when serialized and non-existent fields are set as null during deserialization then my storage and transfer costs can be minimized.

The other workaround that comes to mind is using the standard dart library to deserialize the JSON into a map, check for existence, and then convert fields into PigeonStructs if they exist but then I'm paying for two parses.

Please let me know if that makes sense, I can provide an example, or if there's some easier approach you know of that I'm not seeing. Thanks again!

dart - mirrors

This is a notebook on dart mirrors

    print("location ${declaration.location} isClass=${declaration is ClassMirror}");
    if (declaration is ClassMirror) {
    
      if (declaration.simpleName.name == "X") {
        declaration.invoke(#staticMethod, []);
      }
    } else if (declaration is MethodMirror) { // for top-level functions
       if (declaration.simpleName == Symbol("foo")) {
         library.invoke(Symbol("foo"), []);
      }
    } 

extension SymbolNameExt on Symbol {
  String get name {
    var str = this.toString();
    if (!str.startsWith('Symbol("')) throw 'Weird symbol $str - BUG!';
    return str.substring(str.indexOf('"') + 1, str.lastIndexOf('"'));
  }
}

reading annotations

for (var meta in declaration.metadata) {
      if (meta.type == reflectClass(ExampleAnnotation)) {
        //print("simple name: ${declaration.simpleName.name}");
        //print(meta.getField(#value));
      }
    }
}

computing effective file name with a default directory

extension on Options {
  String get effectiveFileName {
    if (this.destinationFilePath != null) return this.destinationFilePath!;
    String scriptPath = Platform.script.toFilePath();
    String dirname = path.dirname(scriptPath);
    String mainFileName = path.basenameWithoutExtension(scriptPath);
    return '$dirname/$mainFileName.g.dart';
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.