/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/message/param/ParamDescriptor.java

http://mobicents.googlecode.com/ · Java · 93 lines · 12 code · 7 blank · 74 comment · 0 complexity · fb44bb10e629445d5706f052829c1e4d MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.message.param;
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25. import java.io.Serializable;
  26. import org.mobicents.protocols.smpp.util.PacketDecoder;
  27. import org.mobicents.protocols.smpp.util.PacketEncoder;
  28. /**
  29. * Parameter descriptor. The parameter descriptor interface provides a way
  30. * for SMPP types to be read from byte arrays and written to output streams.
  31. * Descriptors are used for both mandatory and optional parameters.
  32. * @version $Id: ParamDescriptor.java 457 2009-01-15 17:37:42Z orank $
  33. */
  34. public interface ParamDescriptor extends Serializable {
  35. /**
  36. * Get the index of another numerical mandatory parameter which specifies
  37. * the length of the parameter this descriptor represents. For example,
  38. * in a submit_sm packet, the length of the short_message parameter is
  39. * specified by the sm_length parameter, a 1-byte integer immediately
  40. * preceding short_message in the mandatory parameter section of the packet.
  41. * Therefore, the parameter descriptor that will be used to decode the
  42. * short_message would return the index of the sm_length parameter in the
  43. * body. This specified length can then be used to decode the correct
  44. * number of bytes for the short message.
  45. * <p>
  46. * As another example, take the submit_multi packet. It has a mandatory
  47. * parameter called dest_address(es) which specify all the destinations
  48. * the message should be submitted to. The number of destinations in the
  49. * destination table is specified by the number_of_dests mandatory
  50. * parameter. In this case, the descriptor used to read the dest_addresses
  51. * would return the index of number_of_dests from this method.
  52. * </p>
  53. * @return The index in the mandatory parameters of where to find the length
  54. * specifier for this descriptor. If this descriptor does not need or
  55. * support a length specifier, <code>-1</code> must be returned.
  56. */
  57. int getLengthSpecifier();
  58. /**
  59. * Get the encoded byte-size of <code>obj</code>.
  60. * @param obj The object to calculate the encoded size for.
  61. * @return The number of bytes the specified object would be encoded
  62. * to via the {@link #writeObject(Object, OutputStream)} method.
  63. */
  64. int sizeOf(Object obj);
  65. /**
  66. * Write the specified object to an output stream.
  67. * @param obj The object to encode.
  68. * @param out The output stream to write the object to.
  69. * @throws IOException If there was an error writing to the stream.
  70. */
  71. void writeObject(Object obj, PacketEncoder encoder) throws IOException;
  72. /**
  73. * Read an object from a byte array.
  74. * @param data The byte data to read (or decode) an object from.
  75. * @param position The position to begin parsing from. This position will
  76. * be updated upon return to point to the first byte after the decoded
  77. * object in the byte array.
  78. * @param length The number of bytes to use in reading the object. If the
  79. * length is unknown and intrinsic to the type being decoded (such as
  80. * a C-String, which is terminated by a nul-byte), then <code>-1</code>
  81. * may be supplied.
  82. * @return The decoded object.
  83. */
  84. // TODO this should throw something - a runtime exception
  85. Object readObject(PacketDecoder decoder, int length);
  86. }