-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbinaryprocess.cs
42 lines (40 loc) · 1.18 KB
/
binaryprocess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.IO;
public class BinaryProcess
{
public static void Main(string[] args)
{
if(args[0] == "-consume")
{
using(Stream inputStream = Console.OpenStandardInput())
{
for(byte counter = 0; counter < 255; counter++)
{
byte received = (byte) inputStream.ReadByte();
if(received != counter)
{
Console.WriteLine(
"Got an invalid byte: {0}, expected {1}.",
received, counter);
return;
}
else
{
Console.WriteLine(
"Properly received byte: {0}.", received, counter);
}
}
}
}
if(args[0] == "-emit")
{
using(Stream outputStream = Console.OpenStandardOutput())
{
for(byte counter = 0; counter < 255; counter++)
{
outputStream.WriteByte(counter);
}
}
}
}
}