1 module hunt.proton.message.Message; 2 3 import std.stdio; 4 5 import hunt.proton.amqp.messaging.ApplicationProperties; 6 import hunt.proton.amqp.messaging.DeliveryAnnotations; 7 import hunt.proton.amqp.messaging.Footer; 8 import hunt.proton.amqp.messaging.Header; 9 import hunt.proton.amqp.messaging.MessageAnnotations; 10 import hunt.proton.amqp.messaging.Properties; 11 import hunt.proton.amqp.messaging.Section; 12 import hunt.proton.codec.ReadableBuffer; 13 import hunt.proton.codec.WritableBuffer; 14 import hunt.proton.message.impl.MessageImpl; 15 import hunt.proton.message.MessageError; 16 import hunt.String; 17 18 /** 19 * Represents a Message within Proton. 20 * 21 * Create instances of Message using {@link Message.Factory}. 22 * 23 */ 24 interface Message 25 { 26 27 class Factory 28 { 29 public static Message create() { 30 return new MessageImpl(); 31 } 32 33 public static Message create(Header header, 34 DeliveryAnnotations deliveryAnnotations, 35 MessageAnnotations messageAnnotations, 36 Properties properties, 37 ApplicationProperties applicationProperties, 38 Section body, 39 Footer footer) 40 { 41 return new MessageImpl(header, deliveryAnnotations, 42 messageAnnotations, properties, 43 applicationProperties, body, footer); 44 } 45 } 46 47 48 enum short DEFAULT_PRIORITY = 4; 49 50 bool isDurable(); 51 52 long getDeliveryCount(); 53 54 short getPriority(); 55 56 bool isFirstAcquirer(); 57 58 long getTtl(); 59 60 void setDurable(bool durable); 61 62 void setTtl(long ttl); 63 64 void setDeliveryCount(long deliveryCount); 65 66 void setFirstAcquirer(bool firstAcquirer); 67 68 void setPriority(short priority); 69 70 Object getMessageId(); 71 72 long getGroupSequence(); 73 74 String getReplyToGroupId(); 75 76 77 long getCreationTime(); 78 79 String getAddress(); 80 81 byte[] getUserId(); 82 83 String getReplyTo(); 84 85 String getGroupId(); 86 87 String getContentType(); 88 89 long getExpiryTime(); 90 91 Object getCorrelationId(); 92 93 String getContentEncoding(); 94 95 String getSubject(); 96 97 void setGroupSequence(long groupSequence); 98 99 void setUserId(byte[] userId); 100 101 void setCreationTime(long creationTime); 102 103 void setSubject(String subject); 104 105 void setGroupId(String groupId); 106 107 void setAddress(String to); 108 109 void setExpiryTime(long absoluteExpiryTime); 110 111 void setReplyToGroupId(String replyToGroupId); 112 113 void setContentEncoding(String contentEncoding); 114 115 void setContentType(String contentType); 116 117 void setReplyTo(String replyTo); 118 119 void setCorrelationId(String correlationId); 120 121 void setMessageId(String messageId); 122 123 Header getHeader(); 124 125 DeliveryAnnotations getDeliveryAnnotations(); 126 127 MessageAnnotations getMessageAnnotations(); 128 129 Properties getProperties(); 130 131 ApplicationProperties getApplicationProperties(); 132 133 Section getBody(); 134 135 Footer getFooter(); 136 137 void setHeader(Header header); 138 139 void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations); 140 141 void setMessageAnnotations(MessageAnnotations messageAnnotations); 142 143 void setProperties(Properties properties); 144 145 void setApplicationProperties(ApplicationProperties applicationProperties); 146 147 void setBody(Section body); 148 149 void setFooter(Footer footer); 150 151 /** 152 * TODO describe what happens if the data does not represent a complete message. 153 * Currently this appears to leave the message in an unknown state. 154 */ 155 int decode(byte[] data, int offset, int length); 156 157 /** 158 * Decodes the Message from the given {@link ReadableBuffer}. 159 * <p> 160 * If the buffer given does not contain the fully encoded Message bytes for decode 161 * this method will throw an exception to indicate the buffer underflow condition and 162 * the message object will be left in an undefined state. 163 * 164 * @param buffer 165 * A {@link ReadableBuffer} that contains the complete message bytes. 166 */ 167 void decode(ReadableBuffer buffer); 168 169 /** 170 * Encodes up to {@code length} bytes of the message into the provided byte array, 171 * starting at position {@code offset}. 172 * 173 * TODO describe what happens if length is smaller than the encoded form, Currently 174 * Proton-J throws an exception. What does Proton-C do? 175 * 176 * @return the number of bytes written to the byte array 177 */ 178 int encode(byte[] data, int offset, int length); 179 180 /** 181 * Encodes the current Message contents into the given {@link WritableBuffer} instance. 182 * <p> 183 * This method attempts to encode all message data into the {@link WritableBuffer} and 184 * if the buffer has insufficient space it will throw an exception to indicate the buffer 185 * overflow condition. If successful the method returns the number of bytes written to 186 * the provided buffer to fully encode the message. 187 * 188 * @param buffer 189 * The {@link WritableBuffer} instance to encode the message contents into. 190 * 191 * @return the number of bytes written to fully encode the message. 192 */ 193 int encode(WritableBuffer buffer); 194 195 void clear(); 196 197 MessageError getError(); 198 }