public-api/api/oas_uri_gen.go

540 lines
12 KiB
Go

// 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
}
// EncodeURI encodes RankFilter as URI form.
func (s *RankFilter) EncodeURI(e uri.Encoder) error {
if err := e.EncodeField("StyleID", func(e uri.Encoder) error {
if val, ok := s.StyleID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"StyleID\"")
}
if err := e.EncodeField("GameID", func(e uri.Encoder) error {
if val, ok := s.GameID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"GameID\"")
}
if err := e.EncodeField("ModeID", func(e uri.Encoder) error {
if val, ok := s.ModeID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"ModeID\"")
}
if err := e.EncodeField("Sort", func(e uri.Encoder) error {
if val, ok := s.Sort.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"Sort\"")
}
return nil
}
var uriFieldsNameOfRankFilter = [4]string{
0: "StyleID",
1: "GameID",
2: "ModeID",
3: "Sort",
}
// DecodeURI decodes RankFilter from URI form.
func (s *RankFilter) DecodeURI(d uri.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RankFilter to nil")
}
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
switch k {
case "StyleID":
if err := func() error {
var sDotStyleIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotStyleIDVal = c
return nil
}(); err != nil {
return err
}
s.StyleID.SetTo(sDotStyleIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "GameID":
if err := func() error {
var sDotGameIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotGameIDVal = c
return nil
}(); err != nil {
return err
}
s.GameID.SetTo(sDotGameIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
case "ModeID":
if err := func() error {
var sDotModeIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotModeIDVal = c
return nil
}(); err != nil {
return err
}
s.ModeID.SetTo(sDotModeIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
}
case "Sort":
if err := func() error {
var sDotSortVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotSortVal = c
return nil
}(); err != nil {
return err
}
s.Sort.SetTo(sDotSortVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Sort\"")
}
default:
return nil
}
return nil
}); err != nil {
return errors.Wrap(err, "decode RankFilter")
}
return nil
}
// EncodeURI encodes TimeFilter as URI form.
func (s *TimeFilter) EncodeURI(e uri.Encoder) error {
if err := e.EncodeField("ID", func(e uri.Encoder) error {
if val, ok := s.ID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"ID\"")
}
if err := e.EncodeField("Time", func(e uri.Encoder) error {
if val, ok := s.Time.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"Time\"")
}
if err := e.EncodeField("UserID", func(e uri.Encoder) error {
if val, ok := s.UserID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"UserID\"")
}
if err := e.EncodeField("MapID", func(e uri.Encoder) error {
if val, ok := s.MapID.Get(); ok {
return e.EncodeValue(conv.Int64ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"MapID\"")
}
if err := e.EncodeField("StyleID", func(e uri.Encoder) error {
if val, ok := s.StyleID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"StyleID\"")
}
if err := e.EncodeField("ModeID", func(e uri.Encoder) error {
if val, ok := s.ModeID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"ModeID\"")
}
if err := e.EncodeField("GameID", func(e uri.Encoder) error {
if val, ok := s.GameID.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode field \"GameID\"")
}
return nil
}
var uriFieldsNameOfTimeFilter = [7]string{
0: "ID",
1: "Time",
2: "UserID",
3: "MapID",
4: "StyleID",
5: "ModeID",
6: "GameID",
}
// DecodeURI decodes TimeFilter from URI form.
func (s *TimeFilter) DecodeURI(d uri.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode TimeFilter to nil")
}
if err := d.DecodeFields(func(k string, d uri.Decoder) error {
switch k {
case "ID":
if err := func() error {
var sDotIDVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotIDVal = c
return nil
}(); err != nil {
return err
}
s.ID.SetTo(sDotIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ID\"")
}
case "Time":
if err := func() error {
var sDotTimeVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotTimeVal = c
return nil
}(); err != nil {
return err
}
s.Time.SetTo(sDotTimeVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"Time\"")
}
case "UserID":
if err := func() error {
var sDotUserIDVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotUserIDVal = c
return nil
}(); err != nil {
return err
}
s.UserID.SetTo(sDotUserIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"UserID\"")
}
case "MapID":
if err := func() error {
var sDotMapIDVal int64
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt64(val)
if err != nil {
return err
}
sDotMapIDVal = c
return nil
}(); err != nil {
return err
}
s.MapID.SetTo(sDotMapIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"MapID\"")
}
case "StyleID":
if err := func() error {
var sDotStyleIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotStyleIDVal = c
return nil
}(); err != nil {
return err
}
s.StyleID.SetTo(sDotStyleIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"StyleID\"")
}
case "ModeID":
if err := func() error {
var sDotModeIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotModeIDVal = c
return nil
}(); err != nil {
return err
}
s.ModeID.SetTo(sDotModeIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"ModeID\"")
}
case "GameID":
if err := func() error {
var sDotGameIDVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
sDotGameIDVal = c
return nil
}(); err != nil {
return err
}
s.GameID.SetTo(sDotGameIDVal)
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"GameID\"")
}
default:
return nil
}
return nil
}); err != nil {
return errors.Wrap(err, "decode TimeFilter")
}
return nil
}