https://github.com/foxcapades/go-bytify
Simple lib for writing typed values to byte buffers.
https://github.com/foxcapades/go-bytify
buffer bytes go golang library
Last synced: 9 months ago
JSON representation
Simple lib for writing typed values to byte buffers.
- Host: GitHub
- URL: https://github.com/foxcapades/go-bytify
- Owner: Foxcapades
- License: mit
- Created: 2020-11-03T16:10:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-01T23:43:34.000Z (over 5 years ago)
- Last Synced: 2025-02-12T17:19:20.977Z (over 1 year ago)
- Topics: buffer, bytes, go, golang, library
- Language: Go
- Homepage:
- Size: 1.22 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Go Bytify
image:https://img.shields.io/github/v/tag/foxcapades/go-bytify[GitHub tag (latest SemVer)]
image:https://img.shields.io/github/go-mod/go-version/foxcapades/go-bytify[GitHub go.mod Go version]
image:https://img.shields.io/github/license/foxcapades/go-bytify[GitHub]
image:https://img.shields.io/badge/api-docs-ff69b4[title="API Docs", link=https://pkg.go.dev/github.com/foxcapades/go-bytify/v0/bytify]
image:https://github.com/Foxcapades/go-bytify/workflows/Go/badge.svg[Go]
image:https://codecov.io/gh/Foxcapades/go-bytify/branch/main/graph/badge.svg?token=E4WD9IURJL[title=codecov, link=https://codecov.io/gh/Foxcapades/go-bytify]
A dead simple library for writing various types to byte buffers.
Bytify is intended for those who pursue senseless, borderline silly
micro-optimizations. If that's not you, consider using the standard library's
`strconv.Append*()` functions instead.
Bytify also has no dependencies on any outside or standard library packages, so
you can soak up that minimized assembly while you revel in the nanoseconds that
you're saving.
== Usage
.Install
[source,sh-session]
----
$ go get github.com/foxcapades/go-bytify/v0/bytify
----
.Example Usage
[source,go]
----
package main
import (
"fmt"
"github.com/foxcapades/go-bytify/v0/bytify"
)
func main() {
value := uint64(123_456_789_123)
buf := make([]byte, bytify.Uint64StringSize(value))
bytify.Uint64ToBytes(value, buf)
fmt.Println(string(buf)) // 123456789123
}
----
== Benchmarks
Benchmark output is stored in `docs/benchmarks`. each file was generated by the
benchmark script `\{version}/tools/bench/\{type}/main.go`.
The cycles/iterations used is 100 cycles of 10,000,000 iterations each (meaning
1 billion calls to each of the `bytify` and `strconv` functions).
== Change Log
Only the last 3 releases will be shown here. For further info see the
link:docs/releases.txt[`docs/releases.txt`] file.
`v0.3.0`::
Added the following feature complete methods with full test coverage:
+
.Serialization Methods
[cols="1m,4m",options="header"]
|===
| Type | Functions
| int8 | Int8ToBytes(int8, []byte) uint8
Int8ToBuf(int8, io.Writer) uint8
Int8ToByteSlice(int8) []byte
| int16 | Int16ToBytes(int16, []byte) uint8
Int16ToBuf(int16, io.Writer) uint8
Int16ToByteSlice(int16) []byte
| int32 | Int32ToBytes(int32, []byte) uint8
Int32ToBuf(int32, io.Writer) uint8
Int32ToByteSlice(int32) []byte
| int64 | Int64ToBytes(int64, []byte) uint8
Int64ToBuf(int64, io.Writer) uint8
Int64ToByteSlice(int64) []byte
|===
+
.Sizing Methods
[cols="1m,4m",options="header"]
|===
| Type | Functions
| int8 | Int8StringSize(int8) uint8
| int16 | Int16StringSize(int16) uint8
| int32 | Int32StringSize(int32) uint8
| int64 | Int64StringSize(int64) uint8
|===
There will be no breaking changes to these functions before v2.0.0 is released.
`v0.2.0`::
Added the following feature complete methods with full test coverage:
+
.Serialization Methods
[cols="1m,4m",options="header"]
|===
| Type | Functions
| uint8 | Uint8ToByteSlice(uint8) []byte
| uint16 | Uint16ToByteSlice(uint16) []byte
| uint32 | Uint32ToByteSlice(uint32) []byte
| uint64 | Uint64ToByteSlice(uint64) []byte
|===
There will be no breaking changes to these functions before v2.0.0 is released.
`v0.1.0`::
Added the following feature complete methods with full test coverage:
+
.Serialization Methods
[cols="1m,4m",options="header"]
|===
| Type | Functions
| uint8 | Uint8ToBytes(uint8, []byte) uint8
Uint8ToBuf(uint8, io.Writer) uint8
| uint16 | Uint16ToBytes(uint16, []byte) uint8
Uint16ToBuf(uint16, io.Writer) uint8
| uint32 | Uint32ToBytes(uint32, []byte) uint8
Uint32ToBuf(uint32, io.Writer) uint8
| uint64 | Uint64ToBytes(uint64, []byte) uint8
Uint64ToBuf(uint64, io.Writer) uint8
|===
+
.Sizing Methods
[cols="1m,4m",options="header"]
|===
| Type | Functions
| uint8 | Uint8StringSize(uint8) uint8
| uint16 | Uint16StringSize(uint16) uint8
| uint32 | Uint32StringSize(uint32) uint8
| uint64 | Uint64StringSize(uint64) uint8
|===
+
There will be no breaking changes to these functions before `v2.0.0` is released.