generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bufiox interfaces and spilit ttheader codec codes
- Loading branch information
Showing
9 changed files
with
1,051 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package bufiox | ||
|
||
// Reader is a buffer IO interface, which provides a user-space zero-copy method to reduce memory allocation and copy overhead. | ||
type Reader interface { | ||
// Next reads the next n bytes sequentially and returns a slice `p` of length `n`, | ||
// otherwise returns an error if it is unable to read a buffer of n bytes. | ||
// The returned `p` can be a shallow copy of the original buffer. | ||
// Must ensure that the data in `p` is not modified before calling Release. | ||
// | ||
// Callers cannot use the returned data after calling Release. | ||
Next(n int) (p []byte, err error) | ||
|
||
// Peek behaves the same as Next, except that it doesn't advance the reader. | ||
// | ||
// Callers cannot use the returned data after calling Release. | ||
Peek(n int) (buf []byte, err error) | ||
|
||
// Skip skips the next n bytes sequentially, otherwise returns an error if it's unable to skip a buffer of n bytes. | ||
Skip(n int) (err error) | ||
|
||
// ReadLen returns the size that has already been read. | ||
// Read/Next/Skip will increase the size. When the release function is called, ReadLen is set to 0. | ||
ReadLen() (n int) | ||
|
||
// Release will free the buffer. After release, buffer read by Next/Skip/Peek is invalid. | ||
// Param e is used when the buffer release depend on error. | ||
// For example, usually the write buffer will be released inside flush, | ||
// but if flush error happen, write buffer may need to be released explicitly. | ||
Release(e error) (err error) | ||
} |
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 bufiox | ||
|
||
// Writer is a buffer IO interface, which provides a user-space zero-copy method to reduce memory allocation and copy overhead. | ||
type Writer interface { | ||
// Malloc returns a shallow copy of the write buffer with length n, | ||
// otherwise returns an error if it's unable to get n bytes from the write buffer. | ||
// Must ensure that the data written by the user to buf can be flushed to the underlying io.Writer. | ||
// | ||
// Caller cannot write data to the returned buf after calling Flush. | ||
Malloc(n int) (buf []byte, err error) | ||
|
||
// WrittenLen returns the total length of the buffer written. | ||
WrittenLen() (length int) | ||
|
||
// Flush writes any malloc data to the underlying io.Writer, and reset WrittenLen to zero. | ||
Flush() (err error) | ||
} |
Oops, something went wrong.