func (ar *ArrayRules) LexicalOrderWithoutDupsValidator() ElementValidationFunc {
	var prev []byte
	var prevIndex int
	return func(index int, next []byte) error {
		if prev == nil {
			prev = next
			prevIndex = index
			return nil
		}
		switch bytes.Compare(prev, next) {
		case 1:
			return fmt.Errorf("%w: element %d should have been before element %d", ErrArrayValidationOrderViolatesLexicalOrder, index, prevIndex)
		case 0:
			return fmt.Errorf("%w: element %d and %d are duplicates", ErrArrayValidationViolatesUniqueness, index, prevIndex)
		}
		prev = next
		prevIndex = index
		return nil
	}
}
LexicalOrderWithoutDupsValidator returns an ElementValidationFunc which returns an error if the given byte slices
are not ordered lexicographically or any elements are duplicated.
package serializer
import (
	"bytes"
	"encoding/json"
	"fmt"
	"sort"
)
type Serializable interface {
	json.Marshaler
	json.Unmarshaler
	Deserialize(data []byte, deSeriMode DeSerializationMode) (int, error)
	Serialize(deSeriMode DeSerializationMode) ([]byte, error)
}
type Serializables []Serializable
type SerializableSelectorFunc func(ty uint32) (Serializable, error)
type DeSerializationMode byte
const (
	DeSeriModeNoValidation DeSerializationMode = 0
	DeSeriModePerformValidation DeSerializationMode = 1 << 0
	DeSeriModePerformLexicalOrdering DeSerializationMode = 1 << 1
)
func (sm DeSerializationMode) HasMode(mode DeSerializationMode) bool {
	return sm&mode > 0
}
type ArrayValidationMode byte
const (
	ArrayValidationModeNone ArrayValidationMode = 0
	ArrayValidationModeNoDuplicates ArrayValidationMode = 1 << 0
	ArrayValidationModeLexicalOrdering ArrayValidationMode = 1 << 1
)
func (av ArrayValidationMode) HasMode(mode ArrayValidationMode) bool {
	return av&mode > 0
}
type ArrayRules struct {
	Min uint
	Max uint
	ValidationMode ArrayValidationMode
}
func (ar *ArrayRules) CheckBounds(count uint) error {
	if ar.Min != 0 && count < ar.Min {
		return fmt.Errorf("%w: min is %d but count is %d", ErrArrayValidationMinElementsNotReached, ar.Min, count)
	}
	if ar.Max != 0 && count > ar.Max {
		return fmt.Errorf("%w: max is %d but count is %d", ErrArrayValidationMaxElementsExceeded, ar.Max, count)
	}
	return nil
}
type ElementValidationFunc func(index int, next []byte) error
func (ar *ArrayRules) ElementUniqueValidator() ElementValidationFunc {
	set := map[string]int{}
	return func(index int, next []byte) error {
		k := string(next)
		if j, has := set[k]; has {
			return fmt.Errorf("%w: element %d and %d are duplicates", ErrArrayValidationViolatesUniqueness, j, index)
		}
		set[k] = index
		return nil
	}
}
func (ar *ArrayRules) LexicalOrderValidator() ElementValidationFunc {
	var prev []byte
	var prevIndex int
	return func(index int, next []byte) error {
		switch {
		case prev == nil:
			prev = next
			prevIndex = index
		case bytes.Compare(prev, next) > 0:
			return fmt.Errorf("%w: element %d should have been before element %d", ErrArrayValidationOrderViolatesLexicalOrder, index, prevIndex)
		default:
			prev = next
			prevIndex = index
		}
		return nil
	}
}