github.com/moreal/bencodex-go@v0.0.0-20231021172012-18277a477d15/internal/encoder/bytes.go (about)

     1  package encoder
     2  
     3  import bencodex "github.com/moreal/bencodex-go/internal"
     4  
     5  //go:nosplit
     6  func (e *Encoder) encodeBytesLike(data bencodex.BencodexBytesLike) {
     7  	dataLength := data.Len()
     8  	e.grow(dataLength + 23)
     9  	if data.IsString() {
    10  		e.writeByte('u')
    11  	}
    12  	e.writeInt(int64(dataLength))
    13  	e.writeByte(':')
    14  	if data.IsBytes() {
    15  		e.write(data.MustAsBytes())
    16  	} else {
    17  		e.write(bencodex.S2B(data.MustAsString()))
    18  	}
    19  }