RSocket路由工具類


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;


/**
 * RSocket 路由工具類
 */
public class RSocketRouteUtils {
    /**
     * byte[] 類型
     *
     * @param routePath
     * @return
     */
    public static byte[] routeByte(String routePath) {
        byte[] routePathBytes = routePath.getBytes();
        byte[] route = new byte[routePathBytes.length + 1];
        route[0] = (byte) routePathBytes.length;
        for (int i = 0; i < routePathBytes.length; i++) {
            route[i + 1] = routePathBytes[i];
        }
        return route;
    }

    /**
     * ByteBuf 類型
     *
     * @param routePath
     * @return
     */
    public static ByteBuf routeByteBuf(String routePath) {
        byte[] routePathBytes = routePath.getBytes();
        ByteBuf buf = Unpooled.buffer();
        buf.writeByte(routePathBytes.length);
        buf.writeBytes(routePathBytes);
        return buf;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章