/// <summary> /// Initializes a message with an AmqpValue body. The body must be a defined AMQP type. /// </summary> /// <param name="body">the object stored in the AmqpValue section.</param> public Message(object body) { this.BodySection = new AmqpValue() { Value = body }; }
public object GetObject() { RestrictedDescribed body = amqpMessage.BodySection; if (body == null) { return(null); } else if (body is AmqpValue) { AmqpValue value = body as AmqpValue; return(value.Value); } else if (body is Data) { return((body as Data).Binary); } else if (body is AmqpSequence) { return((body as AmqpSequence).List); } else { throw new IllegalStateException("Unexpected body type: " + body.GetType().Name); } }
static void EncodeIfNotNull(RestrictedDescribed section, ByteBuffer buffer) { if (section != null) { section.Encode(buffer); } }
static int GetEstimatedBodySize(RestrictedDescribed body) { var data = body as Data; if (data != null) { if (data.Buffer != null) { return(data.Buffer.Length); } else { return(data.Binary.Length); } } var value = body as AmqpValue; if (value != null) { var b = value.Value as byte[]; if (b != null) { return(b.Length); } var f = value.Value as ByteBuffer; if (f != null) { return(f.Length); } } return(64); }
/// <summary> /// Initializes a message from an object as the body. The object is wrapped /// in an <see cref="AmqpValue"/> section. To control the body section type, /// create an empty message and set <see cref="Message.BodySection"/> to either /// <see cref="AmqpValue"/>, <see cref="Data"/> or <see cref="AmqpSequence"/>. /// </summary> /// <param name="body">the object stored in the AmqpValue section.</param> public Message(object body) { #if (NETFX || NETFX40 || NETFX35) this.BodySection = new AmqpValue <object>(body); #else this.BodySection = new AmqpValue() { Value = body }; #endif }
private static AmqpNmsMessageFacade CreateWithoutAnnotation(RestrictedDescribed body, Properties properties) { Symbol contentType = GetContentType(properties); if (body is Data || body is null) { if (IsContentType(SymbolUtil.OCTET_STREAM_CONTENT_TYPE, contentType) || IsContentType(null, contentType)) { return(new AmqpNmsBytesMessageFacade()); } else if (IsContentType(SymbolUtil.SERIALIZED_DOTNET_OBJECT_CONTENT_TYPE, contentType)) { return(new AmqpNmsObjectMessageFacade()); } else { if (IsTextualContent(contentType)) { return(new AmqpNmsTextMessageFacade()); } else { return(new AmqpNmsBytesMessageFacade()); } } } else if (body is AmqpValue amqpValue) { object value = amqpValue.Value; if (value == null || value is string) { return(new AmqpNmsTextMessageFacade()); } else if (value is byte[]) { return(new AmqpNmsBytesMessageFacade()); } else { return(new AmqpNmsObjectMessageFacade()); } } else if (body is AmqpSequence) { return(new AmqpNmsObjectMessageFacade()); } return(null); }
public void TestSetObjectOnNewAmqpTypedMessage() { String content = "myStringContent"; AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(true); amqpObjectMessageFacade.Body = content; // retrieve the body from the underlying message, check it matches expectation RestrictedDescribed section = amqpObjectMessageFacade.Message.BodySection; Assert.NotNull(section); Assert.IsInstanceOf <AmqpValue>(section); Assert.AreEqual(content, ((AmqpValue)section).Value); }
private Data GetBinaryFromBody() { RestrictedDescribed body = Message.BodySection; Data result = EMPTY_DATA; if (body == null) { return(result); } else if (body is Data) { byte[] binary = (body as Data).Binary; if (binary != null && binary.Length != 0) { return(body as Data); } } else if (body is AmqpValue) { object value = (body as AmqpValue).Value; if (value == null) { return(result); } if (value is byte[]) { byte[] dataValue = value as byte[]; if (dataValue.Length > 0) { result = new Data(); result.Binary = dataValue; } } else { throw new IllegalStateException("Unexpected Amqp value content-type: " + value.GetType().FullName); } } else { throw new IllegalStateException("Unexpected body content-type: " + body.GetType().FullName); } return(result); }
public void TestSetObjectOnNewMessage() { String content = "myStringContent"; AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(); amqpObjectMessageFacade.Body = content; var bytes = GetSerializedBytes(content); // retrieve the bytes from the underlying message, check they match expectation RestrictedDescribed messageBodySection = amqpObjectMessageFacade.Message.BodySection; Assert.NotNull(messageBodySection); Assert.IsInstanceOf <Data>(messageBodySection); CollectionAssert.AreEqual(bytes, ((Data)messageBodySection).Binary, "Underlying message data section did not contain the expected bytes"); }
private string GetTextFromBody() { string result = string.Empty; RestrictedDescribed body = this.message.BodySection; if (body == null) { return(result); } else if (body is Data) { byte[] data = (body as Data).Binary; result = DecodeBinaryBody(data); } else if (body is AmqpValue) { object value = (body as AmqpValue).Value; if (value == null) { return(result); } else if (value is byte[]) { result = DecodeBinaryBody(value as byte[]); } else if (value is string) { result = value as string; } else { throw new IllegalStateException("Unexpected Amqp value content-type: " + value.GetType().FullName); } } else { throw new IllegalStateException("Unexpected body content-type: " + body.GetType().FullName); } return(result); }
// Transport layer should call Codec to encode/decode frames. It ensures that // all dependant static fields in other class are initialized correctly. // NETMF does not track cross-class static field/ctor dependencies public static void Encode(RestrictedDescribed command, ByteBuffer buffer) { Fx.Assert(command != null, "command is null!"); command.Encode(buffer); }