2024-11-26 01:22:45 +00:00
|
|
|
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/bits"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/go-faster/errors"
|
|
|
|
|
|
|
|
"github.com/ogen-go/ogen/conv"
|
|
|
|
"github.com/ogen-go/ogen/uri"
|
|
|
|
"github.com/ogen-go/ogen/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EncodeURI encodes Pagination as URI form.
|
|
|
|
func (s *Pagination) EncodeURI(e uri.Encoder) error {
|
|
|
|
if err := e.EncodeField("Page", func(e uri.Encoder) error {
|
|
|
|
return e.EncodeValue(conv.Int32ToString(s.Page))
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "encode field \"Page\"")
|
|
|
|
}
|
|
|
|
if err := e.EncodeField("Limit", func(e uri.Encoder) error {
|
|
|
|
return e.EncodeValue(conv.Int32ToString(s.Limit))
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "encode field \"Limit\"")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var uriFieldsNameOfPagination = [2]string{
|
|
|
|
0: "Page",
|
|
|
|
1: "Limit",
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeURI decodes Pagination from URI form.
|
|
|
|
func (s *Pagination) DecodeURI(d uri.Decoder) error {
|
|
|
|
if s == nil {
|
|
|
|
return errors.New("invalid: unable to decode Pagination to nil")
|
|
|
|
}
|
|
|
|
var requiredBitSet [1]uint8
|
|
|
|
|
|
|
|
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
|
|
|
|
switch k {
|
|
|
|
case "Page":
|
|
|
|
requiredBitSet[0] |= 1 << 0
|
|
|
|
if err := func() error {
|
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := conv.ToInt32(val)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Page = c
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"Page\"")
|
|
|
|
}
|
|
|
|
case "Limit":
|
|
|
|
requiredBitSet[0] |= 1 << 1
|
|
|
|
if err := func() error {
|
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := conv.ToInt32(val)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Limit = c
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"Limit\"")
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "decode Pagination")
|
|
|
|
}
|
|
|
|
// Validate required fields.
|
|
|
|
var failures []validate.FieldError
|
|
|
|
for i, mask := range [1]uint8{
|
|
|
|
0b00000011,
|
|
|
|
} {
|
|
|
|
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
|
|
|
// Mask only required fields and check equality to mask using XOR.
|
|
|
|
//
|
|
|
|
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
|
|
|
|
// Bits of fields which would be set are actually bits of missed fields.
|
|
|
|
missed := bits.OnesCount8(result)
|
|
|
|
for bitN := 0; bitN < missed; bitN++ {
|
|
|
|
bitIdx := bits.TrailingZeros8(result)
|
|
|
|
fieldIdx := i*8 + bitIdx
|
|
|
|
var name string
|
|
|
|
if fieldIdx < len(uriFieldsNameOfPagination) {
|
|
|
|
name = uriFieldsNameOfPagination[fieldIdx]
|
|
|
|
} else {
|
|
|
|
name = strconv.Itoa(fieldIdx)
|
|
|
|
}
|
|
|
|
failures = append(failures, validate.FieldError{
|
|
|
|
Name: name,
|
|
|
|
Error: validate.ErrFieldRequired,
|
|
|
|
})
|
|
|
|
// Reset bit.
|
|
|
|
result &^= 1 << bitIdx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(failures) > 0 {
|
|
|
|
return &validate.Error{Fields: failures}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
// EncodeURI encodes SubmissionFilter as URI form.
|
|
|
|
func (s *SubmissionFilter) EncodeURI(e uri.Encoder) error {
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := e.EncodeField("ID", func(e uri.Encoder) error {
|
2024-12-06 00:36:15 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(s.ID))
|
2024-11-26 01:22:45 +00:00
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "encode field \"ID\"")
|
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
if err := e.EncodeField("DisplayName", func(e uri.Encoder) error {
|
|
|
|
if val, ok := s.DisplayName.Get(); ok {
|
|
|
|
return e.EncodeValue(conv.StringToString(val))
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "encode field \"DisplayName\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
if err := e.EncodeField("Creator", func(e uri.Encoder) error {
|
|
|
|
if val, ok := s.Creator.Get(); ok {
|
|
|
|
return e.EncodeValue(conv.StringToString(val))
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "encode field \"Creator\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
if err := e.EncodeField("GameID", func(e uri.Encoder) error {
|
|
|
|
if val, ok := s.GameID.Get(); ok {
|
2024-11-26 01:22:45 +00:00
|
|
|
return e.EncodeValue(conv.Int32ToString(val))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "encode field \"GameID\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-12-10 06:27:52 +00:00
|
|
|
var uriFieldsNameOfSubmissionFilter = [4]string{
|
2024-11-26 01:22:45 +00:00
|
|
|
0: "ID",
|
2024-11-26 20:39:10 +00:00
|
|
|
1: "DisplayName",
|
|
|
|
2: "Creator",
|
|
|
|
3: "GameID",
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
// DecodeURI decodes SubmissionFilter from URI form.
|
|
|
|
func (s *SubmissionFilter) DecodeURI(d uri.Decoder) error {
|
2024-11-26 01:22:45 +00:00
|
|
|
if s == nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.New("invalid: unable to decode SubmissionFilter to nil")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-11-26 01:22:45 +00:00
|
|
|
|
|
|
|
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
|
|
|
|
switch k {
|
|
|
|
case "ID":
|
2024-12-06 00:36:15 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
2024-12-06 00:36:15 +00:00
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-11-26 01:22:45 +00:00
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
c, err := conv.ToInt64(val)
|
|
|
|
if err != nil {
|
2024-11-26 01:22:45 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
|
|
|
|
s.ID = c
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"ID\"")
|
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
case "DisplayName":
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
2024-11-26 20:39:10 +00:00
|
|
|
var sDotDisplayNameVal string
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
c, err := conv.ToString(val)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
sDotDisplayNameVal = c
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
s.DisplayName.SetTo(sDotDisplayNameVal)
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "decode field \"DisplayName\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
case "Creator":
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
2024-11-26 20:39:10 +00:00
|
|
|
var sDotCreatorVal string
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
c, err := conv.ToString(val)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
sDotCreatorVal = c
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
s.Creator.SetTo(sDotCreatorVal)
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "decode field \"Creator\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
case "GameID":
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
2024-11-26 20:39:10 +00:00
|
|
|
var sDotGameIDVal int32
|
2024-11-26 01:22:45 +00:00
|
|
|
if err := func() error {
|
|
|
|
val, err := d.DecodeValue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := conv.ToInt32(val)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
sDotGameIDVal = c
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
s.GameID.SetTo(sDotGameIDVal)
|
2024-11-26 01:22:45 +00:00
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "decode field \"GameID\"")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
2024-11-26 20:39:10 +00:00
|
|
|
return errors.Wrap(err, "decode SubmissionFilter")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
// Validate required fields.
|
|
|
|
var failures []validate.FieldError
|
|
|
|
for i, mask := range [1]uint8{
|
|
|
|
0b00000001,
|
|
|
|
} {
|
|
|
|
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
|
|
|
// Mask only required fields and check equality to mask using XOR.
|
|
|
|
//
|
|
|
|
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
|
|
|
|
// Bits of fields which would be set are actually bits of missed fields.
|
|
|
|
missed := bits.OnesCount8(result)
|
|
|
|
for bitN := 0; bitN < missed; bitN++ {
|
|
|
|
bitIdx := bits.TrailingZeros8(result)
|
|
|
|
fieldIdx := i*8 + bitIdx
|
|
|
|
var name string
|
|
|
|
if fieldIdx < len(uriFieldsNameOfSubmissionFilter) {
|
|
|
|
name = uriFieldsNameOfSubmissionFilter[fieldIdx]
|
|
|
|
} else {
|
|
|
|
name = strconv.Itoa(fieldIdx)
|
|
|
|
}
|
|
|
|
failures = append(failures, validate.FieldError{
|
|
|
|
Name: name,
|
|
|
|
Error: validate.ErrFieldRequired,
|
|
|
|
})
|
|
|
|
// Reset bit.
|
|
|
|
result &^= 1 << bitIdx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(failures) > 0 {
|
|
|
|
return &validate.Error{Fields: failures}
|
|
|
|
}
|
2024-11-26 01:22:45 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|