bytes.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package java
  2. const bytesConstTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  3. {{- if $r.Const }}
  4. private final com.google.protobuf.ByteString {{ constantName . "Const" }} = com.google.protobuf.ByteString.copyFrom({{ byteArrayLit $r.GetConst }});
  5. {{- end -}}
  6. {{- if $r.In }}
  7. private final com.google.protobuf.ByteString[] {{ constantName . "In" }} = new com.google.protobuf.ByteString[]{
  8. {{- range $r.In }}
  9. com.google.protobuf.ByteString.copyFrom({{ byteArrayLit . }}),
  10. {{- end }}
  11. };
  12. {{- end -}}
  13. {{- if $r.NotIn }}
  14. private final com.google.protobuf.ByteString[] {{ constantName . "NotIn" }} = new com.google.protobuf.ByteString[]{
  15. {{- range $r.NotIn }}
  16. com.google.protobuf.ByteString.copyFrom({{ byteArrayLit . }}),
  17. {{- end }}
  18. };
  19. {{- end -}}
  20. {{- if $r.Pattern }}
  21. private final com.google.re2j.Pattern {{ constantName . "Pattern" }} = com.google.re2j.Pattern.compile({{ javaStringEscape $r.GetPattern }});
  22. {{- end -}}
  23. {{- if $r.Prefix }}
  24. private final byte[] {{ constantName . "Prefix" }} = {{ byteArrayLit $r.GetPrefix }};
  25. {{- end -}}
  26. {{- if $r.Contains }}
  27. private final byte[] {{ constantName . "Contains" }} = {{ byteArrayLit $r.GetContains }};
  28. {{- end -}}
  29. {{- if $r.Suffix }}
  30. private final byte[] {{ constantName . "Suffix" }} = {{ byteArrayLit $r.GetSuffix }};
  31. {{- end -}}`
  32. const bytesTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  33. {{- if $r.GetIgnoreEmpty }}
  34. if ( !{{ accessor . }}.isEmpty() ) {
  35. {{- end -}}
  36. {{- if $r.Const }}
  37. io.envoyproxy.pgv.ConstantValidation.constant("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Const" }});
  38. {{- end -}}
  39. {{- if $r.Len }}
  40. io.envoyproxy.pgv.BytesValidation.length("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetLen }});
  41. {{- end -}}
  42. {{- if $r.MinLen }}
  43. io.envoyproxy.pgv.BytesValidation.minLength("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMinLen }});
  44. {{- end -}}
  45. {{- if $r.MaxLen }}
  46. io.envoyproxy.pgv.BytesValidation.maxLength("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMaxLen }});
  47. {{- end -}}
  48. {{- if $r.Pattern }}
  49. io.envoyproxy.pgv.BytesValidation.pattern("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Pattern" }});
  50. {{- end -}}
  51. {{- if $r.Prefix }}
  52. io.envoyproxy.pgv.BytesValidation.prefix("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Prefix" }});
  53. {{- end -}}
  54. {{- if $r.Contains }}
  55. io.envoyproxy.pgv.BytesValidation.contains("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Contains" }});
  56. {{- end -}}
  57. {{- if $r.Suffix }}
  58. io.envoyproxy.pgv.BytesValidation.suffix("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Suffix" }});
  59. {{- end -}}
  60. {{- if $r.GetIp }}
  61. io.envoyproxy.pgv.BytesValidation.ip("{{ $f.FullyQualifiedName }}", {{ accessor . }});
  62. {{- end -}}
  63. {{- if $r.GetIpv4 }}
  64. io.envoyproxy.pgv.BytesValidation.ipv4("{{ $f.FullyQualifiedName }}", {{ accessor . }});
  65. {{- end -}}
  66. {{- if $r.GetIpv6 }}
  67. io.envoyproxy.pgv.BytesValidation.ipv6("{{ $f.FullyQualifiedName }}", {{ accessor . }});
  68. {{- end -}}
  69. {{- if $r.In }}
  70. io.envoyproxy.pgv.CollectiveValidation.in("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "In" }});
  71. {{- end -}}
  72. {{- if $r.NotIn }}
  73. io.envoyproxy.pgv.CollectiveValidation.notIn("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "NotIn" }});
  74. {{- end -}}
  75. {{- if $r.GetIgnoreEmpty }}
  76. }
  77. {{- end -}}
  78. `