Skip to content

Instantly share code, notes, and snippets.

@txdv
Created July 16, 2011 15:57
Show Gist options
  • Save txdv/1086482 to your computer and use it in GitHub Desktop.
Save txdv/1086482 to your computer and use it in GitHub Desktop.
API example of my Manos BinaryStreamReader.
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