func WithNoEntropyCompression(b bool) EOption {
	return func(o *encoderOptions) error {
		o.noEntropy = b
		return nil
	}
}
WithNoEntropyCompression will always skip entropy compression of literals.
This can be useful if content has matches, but unlikely to benefit from entropy
compression. Usually the slight speed improvement is not worth enabling this.
package zstd
import (
	"errors"
	"fmt"
	"runtime"
	"strings"
)
type EOption func(*encoderOptions) error
type encoderOptions struct {
	concurrent int
	crc        bool
	single     *bool
	pad        int
	blockSize  int
	windowSize int
	level      EncoderLevel
	fullZero   bool
	noEntropy  bool
}
func (o *encoderOptions) setDefault() {
	*o = encoderOptions{
		concurrent: runtime.GOMAXPROCS(0),
		crc:        true,
		single:     nil,
		blockSize:  1 << 16,
		windowSize: 1 << 22,
		level:      SpeedDefault,
	}
}
func (o encoderOptions) encoder() encoder {
	switch o.level {
	case SpeedDefault:
		return &doubleFastEncoder{fastEncoder: fastEncoder{maxMatchOff: int32(o.windowSize)}}
	case SpeedFastest:
		return &fastEncoder{maxMatchOff: int32(o.windowSize)}
	}
	panic("unknown compression level")
}
func WithEncoderCRC(b bool) EOption {
	return func(o *encoderOptions) error { o.crc = b; return nil }
}
func WithEncoderConcurrency(n int) EOption {
	return func(o *encoderOptions) error {
		if n <= 0 {
			return fmt.Errorf("concurrency must be at least 1")
		}
		o.concurrent = n
		return nil
	}
}
func WithWindowSize(n int) EOption {
	return func(o *encoderOptions) error {
		switch {
		case n < MinWindowSize:
			return fmt.Errorf("window size must be at least %d", MinWindowSize)
		case n > MaxWindowSize:
			return fmt.Errorf("window size must be at most %d", MaxWindowSize)
		case (n & (n - 1)) != 0:
			return errors.New("window size must be a power of 2")
		}
		o.windowSize = n
		if o.blockSize > o.windowSize {
			o.blockSize = o.windowSize
		}
		return nil
	}
}
func WithEncoderPadding(n int) EOption {
	return func(o *encoderOptions) error {
		if n <= 0 {
			return fmt.Errorf("padding must be at least 1")
		}
		if n == 1 {
			o.pad = 0
		}
		if n > 1<<30 {
			return fmt.Errorf("padding must less than 1GB (1<<30 bytes) ")
		}
		o.pad = n
		return nil
	}
}
type EncoderLevel int
const (
	speedNotSet EncoderLevel = iota
	SpeedFastest
	SpeedDefault
	speedLast
	SpeedBetterCompression = SpeedDefault
	SpeedBestCompression = SpeedDefault
)
func EncoderLevelFromString(s string) (bool, EncoderLevel) {
	for l := EncoderLevel(speedNotSet + 1); l < speedLast; l++ {
		if strings.EqualFold(s, l.String()) {
			return true, l
		}
	}
	return false, SpeedDefault
}
func EncoderLevelFromZstd(level int) EncoderLevel {
	switch {
	case level < 3:
		return SpeedFastest
	case level >= 3:
		return SpeedDefault
	}
	return SpeedDefault
}
func (e EncoderLevel) String() string {
	switch e {
	case SpeedFastest:
		return "fastest"
	case SpeedDefault:
		return "default"
	default:
		return "invalid"
	}
}
func WithEncoderLevel(l EncoderLevel) EOption {
	return func(o *encoderOptions) error {
		switch {
		case l <= speedNotSet || l >= speedLast:
			return fmt.Errorf("unknown encoder level")
		}
		o.level = l
		return nil
	}
}
func WithZeroFrames(b bool) EOption {
	return func(o *encoderOptions) error {
		o.fullZero = b
		return nil
	}
}