private static PyTuple CreateHeader(PyToken type, PyTuple args) { if (args == null) { args = new PyTuple(); } PyTuple head = new PyTuple(); head.Items.Add(type); head.Items.Add(args); return(head); }
public PyObject Encode() { PyTuple args = new PyTuple(); // Command args.Items.Add(new PyInt((int)type)); // Source args.Items.Add(source.Encode()); // Dest args.Items.Add(dest.Encode()); // unknown if (userID == 0) { args.Items.Add(new PyNone()); } else { args.Items.Add(new PyInt((int)userID)); } // Add call args( payload ) args.Items.Add(payload); // Named arguments if (named_payload == null) { args.Items.Add(new PyNone()); } else { args.Items.Add(named_payload); } return(new PyObjectData(type_string, args)); }
private static string PrintTuple(PyTuple tuple) { return("[PyTuple " + tuple.Items.Count + " items]"); }
public bool Decode(PyObject data) { PyObject packet = data; if (packet.Type == PyObjectType.ChecksumedStream) { packet = packet.As <PyChecksumedStream>().Data; } if (packet.Type == PyObjectType.SubStream) { packet = packet.As <PySubStream>().Data; } if (packet.Type != PyObjectType.ObjectData) { return(false); } PyObjectData packeto = packet.As <PyObjectData>(); type_string = packeto.Name; if (packeto.Arguments.Type != PyObjectType.Tuple) { return(false); } PyTuple tuple = packeto.Arguments.As <PyTuple>(); if (tuple.Items.Count != 6) { return(false); } if ((tuple.Items[0].Type != PyObjectType.IntegerVar) && (tuple.Items[0].Type != PyObjectType.Long)) { return(false); } PyInt typer = tuple.Items[0].As <PyInt>(); type = (Macho.MachoNetMsg_Type)typer.Value; if (!source.Decode(tuple.Items[1])) { return(false); } if (!dest.Decode(tuple.Items[2])) { return(false); } if ((tuple.Items[3].Type == PyObjectType.IntegerVar) || (tuple.Items[3].Type == PyObjectType.Long)) { userID = (uint)tuple.Items[3].As <PyInt>().Value; } else if (tuple.Items[3].Type == PyObjectType.None) { userID = 0; } else { return(false); } // Payload( or call arguments ) if ((tuple.Items[4].Type != PyObjectType.Buffer) && (tuple.Items[4].Type != PyObjectType.Tuple)) { return(false); } payload = tuple.Items[4].As <PyTuple>(); if (tuple.Items[5].Type == PyObjectType.None) { named_payload = new PyDict(); } else if (tuple.Items[5].Type == PyObjectType.Dict) { named_payload = tuple.Items[5].As <PyDict>(); } else { return(false); } return(true); }
/* From client/script/common/net/machonet.py line: 3864(very old client source) * Client = ('clientID', 'callID', 'service') * Broadcast = ('broadcastID', 'narrowcast', 'idtype') * Node = ('nodeID', 'service', 'callID') * Any = ('service', 'callID') */ public PyObject Encode() { PyTuple t = new PyTuple(); switch (type) { case AddrType.Any: t.Items.Add(new PyString("A")); if (service == "") { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyString(service)); } if (typeID == 0) { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyLongLong((long)typeID)); } break; case AddrType.Node: t.Items.Add(new PyString("N")); t.Items.Add(new PyLongLong((long)typeID)); if (service == "") { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyString(service)); } if (callID == 0) { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyLongLong((long)callID)); } break; case AddrType.Client: t.Items.Add(new PyString("C")); t.Items.Add(new PyLongLong((long)typeID)); t.Items.Add(new PyLongLong((long)callID)); if (service == "") { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyString(service)); } break; case AddrType.Broadcast: t.Items.Add(new PyString("B")); if (service == "") { t.Items.Add(new PyNone()); } else { t.Items.Add(new PyString(service)); } t.Items.Add(new PyList()); t.Items.Add(new PyString(bcast_type)); break; default: break; } return(new PyObjectData("macho.MachoAddress", t)); }
public bool Decode(PyObject from) { if (from.Type != PyObjectType.ObjectData) { return(false); } PyObjectData obj = from.As <PyObjectData>(); if (obj.Name != "macho.MachoAddress") { return(false); } if (obj.Arguments.Type != PyObjectType.Tuple) { return(false); } PyTuple args = obj.Arguments.As <PyTuple>(); if (args.Items.Count < 3) { return(false); } if (args.Items[0].Type != PyObjectType.String) { return(false); } PyString typei = args.Items[0].As <PyString>(); switch (typei.Value) { case "A": if (args.Items.Count != 3) { return(false); } if (!DecodeService(args.Items[1]) || !DecodeCallID(args.Items[2])) { return(false); } type = AddrType.Any; break; case "N": if (args.Items.Count != 4) { return(false); } if (!DecodeTypeID(args.Items[1]) || !DecodeService(args.Items[2]) || !DecodeCallID(args.Items[3])) { return(false); } type = AddrType.Node; break; case "C": if (args.Items.Count != 4) { return(false); } if (!DecodeTypeID(args.Items[1]) || !DecodeCallID(args.Items[2]) || !DecodeService(args.Items[3])) { return(false); } type = AddrType.Client; break; case "B": if (args.Items.Count != 4) { return(false); } type = AddrType.Broadcast; if (args.Items[1].Type != PyObjectType.String) { return(false); } if (args.Items[3].Type != PyObjectType.String) { return(false); } PyString bid = args.Items[1].As <PyString>(); PyString idt = args.Items[3].As <PyString>(); service = bid.Value; bcast_type = idt.Value; break; default: return(false); } return(true); }
public PyObjectEx_Type1(PyToken type, PyTuple args) : base(false, CreateHeader(type, args)) { }