(key prepareKey)
| 60 | } |
| 61 | |
| 62 | func (pm *PreparedMessage) frame(key prepareKey) (int, []byte, error) { |
| 63 | pm.mu.Lock() |
| 64 | frame, ok := pm.frames[key] |
| 65 | if !ok { |
| 66 | frame = &preparedFrame{} |
| 67 | pm.frames[key] = frame |
| 68 | } |
| 69 | pm.mu.Unlock() |
| 70 | |
| 71 | var err error |
| 72 | frame.once.Do(func() { |
| 73 | // Prepare a frame using a 'fake' connection. |
| 74 | // TODO: Refactor code in conn.go to allow more direct construction of |
| 75 | // the frame. |
| 76 | mu := make(chan struct{}, 1) |
| 77 | mu <- struct{}{} |
| 78 | var nc prepareConn |
| 79 | c := &Conn{ |
| 80 | conn: &nc, |
| 81 | mu: mu, |
| 82 | isServer: key.isServer, |
| 83 | compressionLevel: key.compressionLevel, |
| 84 | enableWriteCompression: true, |
| 85 | writeBuf: make([]byte, defaultWriteBufferSize+maxFrameHeaderSize), |
| 86 | } |
| 87 | if key.compress { |
| 88 | c.newCompressionWriter = compressNoContextTakeover |
| 89 | } |
| 90 | err = c.WriteMessage(pm.messageType, pm.data) |
| 91 | frame.data = nc.buf.Bytes() |
| 92 | }) |
| 93 | return pm.messageType, frame.data, err |
| 94 | } |
| 95 | |
| 96 | type prepareConn struct { |
| 97 | buf bytes.Buffer |
no test coverage detected