GithubHelp home page GithubHelp logo

bitbuf's Introduction

GoDoc Go report card Build Status

bitbuf

A readable bitstream. Create from a byte slice, and read through the stream bit by bit.

Supports the following read types:

  • byte, []byte
  • int8, int16, int32, int64
  • uint8, uint16, uint32, uint64
  • float32, float64
  • string (of known length, or until null terminator)
  • bits (returned as []byte

Usage

package main

import (
	"bytes"
	"encoding/binary"
	"github.com/galaco/bitbuf"
	"log"
)

type Foo struct {
	A byte
	B int16
	C float32
	D int64
	E [32]byte
	F uint8
	G float64
	H int8
	I uint32
}

func main() {
	dataBuffer := &bytes.Buffer{}
	f := Foo{
		A: 32,
		B: 8375,
		C: 2106.3212345,
		D: 5635455352,
		E: [32]byte{84,12,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,12,13,54,1,143,234,5,56,1,2},
		F: 213,
		G: -756351.123,
		H: -57,
		I: 12645123,
	}

	binary.Write(dataBuffer, binary.LittleEndian, f)

	buf := bitbuf.NewReader(dataBuffer.Bytes())
	log.Println(buf.ReadByte())
	log.Println(buf.ReadInt16())
	log.Println(buf.ReadFloat32())
	log.Println(buf.ReadInt64())
	log.Println(buf.ReadBytes(32))
	log.Println(buf.ReadUint8())
	log.Println(buf.ReadFloat64())
	log.Println(buf.ReadInt8())
	log.Println(buf.ReadUint32())
}

bitbuf's People

Contributors

galaco avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.