Skip to content

Prependable is a buffer that support 'Prepend(data []byte)' method without copying and moving the existing payload inside the buffer.

License

Notifications You must be signed in to change notification settings

MUCZ/Prependable

Repository files navigation

Prependable

Docs : https://pkg.go.dev/github.com/mucz/prependable

Prependable is a buffer that support 'Prepend(data []byte)' method without copying and moving the existing payload inside the buffer.

It is useful when building networking packets, where each protocol adds its own headers to the front of the higher-level protocol header and payload; for example, TCP would prepend its header to the payload, then IP would prepend its own, then ethernet.

The larger the (len(payload)/len(header)), the more Prependable Buffer can show performance benefits.

|- reserved  space -|
+-------------------+------------------+------------------+
| prependable bytes |  readable bytes  |  writable bytes  |
|                   |     (CONTENT)    |                  |
+-------------------+------------------+------------------+
|                   |                  |                  |
0      <=      readerIndex   <=   writerIndex    <=     size

About

Prependable is a buffer that support 'Prepend(data []byte)' method without copying and moving the existing payload inside the buffer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published