randxdr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxBytesSize is the MaxBytesSize value in the Generator returned by NewGenerator()
	DefaultMaxBytesSize = 1024
	// DefaultMaxVecLen is the MaxVecLen value in the Generator returned by NewGenerator()
	DefaultMaxVecLen = 10
	// DefaultSeed is the seed for the Source value in the Generator returned by NewGenerator()
	DefaultSeed = 99
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// MaxBytesSize configures the upper bound limit for variable length
	// opaque data and variable length strings
	// https://tools.ietf.org/html/rfc4506#section-4.10
	MaxBytesSize uint32
	// MaxVecLen configures the upper bound limit for variable length arrays
	// https://tools.ietf.org/html/rfc4506#section-4.13
	MaxVecLen uint32
	// Source is the rand.Source which is used by the Generator to create
	// random values
	Source rand.Source
}

Generator generates random XDR values.

func NewGenerator

func NewGenerator() Generator

NewGenerator returns a new Generator instance configured with default settings. The returned Generator is deterministic but it is not thread-safe.

func (Generator) Next

func (g Generator) Next(shape goxdr.XdrType, presets []Preset)

Next modifies the given shape and populates it with random value fields.

type Preset

type Preset struct {
	Selector Selector
	Setter   Setter
}

Preset can be used to restrict values for specific fields of a goxdr.XdrType.

type Selector

type Selector func(string, goxdr.XdrType) bool

Selector is function used to match fields of a goxdr.XdrType

var IsNestedInnerSet Selector = func(name string, xdrType goxdr.XdrType) bool {
	if strings.HasSuffix(name, ".innerSets") && strings.Count(name, ".innerSets[") > 0 {
		_, ok := goxdr.XdrBaseType(xdrType).(goxdr.XdrVec)
		return ok
	}
	return false
}

IsNestedInnerSet is a Selector which identifies nesting for the following xdr type:

struct SCPQuorumSet
{
	uint32 threshold;
	PublicKey validators<>;
	SCPQuorumSet innerSets<>;
};

supports things like: A,B,C,(D,E,F),(G,H,(I,J,K,L)) only allows 2 levels of nesting

var IsPtr Selector = func(name string, xdrType goxdr.XdrType) bool {
	_, ok := goxdr.XdrBaseType(xdrType).(goxdr.XdrPtr)
	return ok
}

IsPtr is a Selector which matches on all XDR pointer fields

func FieldEquals

func FieldEquals(toMatch string) Selector

FieldEquals returns a Selector which matches on a field name by equality

func FieldMatches

func FieldMatches(r *regexp.Regexp) Selector

FieldMatches returns a Selector which matches on a field name by regexp

type Setter

type Setter func(*randMarshaller, string, goxdr.XdrType)

Setter is a function used to set field values for a goxdr.XdrType

var SetPtrToPresent Setter = func(m *randMarshaller, name string, xdrType goxdr.XdrType) {
	p := goxdr.XdrBaseType(xdrType).(goxdr.XdrPtr)
	p.SetPresent(true)
	p.XdrMarshalValue(m, name)
}

SetPtrToPresent is a Setter which ensures that a given XDR pointer field is not nil

func SetPositiveNum32

func SetPositiveNum32() Setter

SetPositiveNum32 returns a Setter which sets a uint32 XDR field to a random positive value

func SetPositiveNum64

func SetPositiveNum64() Setter

SetPositiveNum64 returns a Setter which sets a uint64 XDR field to a random positive value

func SetU32

func SetU32(val uint32) Setter

SetU32 returns a Setter which sets a uint32 XDR field to a fixed value

func SetVecLen

func SetVecLen(vecLen uint32) Setter

SetVecLen returns a Setter which sets the length of a variable length array ( https://tools.ietf.org/html/rfc4506#section-4.13 ) to a fixed value

Jump to

Keyboard shortcuts

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