MCPcopy
hub / github.com/gorilla/websocket / NewPreparedMessage

Function NewPreparedMessage

prepared.go:43–60  ·  view source on GitHub ↗

NewPreparedMessage returns an initialized PreparedMessage. You can then send it to connection using WritePreparedMessage method. Valid wire representation will be calculated lazily only once for a set of current connection options.

(messageType int, data []byte)

Source from the content-addressed store, hash-verified

41// representation will be calculated lazily only once for a set of current
42// connection options.
43func NewPreparedMessage(messageType int, data []byte) (*PreparedMessage, error) {
44 pm := &PreparedMessage{
45 messageType: messageType,
46 frames: make(map[prepareKey]*preparedFrame),
47 data: data,
48 }
49
50 // Prepare a plain server frame.
51 _, frameData, err := pm.frame(prepareKey{isServer: true, compress: false})
52 if err != nil {
53 return nil, err
54 }
55
56 // To protect against caller modifying the data argument, remember the data
57 // copied to the plain server frame.
58 pm.data = frameData[len(frameData)-len(data):]
59 return pm, nil
60}
61
62func (pm *PreparedMessage) frame(key prepareKey) (int, []byte, error) {
63 pm.mu.Lock()

Callers 3

echoReadAllFunction · 0.92
TestPreparedMessageFunction · 0.85
BenchmarkBroadcastFunction · 0.85

Calls 1

frameMethod · 0.95

Tested by 2

TestPreparedMessageFunction · 0.68
BenchmarkBroadcastFunction · 0.68