static void Main(string[] args) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); while (true) { try { Console.InputEncoding = System.Text.Encoding.GetEncoding(1200); Console.OutputEncoding = System.Text.Encoding.GetEncoding(1200); Console.WindowWidth = Console.LargestWindowWidth; Console.SetIn(new StreamReader(Console.OpenStandardInput(32768), Console.InputEncoding, false, 32768)); Console.WriteLine("Bit string:\n"); var inputs = Console.ReadLine(); var input = ParseBitString(inputs); Console.Write($"{Environment.NewLine}___________________{Environment.NewLine}"); DrawImageInConsole(input, 4); Console.Write($"{Environment.NewLine}___________________{Environment.NewLine}"); var decodedSymbol = new QRSymbol(input); Console.Write($"{Environment.NewLine}___________________{Environment.NewLine}"); Console.WriteLine($"Symbol deconstruction: SUCCESS{Environment.NewLine}"); Console.WriteLine($"Version: {decodedSymbol.VersionInfo.Version}"); Console.WriteLine($"Mask: {decodedSymbol.FormatInfo.Mask}"); Console.WriteLine($"EC Level: {decodedSymbol.FormatInfo.ErrorCorrectionLevel}"); Console.WriteLine(); Console.WriteLine("Data segments:"); var segments = SegmentDecoder.DecodeAllSegments(decodedSymbol); PrintSegments(segments); } catch (Exception e) { Console.WriteLine(e.Message); } Console.Write($"{Environment.NewLine}___________________{Environment.NewLine}"); } }
/// <summary> /// Decodes all segments in <paramref name="bitArray"/> /// until an unknown or a terminator segment is encountered or the end is reached /// </summary> /// <param name="bitArray">Span of bits to be decoded</param> /// <param name="codeVersion">QR Code version from 1 to 40</param> /// <returns>List of successfully decoded segments</returns> public static List <Segment> DecodeAllSegments(QRSymbol symbol) { var bitArray = symbol.Data; List <Segment> segments = new List <Segment>(); while (TryDecodeFirstSegment(bitArray.Span, symbol.VersionInfo.Version, out Segment segment, out int bitsRead)) { segments.Add(segment); bitArray = bitArray.Slice(bitsRead); if (segment.Mode == SegmentMode.Terminator) { break; } } return(segments); }