Ejemplo n.º 1
0
        private static byte[] DecodeThroughTextWriter(BinaryCodec codec, string inputData)
        {
            using (var memoryStream = new MemoryStream())
            {
                var random      = new Random(5);
                int inputOffset = 0;
                int inputLength = inputData.Length;

                using (var codecWriter = new BinaryDecoderWriter(codec, memoryStream))
                {
                    while (true)
                    {
                        int charsToProcess = (inputLength > 0) ? random.Next(1, inputLength) : 0;
                        if (charsToProcess == 0)
                        {
                            break;
                        }

                        codecWriter.Write(inputData.Substring(inputOffset, charsToProcess));
                        inputOffset += charsToProcess;
                        inputLength -= charsToProcess;
                    }

                    codecWriter.Flush();
                }

                return(memoryStream.ToArray());
            }
        }