varu64

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 7 Imported by: 0

README

varu64

Go Reference

varu64 provides Go implementation of VarU64.

package main

import (
	"encoding/json"
	"os"

	"github.com/ksinica/varu64"
)

func main() {
	type foo struct {
		Bar varu64.Uint64 `json:"bar"`
	}
	json.NewEncoder(os.Stdout).Encode(&foo{
		Bar: varu64.U64(72057594037927933),
	})
	// {"bar": "fefffffffffffffd"}

	var val varu64.Uint64
	val.SetValue(1)
	json.NewEncoder(os.Stdout).Encode(&val)
	// "01"
}

License

Source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNonCanonical is a non-critical error signalizing that a non-canonical
	// VarU64 encoding was encountered. Operations returning ErrNonCanonical
	// can be considered successful.
	ErrNonCanonical = errors.New("varu64: non-canonical encoding")
)

Functions

func ReadUint64

func ReadUint64(r io.Reader) (uint64, int, error)

ReadFrom decodes VarU64 from r until EOF or error, and returns decoded value, number of bytes read and an error, if any, except EOF.

func WriteUint64

func WriteUint64(w io.Writer, value uint64) (int, error)

WriteUint64 encodes value to w. It returns the number of bytes written and an error, if any.

Types

type Uint64

type Uint64 struct {
	io.ReaderFrom
	io.WriterTo
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	encoding.TextMarshaler
	encoding.TextUnmarshaler
	// contains filtered or unexported fields
}

Uint64 is a handy data transfer object that wraps uint64 and allows encoding and decoding as defined by the VarU64 specification.

func U64

func U64(value uint64) Uint64

U64 returns value wrapped as Uint64.

func (*Uint64) MarshalBinary

func (v *Uint64) MarshalBinary() ([]byte, error)

MarshalBinary encodes receiver into a byte slice and returns an error, if any.

func (*Uint64) MarshalText

func (v *Uint64) MarshalText() ([]byte, error)

MarshalText encodes receiver into a textual representation of VarU64 encoding.

func (*Uint64) ReadFrom

func (v *Uint64) ReadFrom(r io.Reader) (int64, error)

ReadFrom decodes VarU64 from r until EOF or error, and sets the receiver's underlying uint64 value to the decoded one. It returns the number of bytes read and an error, if any, except EOF.

func (*Uint64) SetValue

func (v *Uint64) SetValue(value uint64)

SetValue sets the receiver's underlying uint64 value to value.

func (*Uint64) String

func (v *Uint64) String() string

Returns the string representation of the receiver's underlying uint64 value in base 10.

func (*Uint64) UnmarshalBinary

func (v *Uint64) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes VarU64-encoded data into the receiver.

func (*Uint64) UnmarshalText

func (v *Uint64) UnmarshalText(text []byte) error

UnmarshalText decodes VarU64-encoded textual representation into the receiver.

func (*Uint64) Value

func (v *Uint64) Value() uint64

Value returns the receiver's underlying uint64 value.

func (*Uint64) WriteTo

func (v *Uint64) WriteTo(w io.Writer) (int64, error)

WriteTo encodes receiver to w. It returns the number of bytes written and an error, if any.

Jump to

Keyboard shortcuts

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