[jboss-cvs] JBoss Messaging SVN: r3784 - trunk/src/main/org/jboss/messaging/core/remoting/codec.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 25 07:17:05 EST 2008


Author: timfox
Date: 2008-02-25 07:17:04 -0500 (Mon, 25 Feb 2008)
New Revision: 3784

Added:
   trunk/src/main/org/jboss/messaging/core/remoting/codec/ProducerSendMessageCodec.java
Log:
Added missing file from previous commit


Added: trunk/src/main/org/jboss/messaging/core/remoting/codec/ProducerSendMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/ProducerSendMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/ProducerSendMessageCodec.java	2008-02-25 12:17:04 UTC (rev 3784)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.PROD_SEND;
+
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.wireformat.ProducerSendMessage;
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * 
+ * A ProducerSendMessageCodec
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ProducerSendMessageCodec extends AbstractPacketCodec<ProducerSendMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ProducerSendMessageCodec()
+   {
+      super(PROD_SEND);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(ProducerSendMessage message, RemotingBuffer out) throws Exception
+   {
+      byte[] encodedMsg = StreamUtils.toBytes(message.getMessage());   
+
+      int bodyLength = INT_LENGTH + sizeof(message.getAddress()) + encodedMsg.length;
+
+      out.putInt(bodyLength);
+      out.putNullableString(message.getAddress());
+      out.putInt(encodedMsg.length);
+      out.put(encodedMsg);
+   }
+
+   @Override
+   protected ProducerSendMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+
+      String address = in.getNullableString();
+      int msgLength = in.getInt();
+      byte[] encodedMsg = new byte[msgLength];
+      in.get(encodedMsg);
+      Message message = new MessageImpl();
+      StreamUtils.fromBytes(message, encodedMsg);
+
+      return new ProducerSendMessage(address, message);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+




More information about the jboss-cvs-commits mailing list