forked from orijtech/groupcache
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from vimeo/grpc_no_bytes_copy
gRPC: don't copy bytes before sending on the wire.
- Loading branch information
Showing
2 changed files
with
18 additions
and
1 deletion.
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,17 @@ | ||
package grpc | ||
|
||
// unsafeByteCodec is a byte slice type that implements Codec | ||
type unsafeByteCodec []byte | ||
|
||
// MarshalBinary returns the contained byte-slice | ||
func (c *unsafeByteCodec) MarshalBinary() ([]byte, error) { | ||
return *c, nil | ||
} | ||
|
||
// UnmarshalBinary to provided data so they share the same backing array | ||
// this is a generally unsafe performance optimization, but safe in the context | ||
// of the gRPC server. | ||
func (c *unsafeByteCodec) UnmarshalBinary(data []byte) error { | ||
*c = data | ||
return nil | ||
} |