Exemplo n.º 1
0
        /// <summary>
        /// Parses <see cref="GtidSet"/> from string representation.
        /// </summary>
        public static GtidSet Parse(string gtidSet)
        {
            if (gtidSet == null)
            {
                throw new ArgumentNullException(nameof(gtidSet));
            }

            if (gtidSet == "")
            {
                return(new GtidSet());
            }

            var uuidSets = gtidSet.Replace("\n", "")
                           .Split(',')
                           .Select(x => x.Trim())
                           .ToArray();

            var result = new GtidSet();

            foreach (var uuidSet in uuidSets)
            {
                int separatorIndex = uuidSet.IndexOf(':');
                var sourceId       = Uuid.Parse(uuidSet.Substring(0, separatorIndex));

                var      intervals = new List <Interval>();
                string[] ranges    = uuidSet.Substring(separatorIndex + 1).Split(':');

                foreach (var token in ranges)
                {
                    string[] range    = token.Split('-');
                    var      interval = range.Length switch
                    {
                        1 => new Interval(long.Parse(range[0]), long.Parse(range[0])),
                        2 => new Interval(long.Parse(range[0]), long.Parse(range[1])),
                        _ => throw new FormatException($"Invalid interval format {token}")
                    };
                    intervals.Add(interval);
                }

                result.UuidSets[sourceId] = new UuidSet(sourceId, intervals);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses <see cref="PreviousGtidsEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            long uuidSetNumber = reader.ReadInt64LittleEndian();
            var  gtidSet       = new GtidSet();

            for (long i = 0; i < uuidSetNumber; i++)
            {
                var sourceId = new Uuid(reader.ReadByteArraySlow(16));
                var uuidSet  = new UuidSet(sourceId, new List <Interval>());

                long intervalNumber = reader.ReadInt64LittleEndian();
                for (long y = 0; y < intervalNumber; y++)
                {
                    long start = reader.ReadInt64LittleEndian();
                    long end   = reader.ReadInt64LittleEndian();
                    uuidSet.Intervals.Add(new Interval(start, end));
                }
                gtidSet.UuidSets[sourceId] = uuidSet;
            }

            return(new PreviousGtidsEvent(header, gtidSet));
        }