add LengthFieldBasedFrameDecoder
continuous-integration/drone/push Build is passing Details

master
ehlxr 2021-02-08 23:05:31 +08:00
parent dbb95dd999
commit 9d72433199
5 changed files with 14 additions and 18 deletions

View File

@ -6,6 +6,11 @@ import java.util.Map;
* @author ehlxr
*/
public class Constants {
public static final int MAX_FRAME_LENGTH = 1024 * 1024; //最大长度
public static final int LENGTH_FIELD_LENGTH = 4; //长度字段所占的字节数
public static final int LENGTH_FIELD_OFFSET = 2; //长度偏移
public static final int LENGTH_ADJUSTMENT = 0;
public static final int INITIAL_BYTES_TO_STRIP = 0;
private static final Map<String, String> SYS_ENV = System.getenv();
public static String SERVER_HOST = "localhost";
/**
@ -36,22 +41,14 @@ public class Constants {
* sdk client
*/
public static int SDK_CLIENT_TIMEOUTMILLIS = 2000;
/**
* byte
*/
public static int DECODER_FRAMELENGTH = 100;
private Constants() {
}
public static String getEnv(String key) {
return SYS_ENV.get(key) == null ? "" : SYS_ENV.get(key);
}
/**
* byte
*/
public static int DECODER_FRAMELENGTH = 100;
public static final int MAX_FRAME_LENGTH = 1024 * 1024; //最大长度
public static final int LENGTH_FIELD_LENGTH = 4; //长度字段所占的字节数
public static final int LENGTH_FIELD_OFFSET = 2; //长度偏移
public static final int LENGTH_ADJUSTMENT = 0;
public static final int INITIAL_BYTES_TO_STRIP = 0;
}

View File

@ -24,7 +24,6 @@
package io.github.ehlxr.did.netty;
import io.github.ehlxr.did.netty.MyProtocolBean;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

View File

@ -92,7 +92,7 @@ public abstract class AbstractClient implements Client {
logger.debug("write {} to channel", sdkProto);
byte[] bytes = NettyUtil.toBytes(sdkProto);
MyProtocolBean myProtocolBean = new MyProtocolBean((byte)0xA, (byte)0xC, bytes.length, bytes);
MyProtocolBean myProtocolBean = new MyProtocolBean((byte) 0xA, (byte) 0xC, bytes.length, bytes);
channel.writeAndFlush(myProtocolBean).addListener((ChannelFutureListener) channelFuture -> {
if (channelFuture.isSuccess()) {
//发送成功后立即跳出
@ -138,7 +138,7 @@ public abstract class AbstractClient implements Client {
logger.debug("write {} to channel", sdkProto);
byte[] bytes = NettyUtil.toBytes(sdkProto);
MyProtocolBean myProtocolBean = new MyProtocolBean((byte)0xA, (byte)0xC, bytes.length, bytes);
MyProtocolBean myProtocolBean = new MyProtocolBean((byte) 0xA, (byte) 0xC, bytes.length, bytes);
channelFuture.channel().writeAndFlush(myProtocolBean).addListener(channelFuture -> {
if (channelFuture.isSuccess()) {
return;

View File

@ -1,10 +1,10 @@
package io.github.ehlxr.did.client;
import io.github.ehlxr.did.netty.MyProtocolDecoder;
import io.github.ehlxr.did.netty.MyProtocolEncoder;
import io.github.ehlxr.did.client.handler.SdkClientHandler;
import io.github.ehlxr.did.common.Constants;
import io.github.ehlxr.did.common.Try;
import io.github.ehlxr.did.netty.MyProtocolDecoder;
import io.github.ehlxr.did.netty.MyProtocolEncoder;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

View File

@ -1,10 +1,10 @@
package io.github.ehlxr.did.server.sdk;
import io.github.ehlxr.did.common.Constants;
import io.github.ehlxr.did.netty.MyProtocolBean;
import io.github.ehlxr.did.common.NettyUtil;
import io.github.ehlxr.did.common.SdkProto;
import io.github.ehlxr.did.core.SnowFlake;
import io.github.ehlxr.did.netty.MyProtocolBean;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;