Giter Site home page Giter Site logo

crunch's Introduction

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

BenchmarkBufferWrite-4          	30000000	         47.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferRead-4           	20000000	         111 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferWrite-4      	200000000	         7.29 ns/op	       0 B/op	       0 allocs/op
BenchmarkMiniBufferRead-4       	1000000000	         1.73 ns/op	       0 B/op	       0 allocs/op
BenchmarkStdByteBufferWrite-4   	50000000	         24.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkStdByteBufferRead-4    	200000000	         7.84 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.Seek(-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

crunch's People

Contributors

superwhiskers avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.