767 lines
17 KiB
Go
767 lines
17 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package openapi
|
|
|
|
import (
|
|
"math/bits"
|
|
"strconv"
|
|
|
|
"github.com/go-faster/errors"
|
|
"github.com/go-faster/jx"
|
|
|
|
"github.com/ogen-go/ogen/validate"
|
|
)
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *Error) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *Error) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("message")
|
|
e.Str(s.Message)
|
|
}
|
|
{
|
|
e.FieldStart("code")
|
|
e.Int(s.Code)
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfError = [2]string{
|
|
0: "message",
|
|
1: "code",
|
|
}
|
|
|
|
// Decode decodes Error from json.
|
|
func (s *Error) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode Error to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "message":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Message = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"message\"")
|
|
}
|
|
case "code":
|
|
requiredBitSet[0] |= 1 << 1
|
|
if err := func() error {
|
|
v, err := d.Int()
|
|
s.Code = int(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"code\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode Error")
|
|
}
|
|
// 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(jsonFieldsNameOfError) {
|
|
name = jsonFieldsNameOfError[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *Error) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *Error) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *Group) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *Group) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("id")
|
|
s.ID.Encode(e)
|
|
}
|
|
{
|
|
e.FieldStart("name")
|
|
e.Str(s.Name)
|
|
}
|
|
{
|
|
e.FieldStart("user_ids")
|
|
e.ArrStart()
|
|
for _, elem := range s.UserIds {
|
|
elem.Encode(e)
|
|
}
|
|
e.ArrEnd()
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfGroup = [3]string{
|
|
0: "id",
|
|
1: "name",
|
|
2: "user_ids",
|
|
}
|
|
|
|
// Decode decodes Group from json.
|
|
func (s *Group) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode Group to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "id":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
if err := s.ID.Decode(d); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"id\"")
|
|
}
|
|
case "name":
|
|
requiredBitSet[0] |= 1 << 1
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Name = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
}
|
|
case "user_ids":
|
|
requiredBitSet[0] |= 1 << 2
|
|
if err := func() error {
|
|
s.UserIds = make([]ID, 0)
|
|
if err := d.Arr(func(d *jx.Decoder) error {
|
|
var elem ID
|
|
if err := elem.Decode(d); err != nil {
|
|
return err
|
|
}
|
|
s.UserIds = append(s.UserIds, elem)
|
|
return nil
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"user_ids\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode Group")
|
|
}
|
|
// Validate required fields.
|
|
var failures []validate.FieldError
|
|
for i, mask := range [1]uint8{
|
|
0b00000111,
|
|
} {
|
|
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(jsonFieldsNameOfGroup) {
|
|
name = jsonFieldsNameOfGroup[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *Group) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *Group) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *GroupUpdate) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *GroupUpdate) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("name")
|
|
e.Str(s.Name)
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfGroupUpdate = [1]string{
|
|
0: "name",
|
|
}
|
|
|
|
// Decode decodes GroupUpdate from json.
|
|
func (s *GroupUpdate) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode GroupUpdate to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "name":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Name = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode GroupUpdate")
|
|
}
|
|
// 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(jsonFieldsNameOfGroupUpdate) {
|
|
name = jsonFieldsNameOfGroupUpdate[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *GroupUpdate) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *GroupUpdate) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode encodes ID as json.
|
|
func (s ID) Encode(e *jx.Encoder) {
|
|
unwrapped := int64(s)
|
|
|
|
e.Int64(unwrapped)
|
|
}
|
|
|
|
// Decode decodes ID from json.
|
|
func (s *ID) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode ID to nil")
|
|
}
|
|
var unwrapped int64
|
|
if err := func() error {
|
|
v, err := d.Int64()
|
|
unwrapped = int64(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "alias")
|
|
}
|
|
*s = ID(unwrapped)
|
|
return nil
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s ID) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *ID) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *Ok) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *Ok) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("message")
|
|
e.Str(s.Message)
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfOk = [1]string{
|
|
0: "message",
|
|
}
|
|
|
|
// Decode decodes Ok from json.
|
|
func (s *Ok) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode Ok to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "message":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Message = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"message\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode Ok")
|
|
}
|
|
// 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(jsonFieldsNameOfOk) {
|
|
name = jsonFieldsNameOfOk[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *Ok) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *Ok) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *User) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *User) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("id")
|
|
s.ID.Encode(e)
|
|
}
|
|
{
|
|
e.FieldStart("name")
|
|
e.Str(s.Name)
|
|
}
|
|
{
|
|
e.FieldStart("email")
|
|
e.Str(s.Email)
|
|
}
|
|
{
|
|
e.FieldStart("group_id")
|
|
s.GroupID.Encode(e)
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfUser = [4]string{
|
|
0: "id",
|
|
1: "name",
|
|
2: "email",
|
|
3: "group_id",
|
|
}
|
|
|
|
// Decode decodes User from json.
|
|
func (s *User) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode User to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "id":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
if err := s.ID.Decode(d); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"id\"")
|
|
}
|
|
case "name":
|
|
requiredBitSet[0] |= 1 << 1
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Name = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
}
|
|
case "email":
|
|
requiredBitSet[0] |= 1 << 2
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Email = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"email\"")
|
|
}
|
|
case "group_id":
|
|
requiredBitSet[0] |= 1 << 3
|
|
if err := func() error {
|
|
if err := s.GroupID.Decode(d); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"group_id\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode User")
|
|
}
|
|
// Validate required fields.
|
|
var failures []validate.FieldError
|
|
for i, mask := range [1]uint8{
|
|
0b00001111,
|
|
} {
|
|
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(jsonFieldsNameOfUser) {
|
|
name = jsonFieldsNameOfUser[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *User) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *User) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|
|
|
|
// Encode implements json.Marshaler.
|
|
func (s *UserUpdate) Encode(e *jx.Encoder) {
|
|
e.ObjStart()
|
|
s.encodeFields(e)
|
|
e.ObjEnd()
|
|
}
|
|
|
|
// encodeFields encodes fields.
|
|
func (s *UserUpdate) encodeFields(e *jx.Encoder) {
|
|
{
|
|
e.FieldStart("name")
|
|
e.Str(s.Name)
|
|
}
|
|
{
|
|
e.FieldStart("email")
|
|
e.Str(s.Email)
|
|
}
|
|
{
|
|
e.FieldStart("group_id")
|
|
s.GroupID.Encode(e)
|
|
}
|
|
}
|
|
|
|
var jsonFieldsNameOfUserUpdate = [3]string{
|
|
0: "name",
|
|
1: "email",
|
|
2: "group_id",
|
|
}
|
|
|
|
// Decode decodes UserUpdate from json.
|
|
func (s *UserUpdate) Decode(d *jx.Decoder) error {
|
|
if s == nil {
|
|
return errors.New("invalid: unable to decode UserUpdate to nil")
|
|
}
|
|
var requiredBitSet [1]uint8
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
switch string(k) {
|
|
case "name":
|
|
requiredBitSet[0] |= 1 << 0
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Name = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
}
|
|
case "email":
|
|
requiredBitSet[0] |= 1 << 1
|
|
if err := func() error {
|
|
v, err := d.Str()
|
|
s.Email = string(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"email\"")
|
|
}
|
|
case "group_id":
|
|
requiredBitSet[0] |= 1 << 2
|
|
if err := func() error {
|
|
if err := s.GroupID.Decode(d); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}(); err != nil {
|
|
return errors.Wrap(err, "decode field \"group_id\"")
|
|
}
|
|
default:
|
|
return d.Skip()
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return errors.Wrap(err, "decode UserUpdate")
|
|
}
|
|
// Validate required fields.
|
|
var failures []validate.FieldError
|
|
for i, mask := range [1]uint8{
|
|
0b00000111,
|
|
} {
|
|
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(jsonFieldsNameOfUserUpdate) {
|
|
name = jsonFieldsNameOfUserUpdate[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
|
|
}
|
|
|
|
// MarshalJSON implements stdjson.Marshaler.
|
|
func (s *UserUpdate) MarshalJSON() ([]byte, error) {
|
|
e := jx.Encoder{}
|
|
s.Encode(&e)
|
|
return e.Bytes(), nil
|
|
}
|
|
|
|
// UnmarshalJSON implements stdjson.Unmarshaler.
|
|
func (s *UserUpdate) UnmarshalJSON(data []byte) error {
|
|
d := jx.DecodeBytes(data)
|
|
return s.Decode(d)
|
|
}
|