public void ProcessIncoming(int msecs) { int seq = transport.BeginRead(); try { int code = (byte)(Packers.Int8.unpack(transport)); ReplySlot slot; if (!replies.TryGetValue(seq, out slot) || (slot.type != ReplySlotType.SLOT_EMPTY && slot.type != ReplySlotType.SLOT_DISCARDED)) { throw new ProtocolError("invalid reply sequence: " + seq); } Packers.AbstractPacker packer = (Packers.AbstractPacker)slot.value; bool discard = (slot.type == ReplySlotType.SLOT_DISCARDED); switch (code) { case REPLY_SUCCESS: if (packer == null) { slot.value = null; } /*else if (packer == Packers.MockupPacker) { * slot.value = transport.ReadAll (); * }*/ else { slot.value = packer.unpack(transport); } slot.type = ReplySlotType.SLOT_VALUE; break; case REPLY_PROTOCOL_ERROR: throw (ProtocolError)loadProtocolError(); case REPLY_PACKED_EXCEPTION: slot.type = ReplySlotType.SLOT_EXCEPTION; slot.value = loadPackedException(); break; case REPLY_GENERIC_EXCEPTION: slot.type = ReplySlotType.SLOT_EXCEPTION; slot.value = loadGenericException(); break; default: throw new ProtocolError("unknown reply code: " + code); } if (discard) { replies.Remove(seq); } } finally { transport.EndRead(); } }
public int BeginCall(int funcid, Packers.AbstractPacker packer) { int seq = getSeq(); transport.BeginWrite(seq); Packers.Int8.pack(CMD_INVOKE, transport); Packers.Int32.pack(funcid, transport); replies[seq] = new ReplySlot(packer); return(seq); }
/// <summary> /// specialized version of Add that attempts to infer the packer for /// the key, but the packer for the value must be provided /// </summary> public void Add(Object key, Object value, Packers.AbstractPacker valpacker) { Packers.AbstractPacker keypacker = getPackerForBuiltinType(key); if (keypacker == null) { keypacker = getKeyPacker(key); } if (keypacker == null) { throw new ArgumentException("cannot deduce key packer, use 4-argument Add()"); } Add(key, keypacker, value, valpacker); }
/// <summary> /// a Version of Add that implements IDictionary.Add. It attempts to /// infer the packers for the key and for the value /// </summary> public void Add(Object key, Object value) { Packers.AbstractPacker keypacker = getPackerForBuiltinType(key); Packers.AbstractPacker valpacker = getPackerForBuiltinType(value); if (keypacker == null) { throw new ArgumentException("cannot deduce key packer " + key.GetType().ToString() + ", use 4-argument Add()"); } if (valpacker == null) { throw new ArgumentException("cannot deduce value packer " + value.GetType().ToString() + ", use 4-argument Add()"); } Add(key, keypacker, value, valpacker); }
/// <summary> /// Adds the given given value (with the given value-packer) under the /// given key (with the given key packer) /// </summary> /// <param name="key"> /// The key (any object) /// </param> /// <param name="keypacker"> /// The packer for the key (an AbstractPacker) /// </param> /// <param name="value"> /// The value (any object) /// </param> /// <param name="valpacker"> /// The packer for the value (an AbstractPacker) /// </param> public void Add(Object key, Packers.AbstractPacker keypacker, Object value, Packers.AbstractPacker valpacker) { //System.Console.Error.WriteLine("Add: {0}, {1}, {2}, {3}", key, keypacker, value, valpacker); if (keypacker == null || valpacker == null) { throw new ArgumentNullException("keypacker and valpacker cannot be null"); } FieldInfo fi = null; if (fields.TryGetValue(key, out fi)) { fi.keypacker = keypacker; fi.valpacker = valpacker; } else { fields.Add(key, new FieldInfo(keypacker, valpacker)); } data.Add(key, value); }
public FieldInfo(Packers.AbstractPacker keypacker, Packers.AbstractPacker valpacker) { this.keypacker = keypacker; this.valpacker = valpacker; }
public ReplySlot(Packers.AbstractPacker packer) { type = ReplySlotType.SLOT_EMPTY; value = packer; }