public static object ReadDescribed(ByteBuffer buffer, byte formatCode) { Fx.Assert(formatCode == FormatCode.Described, "Format code must be described (0)"); Described described; object descriptor = Encoder.ReadObject(buffer); CreateDescribed create = null; if ((create = (CreateDescribed)knownDescrided[descriptor]) == null) { object value = Encoder.ReadObject(buffer); described = new DescribedValue(descriptor, value); } else { described = create(); described.DecodeValue(buffer); } return(described); }
public void Send(Message message, int timeout) { Fx.AssertAndThrow(ErrorCode.SenderSendInvalidState, this.State < 0xff); this.client.Wait(o => ((Sender)o).credit == 0, this, 60000); lock (this) { if (this.credit < uint.MaxValue) { this.credit--; } } this.deliveryState = null; this.deliveryId = this.client.Send(this, message, timeout == 0); this.deliveryCount++; this.client.Wait(o => ((Sender)o).deliveryState == null, this, timeout); if (!object.Equals(this.deliveryState.Descriptor, 0x24ul)) { throw new Exception(this.deliveryState.Value.ToString()); } }
internal override void OnDisposition(uint first, uint last, DescribedValue state) { }
/// <summary> /// Reads a described value from a buffer. /// </summary> /// <param name="buffer">The buffer to read.</param> /// <param name="formatCode">The format code of the value.</param> public static object ReadDescribed(ByteBuffer buffer, byte formatCode) { Fx.Assert(formatCode == FormatCode.Described, "Format code must be described (0)"); Described described; object descriptor = Encoder.ReadObject(buffer); CreateDescribed create = null; if ((create = (CreateDescribed)knownDescrided[descriptor]) == null) { object value = Encoder.ReadObject(buffer); described = new DescribedValue(descriptor, value); } else { described = create(); described.DecodeValue(buffer); } return described; }
static void Main(string[] args) { //Create host and register message processor var uri = new Uri(Address); var host = new ContainerHost(new List<Uri>() { uri }, null, uri.UserInfo); host.RegisterMessageProcessor(MsgProcName, new MessageProcessor()); host.Open(); //Create client var connection = new Connection(new Address(Address)); var session = new Session(connection); var sender = new SenderLink(session, "message-client", MsgProcName); //Send message with an object of the base class as the body var person = new Person() { EyeColor = "brown", Height = 175, Weight = 75 }; SendMessage(sender, "Person", person); //Send message with an object of a derived class as the body var student = new Student() { GPA = 4.8, Address = new ListAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" } }; SendMessage(sender, "Person", student); //Send message with an object of a derived class as the body var teacher = new Teacher() { Department = "Computer Science", Classes = new List<string>() { "CS101", "CS106", "CS210" } }; SendMessage(sender, "Person", teacher); //Send message with nested simple map as the body var address = new InternationalAddress() { Address = new MapAddress() { Street = "123 Main St.", City = "Big Apple", State = "NY", Zip = "12345" }, Country = "usa" }; SendMessage(sender, "InternationalAddress", address); //Send message with an AMQP value (the described list form of a student) as the body var described = new DescribedValue( new Symbol("samples.amqpnetlite:student"), new List() { 80, 6, "black", 4.9, new DescribedValue( new Symbol("PeerToPeer.CustomType.ListAddress"), new List() { "123 Main St.", "Big Apple", "NY", "12345" } ) } ); SendMessage(sender, "Person", described); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map = new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } }; SendMessage(sender, "MapAddress", map); //Send message with an AMQP value (simple map of an InternationalAddress) as the body var map2 = new Map() { { "address", new Map() { { "street", "123 Main St." }, { "city", "Big Apple" }, { "state", "NY" }, { "zip", "12345" } } }, { "country", "usa" } }; SendMessage(sender, "InternationalAddress", map2); sender.Close(); session.Close(); connection.Close(); host.Close(); }
internal override void OnDisposition(uint first, uint last, DescribedValue deliveryState) { if (this.deliveryId >= first && this.deliveryId <= last) { this.deliveryState = deliveryState; } }
internal void SendDisposition(bool role, uint deliveryId, bool settled, DescribedValue state) { List disposition = new List() { role, deliveryId, null, settled, state }; this.WriteFrame(0, 0, 0x15ul, disposition); Fx.DebugPrint(true, 0, "disposition", disposition, "role", "first", "last"); }
internal abstract void OnDisposition(uint first, uint last, DescribedValue state);