主頁 > 後端開發 > Netty-LengthFieldBasedFrameDecoder-解決拆包粘包問題的解碼器

Netty-LengthFieldBasedFrameDecoder-解決拆包粘包問題的解碼器

2023-07-08 07:53:25 後端開發

構造器引數

  • maxFrameLength:指定解碼器所能處理的資料包的最大長度,超過該長度則拋出 TooLongFrameException 例外;
  • lengthFieldOffset:指定長度欄位的起始位置;
  • lengthFieldLength:指定長度欄位的長度:目前支持1(byte)、2(short)、3(3個byte)、4(int)、8(Long)
  • lengthAdjustment:指定長度欄位所表示的訊息長度值與實際長度值之間的差值,可以用于調整解碼器的計算和提高靈活性,
  • initialBytesToStrip:指定解碼器在將資料包分離出來后,跳過的位元組數,因為這些位元組通常不屬于訊息體內容,而是協議頭或其他控制資訊,

單元測驗Demo

有關使用方法和方式參考測驗Demo即可,

package com.netty.framework.core.channel;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;

/**
 * @author 左半邊是惡魔
 * @date 2023/7/7
 * @time 16:10
 */
public class LengthFieldBasedFrameDecoderTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(LengthFieldBasedFrameDecoderTest.class);

    // 用于輸出內容
    private final ChannelInboundHandlerAdapter handlerAdapter = new ChannelInboundHandlerAdapter() {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            LOGGER.debug("handlerAdapter-接收到資訊:{}", msg);
            super.channelRead(ctx, msg);
        }
    };

    /**
     * 二進制資料結構
     * lengthFieldOffset   = 0
     * lengthFieldLength   = 4
     * lengthAdjustment    = 0
     * initialBytesToStrip = 0 (不跳過長度欄位長度資訊讀取)
     * 編碼前 (16 bytes)                     編碼后 (16 bytes)
     * +------------+----------------+      +------------+----------------+
     * |   Length   | Actual Content |----->|   Length   | Actual Content |
     * | 0x0000000C | "Hello, World" |      | 0x0000000C | "Hello, World" |
     * +------------+----------------+      +------------+----------------+
     */
    @Test
    public void test00() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 0, 4, 0, 0);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // readInt會更新readerIndex值
                int lengthField = byteBuf.readInt();
                LOGGER.debug("長度欄位[LengthField]的值={},即(Hello, World)的二進制長度,", lengthField);
                LOGGER.debug("長度讀取后readerIndex={}", byteBuf.readerIndex());

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeInt(bytes.length);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }


    /**
     * 二進制資料結構
     * lengthFieldOffset   = 0
     * lengthFieldLength   = 4
     * lengthAdjustment    = 0
     * initialBytesToStrip = 4 (跳過長度欄位長度資訊讀取)
     * 編碼前 (16 bytes)                     編碼后 (12 bytes)
     * +------------+----------------+      +--------+--------+
     * |   Length   | Actual Content |----->|  Actual Content |
     * | 0x0000000C | "Hello, World" |      |  "Hello, World" |
     * +------------+----------------+      +--------+--------+
     */
    @Test
    public void test01() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 0, 4, 0, 4);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeInt(bytes.length);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }

    /**
     * 此處lengthField包含了訊息頭的長度,即:Length = lengthFieldLength + 訊息位元組長度(Hello, World的二進制長度)
     * lengthFieldOffset   =  0
     * lengthFieldLength   =  4
     * lengthAdjustment    = -4 (lengthField欄位的長度)
     * initialBytesToStrip =  0
     * 編碼前 (16 bytes)                     編碼后 (16 bytes)
     * +------------+----------------+      +------------+----------------+
     * |   Length   | Actual Content |----->|   Length   | Actual Content |
     * | 0x0000000G | "Hello, World" |      | 0x0000000G | "Hello, World" |
     * +------------+----------------+      +------------+----------------+
     */
    @Test
    public void test02() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 0, 4, -4, 0);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // readInt會更新readerIndex值
                int lengthField = byteBuf.readInt();
                LOGGER.debug("長度欄位[LengthField]的值={},即(Hello, World)的二進制長度,", lengthField);
                LOGGER.debug("長度讀取后readerIndex={}", byteBuf.readerIndex());

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        // 4=int的位元組長度
        byteBuf.writeInt(bytes.length + 4);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }

    /**
     * lengthField在中間位置
     * lengthFieldOffset   = 2 (= the length of Header 1)
     * lengthFieldLength   = 4
     * lengthAdjustment    = 0
     * initialBytesToStrip = 0
     * <p>
     * BEFORE DECODE (18 bytes)                      AFTER DECODE (18 bytes)
     * +----------+----------+----------------+      +----------+----------+----------------+
     * | Header 1 |  Length  | Actual Content |----->| Header 1 |  Length  | Actual Content |
     * |  0xCAFE  | 0x00000C | "Hello, World" |      |  0xCAFE  | 0x00000C | "Hello, World" |
     * +----------+----------+----------------+      +----------+----------+----------------+
     */
    @Test
    public void test03() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 2, 4, 0, 0);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // 讀取header1
                short header1 = byteBuf.readShort();
                LOGGER.debug("header1={}", header1);

                // readInt會更新readerIndex值
                int lengthField = byteBuf.readInt();
                LOGGER.debug("長度欄位[LengthField]的值={},即(Hello, World)的二進制長度,", lengthField);
                LOGGER.debug("長度讀取后readerIndex={}", byteBuf.readerIndex());

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeShort(99);
        byteBuf.writeInt(bytes.length);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }

    /**
     * lengthField在開始位置
     * lengthFieldOffset   = 0 (= the length of Header 1)
     * lengthFieldLength   = 4
     * lengthAdjustment    = 2
     * initialBytesToStrip = 0
     * BEFORE DECODE (18 bytes)                      AFTER DECODE (18 bytes)
     * +----------+----------+----------------+      +----------+----------+----------------+
     * |  Length  | Header 1 | Actual Content |----->|  Length  | Header 1 | Actual Content |
     * | 0x00000C |  0xCAFE  | "Hello, World" |      | 0x00000C |  0xCAFE  | "Hello, World" |
     * +----------+----------+----------------+      +----------+----------+----------------+
     */
    @Test
    public void test04() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 0, 4, 2, 0);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // readInt會更新readerIndex值
                int lengthField = byteBuf.readInt();
                LOGGER.debug("長度欄位[LengthField]的值={},即(Hello, World)的二進制長度,", lengthField);
                LOGGER.debug("長度讀取后readerIndex={}", byteBuf.readerIndex());

                // 讀取header1
                short header1 = byteBuf.readShort();
                LOGGER.debug("header1={}", header1);

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeInt(bytes.length);
        byteBuf.writeShort(99);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }

    /**
     * lengthFieldOffset   = 1 (= the length of HDR1)
     * lengthFieldLength   = 4
     * lengthAdjustment    = 1 (= the length of HDR2)
     * initialBytesToStrip = 5 (= the length of HDR1 + LEN)
     * BEFORE DECODE (18 bytes)                       AFTER DECODE (13 bytes)
     * +------+--------+------+----------------+      +------+----------------+
     * | HDR1 | Length | HDR2 | Actual Content |----->| HDR2 | Actual Content |
     * | 0xCA | 0x000C | 0xFE | "Hello, World" |      | 0xFE | "Hello, World" |
     * +------+--------+------+----------------+      +------+----------------+
     */
    @Test
    public void test05() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 1, 4, 1, 5);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // 讀取header2
                short header2 = byteBuf.readByte();
                LOGGER.debug("header2={}", header2);

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeByte(1);
        byteBuf.writeInt(bytes.length);
        byteBuf.writeByte(9);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }


    /**
     * lengthFieldOffset   =  1
     * lengthFieldLength   =  4 (整個訊息的長度 = HDR1 + Length + HDR2 + Centent)
     * lengthAdjustment    = -5 (HDR1 + LEN的負值)
     * initialBytesToStrip =  5
     * BEFORE DECODE (18 bytes)                       AFTER DECODE (13 bytes)
     * +------+--------+------+----------------+      +------+----------------+
     * | HDR1 | Length | HDR2 | Actual Content |----->| HDR2 | Actual Content |
     * | 0xCA | 0x0010 | 0xFE | "Hello, World" |      | 0xFE | "Hello, World" |
     * +------+--------+------+----------------+      +------+----------------+
     */
    @Test
    public void test06() {
        class LengthFieldDecoder extends LengthFieldBasedFrameDecoder {
            public LengthFieldDecoder() {
                super(1024, 1, 4, -5, 5);
            }

            @Override
            protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
                ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
                LOGGER.debug("長度讀取前readerIndex={}", byteBuf.readerIndex());

                // 讀取header2
                short header2 = byteBuf.readByte();
                LOGGER.debug("header2={}", header2);

                // toString方法根據readerIndex最新值開始解碼
                return byteBuf.toString(StandardCharsets.UTF_8);
            }
        }

        LengthFieldBasedFrameDecoder decoder = new LengthFieldDecoder();
        EmbeddedChannel channel = new EmbeddedChannel(decoder, handlerAdapter);

        byte[] bytes = "Hello, World".getBytes(StandardCharsets.UTF_8);
        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeByte(1);
        byteBuf.writeInt(bytes.length + 6);
        byteBuf.writeByte(2);
        byteBuf.writeBytes(bytes);

        channel.writeInbound(byteBuf);
    }
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/556774.html

