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)
| 41 | // representation will be calculated lazily only once for a set of current |
| 42 | // connection options. |
| 43 | func 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 | |
| 62 | func (pm *PreparedMessage) frame(key prepareKey) (int, []byte, error) { |
| 63 | pm.mu.Lock() |