IStreamMessage.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. using System;
  18. namespace Apache.NMS
  19. {
  20. /// <summary>
  21. /// A StreamMessage object is used to send a stream of primitive types in the
  22. /// .NET programming language. It is filled and read sequentially. It inherits
  23. /// from the Message interface and adds a stream message body.
  24. ///
  25. /// The primitive types can be read or written explicitly using methods for each
  26. /// type. They may also be read or written generically as objects. For instance,
  27. /// a call to IStreamMessage.WriteInt32(6) is equivalent to
  28. /// StreamMessage.WriteObject( (Int32)6 ). Both forms are provided, because the
  29. /// explicit form is convenient for static programming, and the object form is
  30. /// needed when types are not known at compile time.
  31. ///
  32. /// When the message is first created, and when ClearBody is called, the body of
  33. /// the message is in write-only mode. After the first call to reset has been made,
  34. /// the message body is in read-only mode. After a message has been sent, the
  35. /// client that sent it can retain and modify it without affecting the message
  36. /// that has been sent. The same message object can be sent multiple times. When a
  37. /// message has been received, the provider has called reset so that the message
  38. /// body is in read-only mode for the client.
  39. ///
  40. /// If ClearBody is called on a message in read-only mode, the message body is
  41. /// cleared and the message body is in write-only mode.
  42. ///
  43. /// If a client attempts to read a message in write-only mode, a
  44. /// MessageNotReadableException is thrown.
  45. ///
  46. /// If a client attempts to write a message in read-only mode, a
  47. /// MessageNotWriteableException is thrown.
  48. ///
  49. /// IStreamMessage objects support the following conversion table. The marked cases
  50. /// must be supported. The unmarked cases must throw a NMSException. The
  51. /// String-to-primitive conversions may throw a runtime exception if the primitive's
  52. /// valueOf() method does not accept it as a valid String representation of the
  53. /// primitive.
  54. ///
  55. /// A value written as the row type can be read as the column type.
  56. ///
  57. /// | | boolean byte short char int long float double String byte[]
  58. /// |----------------------------------------------------------------------
  59. /// |boolean | X X
  60. /// |byte | X X X X X
  61. /// |short | X X X X
  62. /// |char | X X
  63. /// |int | X X X
  64. /// |long | X X
  65. /// |float | X X X
  66. /// |double | X X
  67. /// |String | X X X X X X X X
  68. /// |byte[] | X
  69. /// |----------------------------------------------------------------------
  70. ///
  71. /// </summary>
  72. public interface IStreamMessage : IMessage
  73. {
  74. /// <summary>
  75. /// Reads a boolean from the stream message.
  76. /// </summary>
  77. /// <returns>
  78. /// A <see cref="System.Boolean"/>
  79. /// </returns>
  80. /// <exception cref="Apache.NMS.NMSException">
  81. /// if the NMS provider fails to read the message due to some internal error.
  82. /// </exception>
  83. /// <exception cref="Apache.NMS.MessageEOFException">
  84. /// if unexpected end of message stream has been reached.
  85. /// </exception>
  86. /// <exception cref="Apache.NMS.MessageFormatException">
  87. /// if this type conversion is invalid.
  88. /// </exception>
  89. /// <exception cref="Apache.NMS.MessageNotReadableException">
  90. /// if the message is in write-only mode.
  91. /// </exception>
  92. bool ReadBoolean();
  93. /// <summary>
  94. /// Reads a byte from the stream message.
  95. /// </summary>
  96. /// <returns>
  97. /// A <see cref="System.Byte"/>
  98. /// </returns>
  99. /// <exception cref="Apache.NMS.NMSException">
  100. /// if the NMS provider fails to read the message due to some internal error.
  101. /// </exception>
  102. /// <exception cref="Apache.NMS.MessageEOFException">
  103. /// if unexpected end of message stream has been reached.
  104. /// </exception>
  105. /// <exception cref="Apache.NMS.MessageFormatException">
  106. /// if this type conversion is invalid.
  107. /// </exception>
  108. /// <exception cref="Apache.NMS.MessageNotReadableException">
  109. /// if the message is in write-only mode.
  110. /// </exception>
  111. byte ReadByte();
  112. /// <summary>
  113. /// Reads a byte array field from the stream message into the specified byte[]
  114. /// object (the read buffer).
  115. ///
  116. /// To read the field value, ReadBytes should be successively called until it returns
  117. /// a value less than the length of the read buffer. The value of the bytes in the
  118. /// buffer following the last byte read is undefined.
  119. ///
  120. /// If ReadBytes returns a value equal to the length of the buffer, a subsequent
  121. /// ReadBytes call must be made. If there are no more bytes to be read, this call
  122. /// returns -1.
  123. ///
  124. /// If the byte array field value is null, ReadBytes returns -1.
  125. /// If the byte array field value is empty, ReadBytes returns 0.
  126. ///
  127. /// Once the first ReadBytes call on a byte[] field value has been made, the full
  128. /// value of the field must be read before it is valid to read the next field.
  129. /// An attempt to read the next field before that has been done will throw a
  130. /// MessageFormatException.
  131. ///
  132. /// To read the byte field value into a new byte[] object, use the ReadObject method.
  133. /// </summary>
  134. /// <param name="value">
  135. /// A <see cref="System.Byte"/>
  136. /// </param>
  137. /// <returns>
  138. /// A <see cref="System.Byte"/>
  139. /// the total number of bytes read into the buffer, or -1 if there is no more data
  140. /// because the end of the byte field has been reached
  141. /// </returns>
  142. /// <exception cref="Apache.NMS.NMSException">
  143. /// if the NMS provider fails to read the message due to some internal error.
  144. /// </exception>
  145. /// <exception cref="Apache.NMS.MessageEOFException">
  146. /// if unexpected end of message stream has been reached.
  147. /// </exception>
  148. /// <exception cref="Apache.NMS.MessageFormatException">
  149. /// if this type conversion is invalid.
  150. /// </exception>
  151. /// <exception cref="Apache.NMS.MessageNotReadableException">
  152. /// if the message is in write-only mode.
  153. /// </exception>
  154. /// <seealso cref="ReadObject"/>
  155. int ReadBytes(byte[] value);
  156. /// <summary>
  157. /// Reads a char from the stream message.
  158. /// </summary>
  159. /// <returns>
  160. /// A <see cref="System.Char"/>
  161. /// </returns>
  162. /// <exception cref="Apache.NMS.NMSException">
  163. /// if the NMS provider fails to read the message due to some internal error.
  164. /// </exception>
  165. /// <exception cref="Apache.NMS.MessageEOFException">
  166. /// if unexpected end of message stream has been reached.
  167. /// </exception>
  168. /// <exception cref="Apache.NMS.MessageFormatException">
  169. /// if this type conversion is invalid.
  170. /// </exception>
  171. /// <exception cref="Apache.NMS.MessageNotReadableException">
  172. /// if the message is in write-only mode.
  173. /// </exception>
  174. char ReadChar();
  175. /// <summary>
  176. /// Reads a short from the stream message.
  177. /// </summary>
  178. /// <returns>
  179. /// A <see cref="System.Int16"/>
  180. /// </returns>
  181. /// <exception cref="Apache.NMS.NMSException">
  182. /// if the NMS provider fails to read the message due to some internal error.
  183. /// </exception>
  184. /// <exception cref="Apache.NMS.MessageEOFException">
  185. /// if unexpected end of message stream has been reached.
  186. /// </exception>
  187. /// <exception cref="Apache.NMS.MessageFormatException">
  188. /// if this type conversion is invalid.
  189. /// </exception>
  190. /// <exception cref="Apache.NMS.MessageNotReadableException">
  191. /// if the message is in write-only mode.
  192. /// </exception>
  193. short ReadInt16();
  194. /// <summary>
  195. /// Reads a int from the stream message.
  196. /// </summary>
  197. /// <returns>
  198. /// A <see cref="System.Int32"/>
  199. /// </returns>
  200. /// <exception cref="Apache.NMS.NMSException">
  201. /// if the NMS provider fails to read the message due to some internal error.
  202. /// </exception>
  203. /// <exception cref="Apache.NMS.MessageEOFException">
  204. /// if unexpected end of message stream has been reached.
  205. /// </exception>
  206. /// <exception cref="Apache.NMS.MessageFormatException">
  207. /// if this type conversion is invalid.
  208. /// </exception>
  209. /// <exception cref="Apache.NMS.MessageNotReadableException">
  210. /// if the message is in write-only mode.
  211. /// </exception>
  212. int ReadInt32();
  213. /// <summary>
  214. /// Reads a long from the stream message.
  215. /// </summary>
  216. /// <returns>
  217. /// A <see cref="System.Int64"/>
  218. /// </returns>
  219. /// <exception cref="Apache.NMS.NMSException">
  220. /// if the NMS provider fails to read the message due to some internal error.
  221. /// </exception>
  222. /// <exception cref="Apache.NMS.MessageEOFException">
  223. /// if unexpected end of message stream has been reached.
  224. /// </exception>
  225. /// <exception cref="Apache.NMS.MessageFormatException">
  226. /// if this type conversion is invalid.
  227. /// </exception>
  228. /// <exception cref="Apache.NMS.MessageNotReadableException">
  229. /// if the message is in write-only mode.
  230. /// </exception>
  231. long ReadInt64();
  232. /// <summary>
  233. /// Reads a float from the stream message.
  234. /// </summary>
  235. /// <returns>
  236. /// A <see cref="System.Single"/>
  237. /// </returns>
  238. /// <exception cref="Apache.NMS.NMSException">
  239. /// if the NMS provider fails to read the message due to some internal error.
  240. /// </exception>
  241. /// <exception cref="Apache.NMS.MessageEOFException">
  242. /// if unexpected end of message stream has been reached.
  243. /// </exception>
  244. /// <exception cref="Apache.NMS.MessageFormatException">
  245. /// if this type conversion is invalid.
  246. /// </exception>
  247. /// <exception cref="Apache.NMS.MessageNotReadableException">
  248. /// if the message is in write-only mode.
  249. /// </exception>
  250. float ReadSingle();
  251. /// <summary>
  252. /// Reads a double from the stream message.
  253. /// </summary>
  254. /// <returns>
  255. /// A <see cref="System.Double"/>
  256. /// </returns>
  257. /// <exception cref="Apache.NMS.NMSException">
  258. /// if the NMS provider fails to read the message due to some internal error.
  259. /// </exception>
  260. /// <exception cref="Apache.NMS.MessageEOFException">
  261. /// if unexpected end of message stream has been reached.
  262. /// </exception>
  263. /// <exception cref="Apache.NMS.MessageFormatException">
  264. /// if this type conversion is invalid.
  265. /// </exception>
  266. /// <exception cref="Apache.NMS.MessageNotReadableException">
  267. /// if the message is in write-only mode.
  268. /// </exception>
  269. double ReadDouble();
  270. /// <summary>
  271. /// Reads a string from the stream message.
  272. /// </summary>
  273. /// <returns>
  274. /// A <see cref="System.String"/>
  275. /// </returns>
  276. /// <exception cref="Apache.NMS.NMSException">
  277. /// if the NMS provider fails to read the message due to some internal error.
  278. /// </exception>
  279. /// <exception cref="Apache.NMS.MessageEOFException">
  280. /// if unexpected end of message stream has been reached.
  281. /// </exception>
  282. /// <exception cref="Apache.NMS.MessageFormatException">
  283. /// if this type conversion is invalid.
  284. /// </exception>
  285. /// <exception cref="Apache.NMS.MessageNotReadableException">
  286. /// if the message is in write-only mode.
  287. /// </exception>
  288. string ReadString();
  289. /// <summary>
  290. /// Reads a Object from the stream message.
  291. /// </summary>
  292. /// <returns>
  293. /// A <see cref="System.Object"/>
  294. /// </returns>
  295. /// <exception cref="Apache.NMS.NMSException">
  296. /// if the NMS provider fails to read the message due to some internal error.
  297. /// </exception>
  298. /// <exception cref="Apache.NMS.MessageEOFException">
  299. /// if unexpected end of message stream has been reached.
  300. /// </exception>
  301. /// <exception cref="Apache.NMS.MessageFormatException">
  302. /// if this type conversion is invalid.
  303. /// </exception>
  304. /// <exception cref="Apache.NMS.MessageNotReadableException">
  305. /// if the message is in write-only mode.
  306. /// </exception>
  307. Object ReadObject();
  308. /// <summary>
  309. /// Writes a boolean to the stream message.
  310. /// </summary>
  311. /// <param name="value">
  312. /// A <see cref="System.Boolean"/>
  313. /// </param>
  314. /// <exception cref="Apache.NMS.NMSException">
  315. /// if the NMS provider fails to write to the message due to some internal error.
  316. /// </exception>
  317. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  318. /// if the message is in read-only mode.
  319. /// </exception>
  320. void WriteBoolean(bool value);
  321. /// <summary>
  322. /// Writes a byte to the stream message.
  323. /// </summary>
  324. /// <param name="value">
  325. /// A <see cref="System.Byte"/>
  326. /// </param>
  327. /// <exception cref="Apache.NMS.NMSException">
  328. /// if the NMS provider fails to write to the message due to some internal error.
  329. /// </exception>
  330. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  331. /// if the message is in read-only mode.
  332. /// </exception>
  333. void WriteByte(byte value);
  334. /// <summary>
  335. /// Writes a byte array field to the stream message.
  336. ///
  337. /// The byte array value is written to the message as a byte array field.
  338. /// Consecutively written byte array fields are treated as two distinct
  339. /// fields when the fields are read.
  340. /// </summary>
  341. /// <param name="value">
  342. /// A <see cref="System.Byte"/>
  343. /// </param>
  344. /// <exception cref="Apache.NMS.NMSException">
  345. /// if the NMS provider fails to write to the message due to some internal error.
  346. /// </exception>
  347. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  348. /// if the message is in read-only mode.
  349. /// </exception>
  350. void WriteBytes(byte[] value);
  351. /// <summary>
  352. /// Writes a portion of a byte array as a byte array field to the stream message.
  353. ///
  354. /// The a portion of the byte array value is written to the message as a byte
  355. /// array field. Consecutively written byte array fields are treated as two distinct
  356. /// fields when the fields are read.
  357. /// </summary>
  358. /// <param name="value">
  359. /// A <see cref="System.Byte"/>
  360. /// </param>
  361. /// <param name="offset">
  362. /// A <see cref="System.Int32"/> value that indicates the point in the buffer to
  363. /// begin writing to the stream message.
  364. /// </param>
  365. /// <param name="length">
  366. /// A <see cref="System.Int32"/> value that indicates how many bytes in the buffer
  367. /// to write to the stream message.
  368. /// </param>
  369. /// <exception cref="Apache.NMS.NMSException">
  370. /// if the NMS provider fails to write to the message due to some internal error.
  371. /// </exception>
  372. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  373. /// if the message is in read-only mode.
  374. /// </exception>
  375. void WriteBytes(byte[] value, int offset, int length);
  376. /// <summary>
  377. /// Writes a char to the stream message.
  378. /// </summary>
  379. /// <param name="value">
  380. /// A <see cref="System.Char"/>
  381. /// </param>
  382. /// <exception cref="Apache.NMS.NMSException">
  383. /// if the NMS provider fails to write to the message due to some internal error.
  384. /// </exception>
  385. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  386. /// if the message is in read-only mode.
  387. /// </exception>
  388. void WriteChar(char value);
  389. /// <summary>
  390. /// Writes a short to the stream message.
  391. /// </summary>
  392. /// <param name="value">
  393. /// A <see cref="System.Int16"/>
  394. /// </param>
  395. /// <exception cref="Apache.NMS.NMSException">
  396. /// if the NMS provider fails to write to the message due to some internal error.
  397. /// </exception>
  398. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  399. /// if the message is in read-only mode.
  400. /// </exception>
  401. void WriteInt16(short value);
  402. /// <summary>
  403. /// Writes a int to the stream message.
  404. /// </summary>
  405. /// <param name="value">
  406. /// A <see cref="System.Int32"/>
  407. /// </param>
  408. /// <exception cref="Apache.NMS.NMSException">
  409. /// if the NMS provider fails to write to the message due to some internal error.
  410. /// </exception>
  411. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  412. /// if the message is in read-only mode.
  413. /// </exception>
  414. void WriteInt32(int value);
  415. /// <summary>
  416. /// Writes a long to the stream message.
  417. /// </summary>
  418. /// <param name="value">
  419. /// A <see cref="System.Int64"/>
  420. /// </param>
  421. /// <exception cref="Apache.NMS.NMSException">
  422. /// if the NMS provider fails to write to the message due to some internal error.
  423. /// </exception>
  424. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  425. /// if the message is in read-only mode.
  426. /// </exception>
  427. void WriteInt64(long value);
  428. /// <summary>
  429. /// Writes a float to the stream message.
  430. /// </summary>
  431. /// <param name="value">
  432. /// A <see cref="System.Single"/>
  433. /// </param>
  434. /// <exception cref="Apache.NMS.NMSException">
  435. /// if the NMS provider fails to write to the message due to some internal error.
  436. /// </exception>
  437. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  438. /// if the message is in read-only mode.
  439. /// </exception>
  440. void WriteSingle(float value);
  441. /// <summary>
  442. /// Writes a double to the stream message.
  443. /// </summary>
  444. /// <param name="value">
  445. /// A <see cref="System.Double"/>
  446. /// </param>
  447. /// <exception cref="Apache.NMS.NMSException">
  448. /// if the NMS provider fails to write to the message due to some internal error.
  449. /// </exception>
  450. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  451. /// if the message is in read-only mode.
  452. /// </exception>
  453. void WriteDouble(double value);
  454. /// <summary>
  455. /// Writes a string to the stream message.
  456. /// </summary>
  457. /// <param name="value">
  458. /// A <see cref="System.String"/>
  459. /// </param>
  460. /// <exception cref="Apache.NMS.NMSException">
  461. /// if the NMS provider fails to write to the message due to some internal error.
  462. /// </exception>
  463. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  464. /// if the message is in read-only mode.
  465. /// </exception>
  466. void WriteString(string value);
  467. /// <summary>
  468. /// Writes a boolean to the stream message.
  469. /// </summary>
  470. /// <param name="value">
  471. /// A <see cref="System.Boolean"/>
  472. /// </param>
  473. /// <exception cref="Apache.NMS.NMSException">
  474. /// if the NMS provider fails to write to the message due to some internal error.
  475. /// </exception>
  476. /// <exception cref="Apache.NMS.MessageNotWriteableException">
  477. /// if the message is in read-only mode.
  478. /// </exception>
  479. void WriteObject(Object value);
  480. /// <summary>
  481. /// Puts the message body in read-only mode and repositions the stream to the beginning.
  482. /// </summary>
  483. /// <exception cref="Apache.NMS.MessageFormatException">
  484. /// Thrown when the Message has an invalid format.
  485. /// </exception>
  486. /// <exception cref="Apache.NMS.NMSException">
  487. /// Thrown when there is an unhandled exception thrown from the provider.
  488. /// </exception>
  489. void Reset();
  490. }
  491. }