1 20 package org.apache.mina.example.sumup.codec; 21 22 import java.util.Collections ; 23 import java.util.HashSet ; 24 import java.util.Set ; 25 26 import org.apache.mina.common.ByteBuffer; 27 import org.apache.mina.common.IoSession; 28 import org.apache.mina.example.sumup.message.AbstractMessage; 29 import org.apache.mina.example.sumup.message.ResultMessage; 30 import org.apache.mina.filter.codec.demux.MessageEncoder; 31 32 38 public class ResultMessageEncoder extends AbstractMessageEncoder { 39 private static final Set <Class <?>> TYPES; 40 41 static { 42 Set <Class <?>> types = new HashSet <Class <?>>(); 43 types.add(ResultMessage.class); 44 TYPES = Collections.unmodifiableSet(types); 45 } 46 47 public ResultMessageEncoder() { 48 super(Constants.RESULT); 49 } 50 51 protected void encodeBody(IoSession session, AbstractMessage message, 52 ByteBuffer out) { 53 ResultMessage m = (ResultMessage) message; 54 if (m.isOk()) { 55 out.putShort((short) Constants.RESULT_OK); 56 out.putInt(m.getValue()); 57 } else { 58 out.putShort((short) Constants.RESULT_ERROR); 59 } 60 } 61 62 public Set <Class <?>> getMessageTypes() { 63 return TYPES; 64 } 65 66 public void dispose() throws Exception { 67 } 68 69 } 70 | Popular Tags |