2024-02-01 18:57:25 +00:00
|
|
|
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
|
2024-02-01 22:09:09 +00:00
|
|
|
package openapi
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-01 22:09:09 +00:00
|
|
|
"math/bits"
|
|
|
|
"strconv"
|
|
|
|
|
2024-02-01 18:57:25 +00:00
|
|
|
"github.com/go-faster/errors"
|
|
|
|
"github.com/go-faster/jx"
|
2024-02-01 22:09:09 +00:00
|
|
|
|
|
|
|
"github.com/ogen-go/ogen/validate"
|
2024-02-01 18:57:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("message")
|
|
|
|
e.Str(s.Message)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("code")
|
|
|
|
e.Int(s.Code)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "message":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Message = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"message\"")
|
|
|
|
}
|
|
|
|
case "code":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 1
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Int()
|
|
|
|
s.Code = int(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
// 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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("id")
|
|
|
|
s.ID.Encode(e)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("name")
|
|
|
|
e.Str(s.Name)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-02 14:39:13 +00:00
|
|
|
e.FieldStart("user_ids")
|
2024-02-01 22:09:09 +00:00
|
|
|
e.ArrStart()
|
2024-02-02 14:39:13 +00:00
|
|
|
for _, elem := range s.UserIds {
|
2024-02-01 22:09:09 +00:00
|
|
|
elem.Encode(e)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
e.ArrEnd()
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var jsonFieldsNameOfGroup = [3]string{
|
|
|
|
0: "id",
|
|
|
|
1: "name",
|
2024-02-02 14:39:13 +00:00
|
|
|
2: "user_ids",
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "id":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
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":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 1
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Name = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
|
|
}
|
2024-02-02 14:39:13 +00:00
|
|
|
case "user_ids":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 2
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-02 14:39:13 +00:00
|
|
|
s.UserIds = make([]ID, 0)
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := d.Arr(func(d *jx.Decoder) error {
|
2024-02-02 14:39:13 +00:00
|
|
|
var elem ID
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := elem.Decode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-02-02 14:39:13 +00:00
|
|
|
s.UserIds = append(s.UserIds, elem)
|
2024-02-01 18:57:25 +00:00
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
2024-02-02 14:39:13 +00:00
|
|
|
return errors.Wrap(err, "decode field \"user_ids\"")
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return d.Skip()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "decode Group")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
// 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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("name")
|
|
|
|
e.Str(s.Name)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "name":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Name = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +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(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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("message")
|
|
|
|
e.Str(s.Message)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "message":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Message = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
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")
|
|
|
|
}
|
2024-02-01 22:09:09 +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(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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("id")
|
|
|
|
s.ID.Encode(e)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("name")
|
|
|
|
e.Str(s.Name)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("email")
|
|
|
|
e.Str(s.Email)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-02 14:39:13 +00:00
|
|
|
e.FieldStart("group_id")
|
|
|
|
s.GroupID.Encode(e)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var jsonFieldsNameOfUser = [4]string{
|
|
|
|
0: "id",
|
|
|
|
1: "name",
|
|
|
|
2: "email",
|
2024-02-02 14:39:13 +00:00
|
|
|
3: "group_id",
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "id":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
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":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 1
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Name = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
|
|
}
|
|
|
|
case "email":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 2
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Email = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"email\"")
|
|
|
|
}
|
2024-02-02 14:39:13 +00:00
|
|
|
case "group_id":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 3
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-02 14:39:13 +00:00
|
|
|
if err := s.GroupID.Decode(d); err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
2024-02-02 14:39:13 +00:00
|
|
|
return errors.Wrap(err, "decode field \"group_id\"")
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return d.Skip()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "decode User")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
// 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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("name")
|
|
|
|
e.Str(s.Name)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
{
|
2024-02-01 22:09:09 +00:00
|
|
|
e.FieldStart("email")
|
|
|
|
e.Str(s.Email)
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
2024-02-02 14:39:13 +00:00
|
|
|
{
|
|
|
|
e.FieldStart("group_id")
|
|
|
|
s.GroupID.Encode(e)
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 14:39:13 +00:00
|
|
|
var jsonFieldsNameOfUserUpdate = [3]string{
|
2024-02-01 18:57:25 +00:00
|
|
|
0: "name",
|
|
|
|
1: "email",
|
2024-02-02 14:39:13 +00:00
|
|
|
2: "group_id",
|
2024-02-01 18:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
var requiredBitSet [1]uint8
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
|
|
|
switch string(k) {
|
|
|
|
case "name":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 0
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Name = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"name\"")
|
|
|
|
}
|
|
|
|
case "email":
|
2024-02-01 22:09:09 +00:00
|
|
|
requiredBitSet[0] |= 1 << 1
|
2024-02-01 18:57:25 +00:00
|
|
|
if err := func() error {
|
2024-02-01 22:09:09 +00:00
|
|
|
v, err := d.Str()
|
|
|
|
s.Email = string(v)
|
|
|
|
if err != nil {
|
2024-02-01 18:57:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}(); err != nil {
|
|
|
|
return errors.Wrap(err, "decode field \"email\"")
|
|
|
|
}
|
2024-02-02 14:39:13 +00:00
|
|
|
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\"")
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
default:
|
|
|
|
return d.Skip()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return errors.Wrap(err, "decode UserUpdate")
|
|
|
|
}
|
2024-02-01 22:09:09 +00:00
|
|
|
// Validate required fields.
|
|
|
|
var failures []validate.FieldError
|
|
|
|
for i, mask := range [1]uint8{
|
2024-02-02 14:39:13 +00:00
|
|
|
0b00000111,
|
2024-02-01 22:09:09 +00:00
|
|
|
} {
|
|
|
|
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}
|
|
|
|
}
|
2024-02-01 18:57:25 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|