github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/extensions/compression/brotli/compressor/v3/brotli.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/extensions/compression/brotli/compressor/v3/brotli.proto
     3  
     4  package envoy_extensions_compression_brotli_compressor_v3
     5  
     6  import (
     7  	"bytes"
     8  	"errors"
     9  	"fmt"
    10  	"net"
    11  	"net/mail"
    12  	"net/url"
    13  	"regexp"
    14  	"strings"
    15  	"time"
    16  	"unicode/utf8"
    17  
    18  	"google.golang.org/protobuf/types/known/anypb"
    19  )
    20  
    21  // ensure the imports are used
    22  var (
    23  	_ = bytes.MinRead
    24  	_ = errors.New("")
    25  	_ = fmt.Print
    26  	_ = utf8.UTFMax
    27  	_ = (*regexp.Regexp)(nil)
    28  	_ = (*strings.Reader)(nil)
    29  	_ = net.IPv4len
    30  	_ = time.Duration(0)
    31  	_ = (*url.URL)(nil)
    32  	_ = (*mail.Address)(nil)
    33  	_ = anypb.Any{}
    34  )
    35  
    36  // Validate checks the field values on Brotli with the rules defined in the
    37  // proto definition for this message. If any rules are violated, an error is returned.
    38  func (m *Brotli) Validate() error {
    39  	if m == nil {
    40  		return nil
    41  	}
    42  
    43  	if wrapper := m.GetQuality(); wrapper != nil {
    44  
    45  		if wrapper.GetValue() > 11 {
    46  			return BrotliValidationError{
    47  				field:  "Quality",
    48  				reason: "value must be less than or equal to 11",
    49  			}
    50  		}
    51  
    52  	}
    53  
    54  	if _, ok := Brotli_EncoderMode_name[int32(m.GetEncoderMode())]; !ok {
    55  		return BrotliValidationError{
    56  			field:  "EncoderMode",
    57  			reason: "value must be one of the defined enum values",
    58  		}
    59  	}
    60  
    61  	if wrapper := m.GetWindowBits(); wrapper != nil {
    62  
    63  		if val := wrapper.GetValue(); val < 10 || val > 24 {
    64  			return BrotliValidationError{
    65  				field:  "WindowBits",
    66  				reason: "value must be inside range [10, 24]",
    67  			}
    68  		}
    69  
    70  	}
    71  
    72  	if wrapper := m.GetInputBlockBits(); wrapper != nil {
    73  
    74  		if val := wrapper.GetValue(); val < 16 || val > 24 {
    75  			return BrotliValidationError{
    76  				field:  "InputBlockBits",
    77  				reason: "value must be inside range [16, 24]",
    78  			}
    79  		}
    80  
    81  	}
    82  
    83  	if wrapper := m.GetChunkSize(); wrapper != nil {
    84  
    85  		if val := wrapper.GetValue(); val < 4096 || val > 65536 {
    86  			return BrotliValidationError{
    87  				field:  "ChunkSize",
    88  				reason: "value must be inside range [4096, 65536]",
    89  			}
    90  		}
    91  
    92  	}
    93  
    94  	// no validation rules for DisableLiteralContextModeling
    95  
    96  	return nil
    97  }
    98  
    99  // BrotliValidationError is the validation error returned by Brotli.Validate if
   100  // the designated constraints aren't met.
   101  type BrotliValidationError struct {
   102  	field  string
   103  	reason string
   104  	cause  error
   105  	key    bool
   106  }
   107  
   108  // Field function returns field value.
   109  func (e BrotliValidationError) Field() string { return e.field }
   110  
   111  // Reason function returns reason value.
   112  func (e BrotliValidationError) Reason() string { return e.reason }
   113  
   114  // Cause function returns cause value.
   115  func (e BrotliValidationError) Cause() error { return e.cause }
   116  
   117  // Key function returns key value.
   118  func (e BrotliValidationError) Key() bool { return e.key }
   119  
   120  // ErrorName returns error name.
   121  func (e BrotliValidationError) ErrorName() string { return "BrotliValidationError" }
   122  
   123  // Error satisfies the builtin error interface
   124  func (e BrotliValidationError) Error() string {
   125  	cause := ""
   126  	if e.cause != nil {
   127  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   128  	}
   129  
   130  	key := ""
   131  	if e.key {
   132  		key = "key for "
   133  	}
   134  
   135  	return fmt.Sprintf(
   136  		"invalid %sBrotli.%s: %s%s",
   137  		key,
   138  		e.field,
   139  		e.reason,
   140  		cause)
   141  }
   142  
   143  var _ error = BrotliValidationError{}
   144  
   145  var _ interface {
   146  	Field() string
   147  	Reason() string
   148  	Key() bool
   149  	Cause() error
   150  	ErrorName() string
   151  } = BrotliValidationError{}