Skip to content

take bytes out of things easily ✨🍪

License

GPL-3.0, LGPL-3.0 licenses found

Licenses found

GPL-3.0
license.gpl
LGPL-3.0
license.lesser
Notifications You must be signed in to change notification settings

LaevusDexter/crunch

 
 

Repository files navigation

crunch

godoc travis codecov go report card edit on repl.it

manipulate bytes and bits in golang with ease

install

$ go get github.com/superwhiskers/crunch

benchmarks

MiniBuffer performs on average more than twice as fast as bytes.Buffer in both writing and reading

BenchmarkBufferWriteBytes-4       	50000000	        36.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferReadBytes-4        	20000000	       100 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferWriteU32LE-4       	30000000	        47.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferReadU32LE-4        	10000000	       170 ns/op	       8 B/op	       1 allocs/op
BenchmarkBufferReadBit-4          	20000000	       113 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferReadBits-4         	 5000000	       253 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferSetBit-4           	20000000	       101 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferClearBit-4         	20000000	        99.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferWriteBytes-4   	200000000	         6.71 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferReadBytes-4    	2000000000	         1.48 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferWriteU32LE-4   	100000000	        21.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferReadU32LE-4    	100000000	        11.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferReadBit-4      	2000000000	         1.71 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferReadBits-4     	100000000	        14.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferSetBit-4       	500000000	         3.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferClearBit-4     	500000000	         3.16 ns/op	       0 B/op	       0 allocs/op
BenchmarkStdByteBufferWrite-4     	50000000	        23.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkStdByteBufferRead-4      	200000000	         7.18 ns/op	       0 B/op	       0 allocs/op

example

package main

import (
	"fmt"
	"github.com/superwhiskers/crunch"
)

func main() {

	// creates a new buffer with four zeroes
	buf := crunch.NewBuffer([]byte{0x00, 0x00, 0x00, 0x00})
	
	// write the byte `0x01` to the first offset, and move the offset forward one
	buf.WriteByteNext(0x01)
	
	// write the byte `0x01` to the second offset, and move the offset forward one
	buf.WriteByteNext(0x01)
	
	// seek the offset back one
	buf.SeekByte(-1, true)
	
	// write the bytes `0x02` and `0x03` to the second and third offsets, respectively
	buf.WriteBytesNext([]byte{0x02, 0x03})
	
	// write the byte `0x04` to offset `0x03`
	buf.WriteByte(0x03, 0x04)
	
	// output the buffer's contents to the console
	fmt.Printf("%v\n", buf.Bytes())
	
}

license

lgplv3

About

take bytes out of things easily ✨🍪

Resources

License

GPL-3.0, LGPL-3.0 licenses found

Licenses found

GPL-3.0
license.gpl
LGPL-3.0
license.lesser

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%