Created
July 16, 2011 15:57
-
-
Save txdv/1086482 to your computer and use it in GitHub Desktop.
API example of my Manos BinaryStreamReader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace NiceParsing | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
var packetWrapper = new { | |
Length = 3, | |
Number = typeof(byte) | |
}; | |
var serverClientProto = new { | |
ProtocolVersion = typeof(byte), | |
ServerVersion = typeof(string), | |
/* ThreadId = typeof(short), | |
ScrambleBuffer = typeof(int), | |
Filler = typeof(byte), | |
ServerCapabilities = typeof(short), | |
ServerLanguage = typeof(byte), | |
ServerStatus = typeof(short), | |
ServerCapabilitiesUpper = typeof(short), | |
SecondFiller = 10,*/ | |
}; | |
Context context = Context.Create(); | |
var socket = context.CreateSocket(); | |
socket.Connect("127.0.0.1", 3306, delegate { | |
var br = new BinaryStreamReader(socket.GetSocketStream()); | |
br.Read(packetWrapper, delegate (dynamic data) { | |
Console.WriteLine ("Packet length: {0} number: {1}", data.Length, data.Number); | |
br.Read(serverClientProto, delegate (dynamic packet) { | |
Console.WriteLine (packet.ProtocolVersion); | |
Console.WriteLine (packet.ServerVersion); | |
}); | |
/* | |
br.Read(new { Data = data.Length[0] }, delegate (dynamic packet) { | |
Console.WriteLine(packet.Data); | |
}); | |
*/ | |
}); | |
}); | |
context.Start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment