Skip to content

Instantly share code, notes, and snippets.

@MichelDiz
Created October 26, 2019 03:57
Show Gist options
  • Save MichelDiz/9af4e74f2a8c83cdb592257678e1cf71 to your computer and use it in GitHub Desktop.
Save MichelDiz/9af4e74f2a8c83cdb592257678e1cf71 to your computer and use it in GitHub Desktop.
// To parse this JSON data, do
//
// final stateResponse = stateResponseFromJson(jsonString);
import 'dart:convert';
StateResponse stateResponseFromJson(String str) => StateResponse.fromJson(json.decode(str));
String stateResponseToJson(StateResponse data) => json.encode(data.toJson());
class StateResponse {
String counter;
Map<String, Group> groups;
Map<String, Zero> zeros;
String maxLeaseId;
String maxTxnTs;
String maxRaftId;
String cid;
License license;
StateResponse({
this.counter,
this.groups,
this.zeros,
this.maxLeaseId,
this.maxTxnTs,
this.maxRaftId,
this.cid,
this.license,
});
factory StateResponse.fromJson(Map<String, dynamic> json) => StateResponse(
counter: json["counter"] == null ? null : json["counter"],
groups: json["groups"] == null ? null : Map.from(json["groups"]).map((k, v) => MapEntry<String, Group>(k, Group.fromJson(v))),
zeros: json["zeros"] == null ? null : Map.from(json["zeros"]).map((k, v) => MapEntry<String, Zero>(k, Zero.fromJson(v))),
maxLeaseId: json["maxLeaseId"] == null ? null : json["maxLeaseId"],
maxTxnTs: json["maxTxnTs"] == null ? null : json["maxTxnTs"],
maxRaftId: json["maxRaftId"] == null ? null : json["maxRaftId"],
cid: json["cid"] == null ? null : json["cid"],
license: json["license"] == null ? null : License.fromJson(json["license"]),
);
Map<String, dynamic> toJson() => {
"counter": counter == null ? null : counter,
"groups": groups == null ? null : Map.from(groups).map((k, v) => MapEntry<String, dynamic>(k, v.toJson())),
"zeros": zeros == null ? null : Map.from(zeros).map((k, v) => MapEntry<String, dynamic>(k, v.toJson())),
"maxLeaseId": maxLeaseId == null ? null : maxLeaseId,
"maxTxnTs": maxTxnTs == null ? null : maxTxnTs,
"maxRaftId": maxRaftId == null ? null : maxRaftId,
"cid": cid == null ? null : cid,
"license": license == null ? null : license.toJson(),
};
}
class Group {
Map<String, Member> members;
Map<String, Tablet> tablets;
String checksum;
Group({
this.members,
this.tablets,
this.checksum,
});
factory Group.fromJson(Map<String, dynamic> json) => Group(
members: json["members"] == null ? null : Map.from(json["members"]).map((k, v) => MapEntry<String, Member>(k, Member.fromJson(v))),
tablets: json["tablets"] == null ? null : Map.from(json["tablets"]).map((k, v) => MapEntry<String, Tablet>(k, Tablet.fromJson(v))),
checksum: json["checksum"] == null ? null : json["checksum"],
);
Map<String, dynamic> toJson() => {
"members": members == null ? null : Map.from(members).map((k, v) => MapEntry<String, dynamic>(k, v.toJson())),
"tablets": tablets == null ? null : Map.from(tablets).map((k, v) => MapEntry<String, dynamic>(k, v.toJson())),
"checksum": checksum == null ? null : checksum,
};
}
class Member {
String id;
int groupId;
String addr;
bool leader;
String lastUpdate;
Member({
this.id,
this.groupId,
this.addr,
this.leader,
this.lastUpdate,
});
factory Member.fromJson(Map<String, dynamic> json) => Member(
id: json["id"] == null ? null : json["id"],
groupId: json["groupId"] == null ? null : json["groupId"],
addr: json["addr"] == null ? null : json["addr"],
leader: json["leader"] == null ? null : json["leader"],
lastUpdate: json["lastUpdate"] == null ? null : json["lastUpdate"],
);
Map<String, dynamic> toJson() => {
"id": id == null ? null : id,
"groupId": groupId == null ? null : groupId,
"addr": addr == null ? null : addr,
"leader": leader == null ? null : leader,
"lastUpdate": lastUpdate == null ? null : lastUpdate,
};
}
class Tablet {
int groupId;
String predicate;
Tablet({
this.groupId,
this.predicate,
});
factory Tablet.fromJson(Map<String, dynamic> json) => Tablet(
groupId: json["groupId"] == null ? null : json["groupId"],
predicate: json["predicate"] == null ? null : json["predicate"],
);
Map<String, dynamic> toJson() => {
"groupId": groupId == null ? null : groupId,
"predicate": predicate == null ? null : predicate,
};
}
class License {
String maxNodes;
String expiryTs;
bool enabled;
License({
this.maxNodes,
this.expiryTs,
this.enabled,
});
factory License.fromJson(Map<String, dynamic> json) => License(
maxNodes: json["maxNodes"] == null ? null : json["maxNodes"],
expiryTs: json["expiryTs"] == null ? null : json["expiryTs"],
enabled: json["enabled"] == null ? null : json["enabled"],
);
Map<String, dynamic> toJson() => {
"maxNodes": maxNodes == null ? null : maxNodes,
"expiryTs": expiryTs == null ? null : expiryTs,
"enabled": enabled == null ? null : enabled,
};
}
class Zero {
String id;
String addr;
bool leader;
Zero({
this.id,
this.addr,
this.leader,
});
factory Zero.fromJson(Map<String, dynamic> json) => Zero(
id: json["id"] == null ? null : json["id"],
addr: json["addr"] == null ? null : json["addr"],
leader: json["leader"] == null ? null : json["leader"],
);
Map<String, dynamic> toJson() => {
"id": id == null ? null : id,
"addr": addr == null ? null : addr,
"leader": leader == null ? null : leader,
};
}
{
"counter": "28",
"groups": {
"1": {
"members": {
"1": {
"id": "1",
"groupId": 1,
"addr": "localhost:7080",
"leader": true,
"lastUpdate": "1571974234"
}
},
"tablets": {
"1": {
"groupId": 1,
"predicate": "dgraph.type"
},
"2": {
"groupId": 2,
"predicate": "friend"
},
"3": {
"groupId": 1,
"predicate": "jobTitle"
},
"4": {
"groupId": 1,
"predicate": "name"
},
"5": {
"groupId": 1,
"predicate": "studied_at"
},
"6": {
"groupId": 1,
"predicate": "telephone"
},
"7": {
"groupId": 1,
"predicate": "url"
}
},
"checksum": "17709726534649136500"
},
"2": {
"members": {
"2": {
"id": "2",
"groupId": 2,
"addr": "localhost:7081",
"leader": true,
"lastUpdate": "1571974234"
}
},
"tablets": {
"1": {
"groupId": 2,
"predicate": "uri"
}
},
"checksum": "11160318154034397263"
},
"3": {
"members": {
"3": {
"id": "3",
"groupId": 3,
"addr": "localhost:7082",
"leader": true,
"lastUpdate": "1571974236"
}
},
"tablets": {
"1": {
"groupId": 1,
"predicate": "dgraph.type"
}},
"checksum": "11160318154034397263"
},
"4": {
"members": {
"4": {
"id": "4",
"groupId": 4,
"addr": "localhost:7083",
"leader": true,
"lastUpdate": "1571974265"
}
},
"checksum": "11160318154034397263"
},
"5": {
"members": {
"5": {
"id": "5",
"groupId": 5,
"addr": "localhost:7084",
"leader": true,
"lastUpdate": "1571974267"
}
},
"checksum": "11160318154034397263"
},
"6": {
"members": {
"6": {
"id": "6",
"groupId": 6,
"addr": "localhost:7085",
"leader": true,
"lastUpdate": "1571974271"
}
},
"checksum": "11160318154034397263"
}
},
"zeros": {
"1": {
"id": "1",
"addr": "localhost:5080",
"leader": true
},
"2": {
"id": "2",
"addr": "localhost:5081"
},
"3": {
"id": "3",
"addr": "localhost:5082"
}
},
"maxLeaseId": "10000",
"maxTxnTs": "10000",
"maxRaftId": "6",
"cid": "54109e30-74bb-4a1c-abc8-6017c9ce15d1",
"license": {
"maxNodes": "18446744073709551615",
"expiryTs": "1574566235",
"enabled": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment