第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我試圖改變來(lái)自流的字節(jié),因?yàn)榻獯a,但它不起作用

我試圖改變來(lái)自流的字節(jié),因?yàn)榻獯a,但它不起作用

Go
千萬(wàn)里不及你 2022-06-06 17:51:30
我正在嘗試io.ReaderCloser使用可以傳遞給 JSON 解碼器的自定義閱讀器來(lái)包裝一個(gè),它在生產(chǎn)中將來(lái)自請(qǐng)求處理程序。我創(chuàng)建了以下import (    "io")// RemoveNull is a stream wrapper that should remove null bytes from the byte streamtype RemoveNull struct {    Reader io.ReadCloser}// NewRemoveNullStream creates a new RemoveNull reader which passes the stream through a null check firstfunc NewRemoveNullStream(reader io.ReadCloser) RemoveNull {    return RemoveNull{        Reader: reader,    }}// Read wraps a Reader to remove null bytes in the streamfunc (null RemoveNull) Read(p []byte) (n int, err error) {    n, err = null.Reader.Read(p)    if err != nil {        return n, err    }    nn := 0    for i := range p {        if p[i] != 0 {            p[nn] = p[i]            nn++        }    }    p = p[:nn]    // fmt.Println(p) i can see the value of p changing and all the null bytes are removed    return n, nil}// Close closes the internal readerfunc (null RemoveNull) Close() error {    return null.Close()}當(dāng)我運(yùn)行以下命令時(shí),我可以從 print 語(yǔ)句中看到確實(shí)刪除了所有空字節(jié),并且 len(p) == 所有預(yù)期好字節(jié)的大小。我寫了下面的測(cè)試,看看代碼是否按我的預(yù)期工作,這就是我意識(shí)到它不是的地方。從測(cè)試中我可以看到解碼時(shí)所有空字節(jié)仍然存在,但在 RemoveNull 閱讀器中我可以看到所有空字節(jié)都已從下劃線數(shù)組中刪除。關(guān)于什么是錯(cuò)的以及如何實(shí)現(xiàn)從流中刪除字節(jié)以避免讓解碼器解碼空字節(jié)的目標(biāo)的任何想法?
查看完整描述

1 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊

您的 Read 實(shí)現(xiàn)中存在錯(cuò)誤。它在 io.EOF 的情況下過早終止,其中同時(shí)存在錯(cuò)誤和數(shù)據(jù)。它返回讀取的錯(cuò)誤字節(jié)數(shù)。分配切片的最后一部分也沒有意義,因?yàn)樗粫?huì)更新傳遞給函數(shù)的切片。


嘗試這個(gè):


func (null RemoveNull) Read(p []byte) (n int, err error) {

    n, err = null.Reader.Read(p)

    nn := 0

    for i:=0;i<n;i++ {

        if p[i] != 0 {

            p[nn] = p[i]

            nn++


        }

    }

    return nn, err

}


查看完整回答
反對(duì) 回復(fù) 2022-06-06
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)