/// <summary> /// Parses <see cref="GtidListEvent"/> from the buffer. /// </summary> public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader) { long gtidListLength = (uint)reader.ReadInt32LittleEndian(); var gtidList = new GtidList(); for (int i = 0; i < gtidListLength; i++) { long domainId = (uint)reader.ReadInt32LittleEndian(); long serverId = (uint)reader.ReadInt32LittleEndian(); long sequence = reader.ReadInt64LittleEndian(); gtidList.Gtids.Add(new Gtid(domainId, serverId, sequence)); } return(new GtidListEvent(header, gtidList)); }
/// <summary> /// Parses <see cref="GtidList"/> from string representation. /// </summary> public static GtidList Parse(string gtidList) { if (gtidList == null) { throw new ArgumentNullException(nameof(gtidList)); } if (gtidList == "") { return(new GtidList()); } var gtids = gtidList.Replace("\n", "") .Split(',') .Select(x => x.Trim()) .ToArray(); var domainMap = new HashSet <long>(); var result = new GtidList(); foreach (var gtid in gtids) { string[] components = gtid.Split('-'); long domainId = long.Parse(components[0]); long serverId = long.Parse(components[1]); long sequence = long.Parse(components[2]); if (domainMap.Contains(domainId)) { throw new FormatException("GtidList must consist of unique domain ids"); } else { domainMap.Add(domainId); } result.Gtids.Add(new Gtid(domainId, serverId, sequence)); } return(result); }