Documentation ¶
Index ¶
Constants ¶
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.
type Selector ¶
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 ¶
FieldEquals returns a Selector which matches on a field name by equality
func FieldMatches ¶
FieldMatches returns a Selector which matches on a field name by regexp
type Setter ¶
Setter is a function used to set field values for a goxdr.XdrType
var SetAssetCode Setter = func(x *randMarshaller, field string, xdrType goxdr.XdrType) { f := goxdr.XdrBaseType(xdrType).(goxdr.XdrBytes) slice := f.GetByteSlice() var end int switch len(slice) { case 4: end = int(x.rand.Int31n(4)) case 12: end = int(4 + x.rand.Int31n(8)) } for i := 0; i <= end; i++ { slice[i] = alphaNumeric[x.rand.Int31n(int32(len(alphaNumeric)))] } }
SetAssetCode returns a Setter which sets an asset code XDR field to a random alphanumeric string right-padded with 0 bytes
var SetPositiveNum32 Setter = func(x *randMarshaller, field string, xdrType goxdr.XdrType) { f := goxdr.XdrBaseType(xdrType).(goxdr.XdrNum32) f.SetU32(uint32(x.rand.Int31n(math.MaxInt32))) }
SetPositiveNum32 returns a Setter which sets a uint32 XDR field to a random positive value
var SetPositiveNum64 Setter = func(x *randMarshaller, field string, xdrType goxdr.XdrType) { f := goxdr.XdrBaseType(xdrType).(goxdr.XdrNum64) f.SetU64(uint64(x.rand.Int63n(math.MaxInt64))) }
SetPositiveNum64 returns a Setter which sets a uint64 XDR field to a random positive value
var SetPrintableASCII Setter = func(x *randMarshaller, field string, xdrType goxdr.XdrType) { f := goxdr.XdrBaseType(xdrType).(goxdr.XdrString) end := int(x.rand.Int31n(int32(f.Bound))) var text []byte for i := 0; i <= end; i++ { printableChar := byte(32 + x.rand.Int31n(95)) text = append(text, printableChar) } f.SetString(string(text)) }
SetPrintableASCII returns a Setter which sets a home domain string32 with a random printable ascii string
func SetVecLen ¶
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