Skip to content

Commit 157278e

Browse files
committed
Document wspb and wsjson buffer reuse
See #71
1 parent ae10ad3 commit 157278e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Diff for: wsjson/wsjson.go

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
)
1212

1313
// Read reads a json message from c into v.
14+
// If the message is larger than 128 bytes, it will use a buffer
15+
// from a pool instead of performing an allocation.
1416
func Read(ctx context.Context, c *websocket.Conn, v interface{}) error {
1517
err := read(ctx, c, v)
1618
if err != nil {
@@ -39,6 +41,7 @@ func read(ctx context.Context, c *websocket.Conn, v interface{}) error {
3941
}
4042

4143
// Write writes the json message v to c.
44+
// It uses json.Encoder which automatically reuses buffers.
4245
func Write(ctx context.Context, c *websocket.Conn, v interface{}) error {
4346
err := write(ctx, c, v)
4447
if err != nil {

Diff for: wspb/wspb.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
// Read reads a protobuf message from c into v.
14+
// It will reuse buffers to avoid allocations.
1415
func Read(ctx context.Context, c *websocket.Conn, v proto.Message) error {
1516
err := read(ctx, c, v)
1617
if err != nil {
@@ -39,6 +40,7 @@ func read(ctx context.Context, c *websocket.Conn, v proto.Message) error {
3940
}
4041

4142
// Write writes the protobuf message v to c.
43+
// It will reuse buffers to avoid allocations.
4244
func Write(ctx context.Context, c *websocket.Conn, v proto.Message) error {
4345
err := write(ctx, c, v)
4446
if err != nil {

0 commit comments

Comments
 (0)