BytesRules describe the rules applied to bytes values. These rules
may also be applied to the google.protobuf.BytesValue Well-Known-Type.
BytesRules describe the rules applied to bytes values. These rules
may also be applied to the google.protobuf.BytesValue Well-Known-Type.
Optional[customReturns a safe value for JSON logs.
Returns a safe value for JSON logs.
Optional[unknownPreserves protobuf fields that this SDK version does not recognize.
Contains the fully qualified protobuf type name.
Optionalconstconst requires the field value to exactly match the specified bytes
value. If the field value doesn't match, an error message is generated.
message MyBytes {
// value must be "\x01\x02\x03\x04"
bytes value = 1 [(buf.validate.field).bytes.const = "\x01\x02\x03\x04"];
}
Optionalcontainscontains requires the field value to have the specified bytes anywhere in
the string.
If the field value doesn't meet the requirement, an error message is generated.
message MyBytes {
// value does not contain \x02\x03
optional bytes value = 1 [(buf.validate.field).bytes.contains = "\x02\x03"];
}
example specifies values that the field may have. These values SHOULD
conform to other rules. example values will not impact validation
but may be used as helpful guidance on how to populate the given field.
message MyBytes {
bytes value = 1 [
(buf.validate.field).bytes.example = "\x01\x02",
(buf.validate.field).bytes.example = "\x02\x03"
];
}
in requires the field value to be equal to one of the specified
values. If the field value doesn't match any of the specified values, an
error message is generated.
message MyBytes {
// value must in ["\x01\x02", "\x02\x03", "\x03\x04"]
optional bytes value = 1 [(buf.validate.field).bytes.in = {"\x01\x02", "\x02\x03", "\x03\x04"}];
}
Optionallenlen requires the field value to have the specified length in bytes.
If the field value doesn't match, an error message is generated.
message MyBytes {
// value length must be 4 bytes.
optional bytes value = 1 [(buf.validate.field).bytes.len = 4];
}
Optionalmaxmax_len requires the field value to have at most the specified maximum
length in bytes.
If the field value exceeds the requirement, an error message is generated.
message MyBytes {
// value must be at most 6 bytes.
optional bytes value = 1 [(buf.validate.field).bytes.max_len = 6];
}
Optionalminmin_len requires the field value to have at least the specified minimum
length in bytes.
If the field value doesn't meet the requirement, an error message is generated.
message MyBytes {
// value length must be at least 2 bytes.
optional bytes value = 1 [(buf.validate.field).bytes.min_len = 2];
}
not_in requires the field value to be not equal to any of the specified
values.
If the field value matches any of the specified values, an error message is
generated.
message MyBytes {
// value must not in ["\x01\x02", "\x02\x03", "\x03\x04"]
optional bytes value = 1 [(buf.validate.field).bytes.not_in = {"\x01\x02", "\x02\x03", "\x03\x04"}];
}
Optionalpatternpattern requires the field value to match the specified regular
expression (RE2 syntax).
The value of the field must be valid UTF-8 or validation will fail with a
runtime error.
If the field value doesn't match the pattern, an error message is generated.
message MyBytes {
// value must match regex pattern "^[a-zA-Z0-9]+$".
optional bytes value = 1 [(buf.validate.field).bytes.pattern = "^[a-zA-Z0-9]+$"];
}
Optionalprefixprefix requires the field value to have the specified bytes at the
beginning of the string.
If the field value doesn't meet the requirement, an error message is generated.
message MyBytes {
// value does not have prefix \x01\x02
optional bytes value = 1 [(buf.validate.field).bytes.prefix = "\x01\x02"];
}
Optionalsuffixsuffix requires the field value to have the specified bytes at the end
of the string.
If the field value doesn't meet the requirement, an error message is generated.
message MyBytes {
// value does not have suffix \x03\x04
optional bytes value = 1 [(buf.validate.field).bytes.suffix = "\x03\x04"];
}
OptionalwellWellKnown rules provide advanced rules against common byte patterns
Contains the case.
Contains the ip.
Contains the case.
Contains the ipv4.
Contains the case.
Contains the ipv6.
Contains the case.
Contains the uuid.
BytesRules describe the rules applied to
bytesvalues. These rules may also be applied to thegoogle.protobuf.BytesValueWell-Known-Type.