標籤:其他

上一篇:java wordcount

下一篇:返回列表

標籤雲
其他(162198) Python(38266) JavaScript(25527) Java(18291) C(15239) 區塊鏈(8275) C#(7972) AI(7469) 爪哇(7425) MySQL(7290) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5876) 数组(5741) R(5409) Linux(5347) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4613) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2438) ASP.NET(2404) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) HtmlCss(1993) .NET技术(1986) 功能(1967) Web開發(1951) C++(1942) python-3.x(1918) 弹簧靴(1913) xml(1889) PostgreSQL(1882) .NETCore(1863) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Netty-LengthFieldBasedFrameDecoder-解決拆包粘包問題的解碼器

    ### 構造器引數 - maxFrameLength:指定解碼器所能處理的資料包的最大長度,超過該長度則拋出 TooLongFrameException 例外; - lengthFieldOffset:指定長度欄位的起始位置; - lengthFieldLength:指定長度欄位的長度:目前支持1( ......

    uj5u.com 2023-07-08 07:53:25 more
  • java wordcount

    import com.google.common.base.Splitter; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; import org.apache.spark.api.j ......

    uj5u.com 2023-07-08 07:53:20 more
  • 【numpy基礎】--目錄(完結)

    # 概述 NumPy是一個開源的科學計算庫,它提供了高效的數值計算和陣列操作功能,主要包括: * 多維陣列的創建、操作和索引。 * 陣列的切片、拼接和轉置。 * 陣列的乘法、除法、求導、積分、對數等基本運算。 * 陣列的逐元素操作、求平均值、中位數、眾數等統計量。 * 陣列作為串列、元組等資料型別進 ......

    uj5u.com 2023-07-08 07:53:16 more
  • 在MAC OS上的vscode 安裝java開發環境

    在Mac OS上安裝vs code的java開發環境. 按照vs code的官方說明安裝Java相關插件, 遇見下列問題并解決了. 安裝JDK環境 安裝Extension Pack for Java 插件后,vscode會提示你安裝一個java,我安裝提示安裝了java.后來才發現安裝的是jre,并 ......

    uj5u.com 2023-07-08 07:53:12 more
  • 基于JavaFX的掃雷游戲實作(三)——互動邏輯

    相信閱讀過上期文章,動手能力強的朋友們已經自己跑出來界面了。所以這期我要講的是互動部分,也就是對于滑鼠點擊事件的回應,包括計時計數對點擊事件以及一些狀態量的影響。 回憶下第一期介紹的掃雷規則和操作,游戲從開局到結束可能會涉及到哪些情況呢?我認為比較重要的就是明確什么情況下游戲已經結束,結束代表的是勝 ......

    uj5u.com 2023-07-08 07:53:08 more
  • python multiprocessing庫使用記錄

    # python multiprocessing庫使用記錄 需求是想并行呼叫形式化分析工具proverif,同時發起對多個query的分析(378個)。實驗室有40核心80執行緒的服務器(雙cpu,至強gold 5218R*2)。 觀察到單個命令在分析時記憶體占用不大,且只使用單核心執行,因此考慮同時調 ......

    uj5u.com 2023-07-08 07:52:05 more
  • python:匯入庫、模塊失敗

    一般發生在程式開始部分: `from pymodbus.client.sync import ModbusSerialClient` `from pymodbus.payload import BinaryPayloadDecoder` `from pymodbus.constants import ......

    uj5u.com 2023-07-07 07:47:05 more
  • Java 構造器

    # Java 構造器 # 1. 構造器 ## 構造器也叫構造方法,是用來完成物件的初始化。 ## 構造器的定義: > ## 構造器的定義:[訪問修飾符] 方法名(形參),構造器與方法不同,并沒有回傳值,也不能寫void,訪問修飾符可以是不同的,方法名要與本類的類名相同 > > ## 構造器的呼叫是由 ......

    uj5u.com 2023-07-07 07:47:01 more
  • 《Effective C++ 改善程式與設計的55個具體做法》讀書筆記

    ### 1 .讓自己習慣C++ #### 條款01 視C++為一個語言聯邦 * `C` * `Object-Oriented C++` * `Template C++` * `STL` * `C++`高效編程守則視情況而變化,取決于你使用`C++`的哪一部分。 #### 條款02 盡量與const, ......

    uj5u.com 2023-07-07 07:46:56 more
  • Python中startswith()和endswith()方法

    **startswith()方法** startswith() 方法用于檢索字串是否以指定字串開頭,如果是回傳 True;反之回傳 False。 **endswith()方法** endswith() 方法用于檢索字串是否以指定字串結尾,如果是則回傳 True;反之則回傳 False ``` ......

    uj5u.com 2023-07-07 07:46:51 more