Composition.vala 1.0 KB

123456789101112131415161718192021222324252627
  1. using Invercargill;
  2. using InvercargillJson;
  3. namespace Binman {
  4. public Attempts<CompositionComponent> get_composition(string path = "/etc/composition") throws Error {
  5. return new JsonlInputStream(File.new_for_path(path).read())
  6. .as_property_groups()
  7. .try_map_with<CompositionComponent>(CompositionComponent.get_mapper());
  8. }
  9. public class CompositionComponent {
  10. public string name { get; set; }
  11. public BinaryData key { get; set; }
  12. public Vector<string> uris { get; set; }
  13. public static PropertyMapper<CompositionComponent> get_mapper() {
  14. return PropertyMapper.build_for<CompositionComponent>(cfg => cfg
  15. .map<string>("name", o => o.name, (o, v) => o.name = v)
  16. .map<string>("key", o => o.key.to_base64(), (o, v) => o.key = new BinaryData.from_base64(v))
  17. .map_many<string>("uris", o => o.uris, (o, v) => o.uris = v.to_vector())
  18. .set_constructor(() => new CompositionComponent())
  19. );
  20. }
  21. }
  22. }