github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/protocol/message/analysis/analysis_test.go (about)

     1  package analysis
     2  
     3  import (
     4  	"github.com/nyan233/littlerpc/core/container"
     5  	message2 "github.com/nyan233/littlerpc/core/protocol/message"
     6  	"github.com/nyan233/littlerpc/core/protocol/message/mux"
     7  	"github.com/nyan233/littlerpc/core/utils/random"
     8  	"github.com/stretchr/testify/assert"
     9  	"testing"
    10  )
    11  
    12  func TestAnalysisNoMuxMessage(t *testing.T) {
    13  	var bytes []byte
    14  	assert.Equal(t, message2.Marshal(message2.New(), (*container.Slice[byte])(&bytes)), nil)
    15  	t.Log(NoMux(bytes))
    16  }
    17  
    18  func TestAnalysisMuxMessage(t *testing.T) {
    19  	var bytes []byte
    20  	assert.Equal(t, message2.Marshal(message2.New(), (*container.Slice[byte])(&bytes)), nil)
    21  	muxBlock := &mux.Block{
    22  		Flags:    mux.Enabled,
    23  		StreamId: random.FastRand(),
    24  		MsgId:    uint64(random.FastRand()),
    25  	}
    26  	muxBlock.SetPayloads(bytes)
    27  	var bytes2 []byte
    28  	mux.Marshal(muxBlock, (*container.Slice[byte])(&bytes2))
    29  	t.Log(Mux(bytes2))
    30  }