blockchain

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package blockchain provides the tools for encoding data primitives in blockchain structures

Index

Constants

This section is empty.

Variables

View Source
var ErrRange = errors.New("value out of range")

Functions

func ReadExtensibleString

func ReadExtensibleString(r *Reader, f func(*Reader) error) (suffix []byte, err error)

ReadExtensibleString reads a varint31 length prefix and that many bytes from r. It then calls the given function to consume those bytes, returning any unconsumed suffix.

func ReadVarint31

func ReadVarint31(r *Reader) (uint32, error)

func ReadVarint63

func ReadVarint63(r *Reader) (uint64, error)

func ReadVarstr31

func ReadVarstr31(r *Reader) ([]byte, error)

func ReadVarstrList

func ReadVarstrList(r *Reader) (result [][]byte, err error)

ReadVarstrList reads a varint31 length prefix followed by that many varstrs.

func WriteExtensibleString

func WriteExtensibleString(w io.Writer, suffix []byte, f func(io.Writer) error) (int, error)

WriteExtensibleString sends the output of the given function, plus the given suffix, to w, together with a varint31 length prefix.

func WriteVarint31

func WriteVarint31(w io.Writer, val uint64) (int, error)

func WriteVarint63

func WriteVarint63(w io.Writer, val uint64) (int, error)

func WriteVarstr31

func WriteVarstr31(w io.Writer, str []byte) (int, error)

func WriteVarstrList

func WriteVarstrList(w io.Writer, l [][]byte) (int, error)

WriteVarstrList writes a varint31 length prefix followed by the elements of l as varstrs.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader wraps a buffer and provides utilities for decoding data primitives in blockchain structures. Its various read calls may return a slice of the underlying buffer.

func NewReader

func NewReader(b []byte) *Reader

NewReader constructs a new reader with the provided bytes. It does not create a copy of the bytes, so the caller is responsible for copying the bytes if necessary.

func (*Reader) Len

func (r *Reader) Len() int

Len returns the number of unread bytes.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes into p. It implements the io.Reader interface.

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

ReadByte reads and returns the next byte from the input.

It implements the io.ByteReader interface.

Jump to

Keyboard shortcuts

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