bitfield

package
v0.0.0-...-23d9192 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2018 License: Apache-2.0, BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package bitfield converts annotated structs into integer values.

Any field that is marked with a bitfield tag is compacted. The tag value has two parts. The part before the comma determines the method name for a generated type. If left blank the name of the field is used. The part after the comma determines the number of bits to use for the representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gen

func Gen(w io.Writer, x interface{}, c *Config) error

Gen generates code for unpacking integers created with Pack.

func Pack

func Pack(x interface{}, c *Config) (packed uint64, err error)

Pack packs annotated bit ranges of struct x in an integer.

Only fields that have a "bitfield" tag are compacted.

Types

type Config

type Config struct {
	// NumBits fixes the maximum allowed bits for the integer representation.
	// If NumBits is not 8, 16, 32, or 64, the actual underlying integer size
	// will be the next largest available.
	NumBits uint

	// If Package is set, code generation will write a package clause.
	Package string

	// TypeName is the name for the generated type. By default it is the name
	// of the type of the value passed to Gen.
	TypeName string
}

Config determines settings for packing and generation. If a Config is used, the same Config should be used for packing and generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL