public boolean write(GeneratedMessage message) throws IOException { int msgSize = message.getSerializedSize(); if (msgSize > Constants.MAX_RECORD_SIZE) { return false; } if (msgBuffer == null || msgBuffer.length < msgSize) { msgBuffer = new byte[msgSize]; } CodedOutputStream cos = CodedOutputStream.newInstance(msgBuffer, 0, msgSize); message.writeTo(cos); cos.flush(); return write(msgBuffer, 0, msgSize); }
public void sendMessage( ChannelHandlerContext ctx, short serviceId, short commandId, GeneratedMessage msg, Packetlistener packetlistener, short seqnum) { if (ctx != null) { Header header = new Header(); header.setCommandId(commandId); header.setServiceId(serviceId); if (seqnum != 0) { header.setSeqnum(seqnum); } if (packetlistener != null && seqnum == 0) { short reqSeqnum = header.getSeqnum(); listenerQueue.push(reqSeqnum, packetlistener); } header.setLength(SysConstant.HEADER_LENGTH + msg.getSerializedSize()); messageServerThread.sendMessage(ctx, header, msg); } }