IBytesMessage.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace Apache.NMS
  18. {
  19. /// <summary>
  20. ///
  21. /// A BytesMessage object is used to send a message containing a stream of uninterpreted
  22. /// bytes. It inherits from the Message interface and adds a bytes message body. The
  23. /// receiver of the message supplies the interpretation of the bytes.
  24. ///
  25. /// This message type is for client encoding of existing message formats. If possible,
  26. /// one of the other self-defining message types should be used instead.
  27. ///
  28. /// Although the NMS API allows the use of message properties with byte messages, they
  29. /// are typically not used, since the inclusion of properties may affect the format.
  30. ///
  31. /// When the message is first created, and when ClearBody is called, the body of the
  32. /// message is in write-only mode. After the first call to Reset has been made, the
  33. /// message body is in read-only mode. After a message has been sent, the client that
  34. /// sent it can retain and modify it without affecting the message that has been sent.
  35. /// The same message object can be sent multiple times. When a message has been received,
  36. /// the provider has called Reset so that the message body is in read-only mode for the
  37. /// client.
  38. ///
  39. /// If ClearBody is called on a message in read-only mode, the message body is cleared and
  40. /// the message is in write-only mode.
  41. ///
  42. /// If a client attempts to read a message in write-only mode, a MessageNotReadableException
  43. /// is thrown.
  44. ///
  45. /// If a client attempts to write a message in read-only mode, a MessageNotWriteableException
  46. /// is thrown.
  47. /// </summary>
  48. public interface IBytesMessage : IMessage
  49. {
  50. byte[] Content { get; set; }
  51. /// <value>
  52. /// Gets the number of bytes of the message body when the message is in read-only mode.
  53. /// The value returned can be used to allocate a byte array. The value returned is the
  54. /// entire length of the message body, regardless of where the pointer for reading the
  55. /// message is currently located.
  56. /// </value>
  57. /// <exception cref="Apache.NMS.MessageNotReadableException">
  58. /// Thrown when the Message is in write-only mode.
  59. /// </exception>
  60. /// <exception cref="Apache.NMS.NMSException">
  61. /// Thrown when there is an unhandled exception thrown from the provider.
  62. /// </exception>
  63. long BodyLength { get; }
  64. /// <summary>
  65. /// Reads a byte from the Message Stream.
  66. /// </summary>
  67. /// <returns>
  68. /// A <see cref="System.Byte"/>
  69. /// </returns>
  70. /// <exception cref="Apache.NMS.MessageNotReadableException">
  71. /// Thrown when the Message is in write-only mode.
  72. /// </exception>
  73. /// <exception cref="Apache.NMS.MessageEOFException">
  74. /// Thrown when an unexpected end of bytes has been reached.
  75. /// </exception>
  76. /// <exception cref="Apache.NMS.NMSException">
  77. /// Thrown when there is an unhandled exception thrown from the provider.
  78. /// </exception>
  79. byte ReadByte();
  80. /// <summary>
  81. /// Writes a byte to the Message stream.
  82. /// </summary>
  83. /// <param name="value">
  84. /// A <see cref="System.Byte"/>
  85. /// </param>
  86. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  87. /// Thrown when the Message is in read-only mode.
  88. /// </exception>
  89. /// <exception cref="Apache.NMS.NMSException">
  90. /// Thrown when there is an unhandled exception thrown from the provider.
  91. /// </exception>
  92. void WriteByte(byte value);
  93. /// <summary>
  94. /// Reads a boolean from the Message Stream.
  95. /// </summary>
  96. /// <returns>
  97. /// A <see cref="System.Boolean"/>
  98. /// </returns>
  99. /// <exception cref="Apache.NMS.MessageNotReadableException">
  100. /// Thrown when the Message is in write-only mode.
  101. /// </exception>
  102. /// <exception cref="Apache.NMS.MessageEOFException">
  103. /// Thrown when an unexpected end of bytes has been reached.
  104. /// </exception>
  105. /// <exception cref="Apache.NMS.NMSException">
  106. /// Thrown when there is an unhandled exception thrown from the provider.
  107. /// </exception>
  108. bool ReadBoolean();
  109. /// <summary>
  110. /// Write a one byte value to the message stream representing the boolean
  111. /// value passed.
  112. /// </summary>
  113. /// <param name="value">
  114. /// A <see cref="System.Boolean"/>
  115. /// </param>
  116. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  117. /// Thrown when the Message is in read-only mode.
  118. /// </exception>
  119. /// <exception cref="Apache.NMS.NMSException">
  120. /// Thrown when there is an unhandled exception thrown from the provider.
  121. /// </exception>
  122. void WriteBoolean(bool value);
  123. /// <summary>
  124. /// Reads a char from the Message Stream.
  125. /// </summary>
  126. /// <returns>
  127. /// A <see cref="System.Char"/>
  128. /// </returns>
  129. /// <exception cref="Apache.NMS.MessageNotReadableException">
  130. /// Thrown when the Message is in write-only mode.
  131. /// </exception>
  132. /// <exception cref="Apache.NMS.MessageEOFException">
  133. /// Thrown when an unexpected end of bytes has been reached.
  134. /// </exception>
  135. /// <exception cref="Apache.NMS.NMSException">
  136. /// Thrown when there is an unhandled exception thrown from the provider.
  137. /// </exception>
  138. char ReadChar();
  139. /// <summary>
  140. /// Write a two byte value to the message stream representing the character
  141. /// value passed. High byte first.
  142. /// </summary>
  143. /// <param name="value">
  144. /// A <see cref="System.Char"/>
  145. /// </param>
  146. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  147. /// Thrown when the Message is in read-only mode.
  148. /// </exception>
  149. /// <exception cref="Apache.NMS.NMSException">
  150. /// Thrown when there is an unhandled exception thrown from the provider.
  151. /// </exception>
  152. void WriteChar(char value);
  153. /// <summary>
  154. /// Reads a Short from the Message Stream.
  155. /// </summary>
  156. /// <returns>
  157. /// A <see cref="System.Int16"/>
  158. /// </returns>
  159. /// <exception cref="Apache.NMS.MessageNotReadableException">
  160. /// Thrown when the Message is in write-only mode.
  161. /// </exception>
  162. /// <exception cref="Apache.NMS.MessageEOFException">
  163. /// Thrown when an unexpected end of bytes has been reached.
  164. /// </exception>
  165. /// <exception cref="Apache.NMS.NMSException">
  166. /// Thrown when there is an unhandled exception thrown from the provider.
  167. /// </exception>
  168. short ReadInt16();
  169. /// <summary>
  170. /// Write a two byte value to the message stream representing the short
  171. /// value passed. High byte first.
  172. /// </summary>
  173. /// <param name="value">
  174. /// A <see cref="System.Int16"/>
  175. /// </param>
  176. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  177. /// Thrown when the Message is in read-only mode.
  178. /// </exception>
  179. /// <exception cref="Apache.NMS.NMSException">
  180. /// Thrown when there is an unhandled exception thrown from the provider.
  181. /// </exception>
  182. void WriteInt16(short value);
  183. /// <summary>
  184. /// Reads an int from the Message Stream.
  185. /// </summary>
  186. /// <returns>
  187. /// A <see cref="System.Int32"/>
  188. /// </returns>
  189. /// <exception cref="Apache.NMS.MessageNotReadableException">
  190. /// Thrown when the Message is in write-only mode.
  191. /// </exception>
  192. /// <exception cref="Apache.NMS.MessageEOFException">
  193. /// Thrown when an unexpected end of bytes has been reached.
  194. /// </exception>
  195. /// <exception cref="Apache.NMS.NMSException">
  196. /// Thrown when there is an unhandled exception thrown from the provider.
  197. /// </exception>
  198. int ReadInt32();
  199. /// <summary>
  200. /// Write a four byte value to the message stream representing the integer
  201. /// value passed. High byte first.
  202. /// </summary>
  203. /// <param name="value">
  204. /// A <see cref="System.Int32"/>
  205. /// </param>
  206. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  207. /// Thrown when the Message is in read-only mode.
  208. /// </exception>
  209. /// <exception cref="Apache.NMS.NMSException">
  210. /// Thrown when there is an unhandled exception thrown from the provider.
  211. /// </exception>
  212. void WriteInt32(int value);
  213. /// <summary>
  214. /// Reads a long from the Message Stream.
  215. /// </summary>
  216. /// <returns>
  217. /// A <see cref="System.Int64"/>
  218. /// </returns>
  219. /// <exception cref="Apache.NMS.MessageNotReadableException">
  220. /// Thrown when the Message is in write-only mode.
  221. /// </exception>
  222. /// <exception cref="Apache.NMS.MessageEOFException">
  223. /// Thrown when an unexpected end of bytes has been reached.
  224. /// </exception>
  225. /// <exception cref="Apache.NMS.NMSException">
  226. /// Thrown when there is an unhandled exception thrown from the provider.
  227. /// </exception>
  228. long ReadInt64();
  229. /// <summary>
  230. /// Write a eight byte value to the message stream representing the long
  231. /// value passed. High byte first.
  232. /// </summary>
  233. /// <param name="value">
  234. /// A <see cref="System.Int64"/>
  235. /// </param>
  236. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  237. /// Thrown when the Message is in read-only mode.
  238. /// </exception>
  239. /// <exception cref="Apache.NMS.NMSException">
  240. /// Thrown when there is an unhandled exception thrown from the provider.
  241. /// </exception>
  242. void WriteInt64(long value);
  243. /// <summary>
  244. /// Reads a float from the Message Stream.
  245. /// </summary>
  246. /// <returns>
  247. /// A <see cref="System.Single"/>
  248. /// </returns>
  249. /// <exception cref="Apache.NMS.MessageNotReadableException">
  250. /// Thrown when the Message is in write-only mode.
  251. /// </exception>
  252. /// <exception cref="Apache.NMS.MessageEOFException">
  253. /// Thrown when an unexpected end of bytes has been reached.
  254. /// </exception>
  255. /// <exception cref="Apache.NMS.NMSException">
  256. /// Thrown when there is an unhandled exception thrown from the provider.
  257. /// </exception>
  258. float ReadSingle();
  259. /// <summary>
  260. /// Write a four byte value to the message stream representing the float
  261. /// value passed. High byte first.
  262. /// </summary>
  263. /// <param name="value">
  264. /// A <see cref="System.Single"/>
  265. /// </param>
  266. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  267. /// Thrown when the Message is in read-only mode.
  268. /// </exception>
  269. /// <exception cref="Apache.NMS.NMSException">
  270. /// Thrown when there is an unhandled exception thrown from the provider.
  271. /// </exception>
  272. void WriteSingle(float value);
  273. /// <summary>
  274. /// Reads an double from the Message Stream.
  275. /// </summary>
  276. /// <returns>
  277. /// A <see cref="System.Double"/>
  278. /// </returns>
  279. /// <exception cref="Apache.NMS.MessageNotReadableException">
  280. /// Thrown when the Message is in write-only mode.
  281. /// </exception>
  282. /// <exception cref="Apache.NMS.MessageEOFException">
  283. /// Thrown when an unexpected end of bytes has been reached.
  284. /// </exception>
  285. /// <exception cref="Apache.NMS.NMSException">
  286. /// Thrown when there is an unhandled exception thrown from the provider.
  287. /// </exception>
  288. double ReadDouble();
  289. /// <summary>
  290. /// Write a eight byte value to the message stream representing the double
  291. /// value passed. High byte first.
  292. /// </summary>
  293. /// <param name="value">
  294. /// A <see cref="System.Double"/>
  295. /// </param>
  296. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  297. /// Thrown when the Message is in read-only mode.
  298. /// </exception>
  299. /// <exception cref="Apache.NMS.NMSException">
  300. /// Thrown when there is an unhandled exception thrown from the provider.
  301. /// </exception>
  302. void WriteDouble(double value);
  303. /// <summary>
  304. /// Reads a byte array from the bytes message stream.
  305. ///
  306. /// If the length of array value is less than the number of bytes remaining to
  307. /// be read from the stream, the array should be filled. A subsequent call reads
  308. /// the next increment, and so on.
  309. ///
  310. /// If the number of bytes remaining in the stream is less than the length of array
  311. /// value, the bytes should be read into the array. The return value of the total number
  312. /// of bytes read will be less than the length of the array, indicating that there are
  313. /// no more bytes left to be read from the stream. The next read of the stream returns -1.
  314. /// </summary>
  315. /// <param name="value">
  316. /// The byte array that will be used as a buffer to read into.
  317. /// </param>
  318. /// <returns>
  319. /// A <see cref="System.Int32"/>
  320. /// The number of bytes read into the passed byte array, or -1 if there are no more
  321. /// bytes left to be read from the stream.
  322. /// </returns>
  323. /// <exception cref="Apache.NMS.NMSException">
  324. /// Thrown when there is an unhandled exception thrown from the provider.
  325. /// </exception>
  326. /// <exception cref="Apache.NMS.MessageNotReadableException">
  327. /// Thrown when the Message is in write-only mode.
  328. /// </exception>
  329. int ReadBytes(byte[] value);
  330. /// <summary>
  331. /// Reads a portion of the bytes message stream.
  332. ///
  333. /// If the length of array value is less than the number of bytes remaining to be
  334. /// read from the stream, the array should be filled. A subsequent call reads the
  335. /// next increment, and so on.
  336. ///
  337. /// If the number of bytes remaining in the stream is less than the length of array
  338. /// value, the bytes should be read into the array. The return value of the total
  339. /// number of bytes read will be less than the length of the array, indicating that
  340. /// there are no more bytes left to be read from the stream. The next read of the
  341. /// stream returns -1.
  342. ///
  343. /// If length is negative, or length is greater than the length of the array value,
  344. /// then an Exception is thrown. No bytes will be read from the stream for this
  345. /// exception case.
  346. /// </summary>
  347. /// <param name="value">
  348. /// The byte array that will be used as a buffer to read into.
  349. /// </param>
  350. /// <param name="length">
  351. /// The amount of bytes to read into the buffer.
  352. /// </param>
  353. /// <returns>
  354. /// A <see cref="System.Int32"/>
  355. /// The number of bytes read into the passed byte array, or -1 if there are no more
  356. /// bytes left to be read from the stream.
  357. /// </returns>
  358. /// <exception cref="Apache.NMS.MessageNotReadableException">
  359. /// Thrown when the Message is in write-only mode.
  360. /// </exception>
  361. /// <exception cref="Apache.NMS.NMSException">
  362. /// Thrown when there is an unhandled exception thrown from the provider.
  363. /// </exception>
  364. int ReadBytes(byte[] value, int length);
  365. /// <summary>
  366. /// Writes a byte array to the bytes message stream.
  367. /// </summary>
  368. /// <param name="value">
  369. /// A <see cref="System.Byte"/>
  370. /// </param>
  371. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  372. /// Thrown when the Message is in read-only mode.
  373. /// </exception>
  374. /// <exception cref="Apache.NMS.NMSException">
  375. /// Thrown when there is an unhandled exception thrown from the provider.
  376. /// </exception>
  377. void WriteBytes(byte[] value);
  378. /// <summary>
  379. /// Writes a portion of a byte array to the bytes message stream.
  380. /// </summary>
  381. /// <param name="value">
  382. /// A <see cref="System.Byte"/>
  383. /// </param>
  384. /// <param name="offset">
  385. /// A <see cref="System.Int32"/>
  386. /// </param>
  387. /// <param name="length">
  388. /// A <see cref="System.Int32"/>
  389. /// </param>
  390. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  391. /// Thrown when the Message is in read-only mode.
  392. /// </exception>
  393. /// <exception cref="Apache.NMS.NMSException">
  394. /// Thrown when there is an unhandled exception thrown from the provider.
  395. /// </exception>
  396. void WriteBytes(byte[] value, int offset, int length);
  397. /// <summary>
  398. /// Reads a string that has been encoded using a modified UTF-8 format from the bytes
  399. /// message stream.
  400. /// </summary>
  401. /// <returns>
  402. /// A <see cref="System.String"/>
  403. /// </returns>
  404. /// <exception cref="Apache.NMS.MessageNotReadableException">
  405. /// Thrown when the Message is in write-only mode.
  406. /// </exception>
  407. /// <exception cref="Apache.NMS.MessageEOFException">
  408. /// Thrown when an unexpected end of bytes has been reached.
  409. /// </exception>
  410. /// <exception cref="Apache.NMS.NMSException">
  411. /// Thrown when there is an unhandled exception thrown from the provider.
  412. /// </exception>
  413. string ReadString();
  414. /// <summary>
  415. /// Writes a string to the bytes message stream using UTF-8 encoding in a
  416. /// machine-independent manner.
  417. /// </summary>
  418. /// <param name="value">
  419. /// A <see cref="System.String"/>
  420. /// </param>
  421. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  422. /// Thrown when the Message is in read-only mode.
  423. /// </exception>
  424. /// <exception cref="Apache.NMS.NMSException">
  425. /// Thrown when there is an unhandled exception thrown from the provider.
  426. /// </exception>
  427. void WriteString(string value);
  428. /// <summary>
  429. /// Writes an object to the bytes message stream.
  430. ///
  431. /// This method works only for the objectified primitive object types
  432. /// (Int32, Double, Boolean ...), String objects, and byte arrays.
  433. /// </summary>
  434. /// <param name="value">
  435. /// A <see cref="System.Object"/>
  436. /// the object in the .NET programming language to be written; it must not be null
  437. /// </param>
  438. /// <exception cref="Apache.NMS.MessageFormatException">
  439. /// Thrown when the Message has an invalid format.
  440. /// </exception>
  441. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  442. /// Thrown when the Message is in read-only mode.
  443. /// </exception>
  444. /// <exception cref="Apache.NMS.NMSException">
  445. /// Thrown when there is an unhandled exception thrown from the provider.
  446. /// </exception>
  447. void WriteObject(System.Object value);
  448. /// <summary>
  449. /// Puts the message body in read-only mode and repositions the stream of bytes to the beginning.
  450. /// </summary>
  451. /// <exception cref="Apache.NMS.MessageFormatException">
  452. /// Thrown when the Message has an invalid format.
  453. /// </exception>
  454. /// <exception cref="Apache.NMS.NMSException">
  455. /// Thrown when there is an unhandled exception thrown from the provider.
  456. /// </exception>
  457. void Reset();
  458. }
  459. }