-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
syd
committed
Nov 15, 2023
1 parent
59cc1ce
commit bc9d5a1
Showing
6 changed files
with
153 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package wxworkfinancesdk | ||
|
||
import ( | ||
"bytes" | ||
"sync" | ||
) | ||
|
||
var bufferPool = sync.Pool{ | ||
New: func() any { | ||
return new(bytes.Buffer) | ||
}, | ||
} | ||
|
||
func BufferPool() *bytes.Buffer { | ||
return bufferPool.Get().(*bytes.Buffer) | ||
} | ||
|
||
func BufferPoolRelease(v *bytes.Buffer) { | ||
v.Reset() | ||
bufferPool.Put(v) | ||
} | ||
|
||
var readerPool = sync.Pool{ | ||
New: func() any { | ||
return new(bytes.Reader) | ||
}, | ||
} | ||
|
||
func ReaderPool(bs []byte) *bytes.Reader { | ||
r := readerPool.Get().(*bytes.Reader) | ||
r.Reset(bs) | ||
return r | ||
} | ||
|
||
func ReaderPoolRelease(r *bytes.Reader) { | ||
readerPool.Put(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
package wxworkfinancesdk | ||
|
||
import "sync" | ||
|
||
// MediaData 媒体消息结构体 | ||
type MediaData struct { | ||
OutIndexBuf string `json:"outindexbuf,omitempty"` // 消息分片索引信息 | ||
IsFinish bool `json:"is_finish,omitempty"` // | ||
Data []byte `json:"data,omitempty"` // 媒体数据内通 | ||
} | ||
|
||
var mediaDataPool = sync.Pool{ | ||
New: func() any { | ||
return new(MediaData) | ||
}, | ||
} | ||
|
||
func MediaDataPool() *MediaData { | ||
return mediaDataPool.Get().(*MediaData) | ||
} | ||
|
||
func MediaDataPoolRelease(m *MediaData) { | ||
m.OutIndexBuf = "" | ||
m.IsFinish = false | ||
m.Data = nil | ||
mediaDataPool.Put(m) | ||
} |