This commit is contained in:
parent
fe0a1e0e0f
commit
a28ec58ce8
@ -1307,12 +1307,6 @@ func (s *ScriptPolicyFilter) Encode(e *jx.Encoder) {
|
||||
|
||||
// encodeFields encodes fields.
|
||||
func (s *ScriptPolicyFilter) encodeFields(e *jx.Encoder) {
|
||||
{
|
||||
if s.ID.Set {
|
||||
e.FieldStart("ID")
|
||||
s.ID.Encode(e)
|
||||
}
|
||||
}
|
||||
{
|
||||
if s.FromScriptHash.Set {
|
||||
e.FieldStart("FromScriptHash")
|
||||
@ -1333,11 +1327,10 @@ func (s *ScriptPolicyFilter) encodeFields(e *jx.Encoder) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfScriptPolicyFilter = [4]string{
|
||||
0: "ID",
|
||||
1: "FromScriptHash",
|
||||
2: "ToScriptID",
|
||||
3: "Policy",
|
||||
var jsonFieldsNameOfScriptPolicyFilter = [3]string{
|
||||
0: "FromScriptHash",
|
||||
1: "ToScriptID",
|
||||
2: "Policy",
|
||||
}
|
||||
|
||||
// Decode decodes ScriptPolicyFilter from json.
|
||||
@ -1348,16 +1341,6 @@ func (s *ScriptPolicyFilter) Decode(d *jx.Decoder) error {
|
||||
|
||||
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
||||
switch string(k) {
|
||||
case "ID":
|
||||
if err := func() error {
|
||||
s.ID.Reset()
|
||||
if err := s.ID.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"ID\"")
|
||||
}
|
||||
case "FromScriptHash":
|
||||
if err := func() error {
|
||||
s.FromScriptHash.Reset()
|
||||
@ -2197,10 +2180,6 @@ func (s *SubmissionFilter) Encode(e *jx.Encoder) {
|
||||
|
||||
// encodeFields encodes fields.
|
||||
func (s *SubmissionFilter) encodeFields(e *jx.Encoder) {
|
||||
{
|
||||
e.FieldStart("ID")
|
||||
e.Int64(s.ID)
|
||||
}
|
||||
{
|
||||
if s.DisplayName.Set {
|
||||
e.FieldStart("DisplayName")
|
||||
@ -2221,11 +2200,10 @@ func (s *SubmissionFilter) encodeFields(e *jx.Encoder) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfSubmissionFilter = [4]string{
|
||||
0: "ID",
|
||||
1: "DisplayName",
|
||||
2: "Creator",
|
||||
3: "GameID",
|
||||
var jsonFieldsNameOfSubmissionFilter = [3]string{
|
||||
0: "DisplayName",
|
||||
1: "Creator",
|
||||
2: "GameID",
|
||||
}
|
||||
|
||||
// Decode decodes SubmissionFilter from json.
|
||||
@ -2233,22 +2211,9 @@ func (s *SubmissionFilter) Decode(d *jx.Decoder) error {
|
||||
if s == nil {
|
||||
return errors.New("invalid: unable to decode SubmissionFilter 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 {
|
||||
v, err := d.Int64()
|
||||
s.ID = int64(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"ID\"")
|
||||
}
|
||||
case "DisplayName":
|
||||
if err := func() error {
|
||||
s.DisplayName.Reset()
|
||||
@ -2286,38 +2251,6 @@ func (s *SubmissionFilter) Decode(d *jx.Decoder) error {
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "decode SubmissionFilter")
|
||||
}
|
||||
// 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(jsonFieldsNameOfSubmissionFilter) {
|
||||
name = jsonFieldsNameOfSubmissionFilter[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
|
||||
}
|
||||
|
@ -605,17 +605,11 @@ func (s *ScriptPolicyCreate) SetPolicy(val int32) {
|
||||
|
||||
// Ref: #/components/schemas/ScriptPolicyFilter
|
||||
type ScriptPolicyFilter struct {
|
||||
ID OptInt64 `json:"ID"`
|
||||
FromScriptHash OptString `json:"FromScriptHash"`
|
||||
ToScriptID OptInt64 `json:"ToScriptID"`
|
||||
Policy OptInt32 `json:"Policy"`
|
||||
}
|
||||
|
||||
// GetID returns the value of ID.
|
||||
func (s *ScriptPolicyFilter) GetID() OptInt64 {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
// GetFromScriptHash returns the value of FromScriptHash.
|
||||
func (s *ScriptPolicyFilter) GetFromScriptHash() OptString {
|
||||
return s.FromScriptHash
|
||||
@ -631,11 +625,6 @@ func (s *ScriptPolicyFilter) GetPolicy() OptInt32 {
|
||||
return s.Policy
|
||||
}
|
||||
|
||||
// SetID sets the value of ID.
|
||||
func (s *ScriptPolicyFilter) SetID(val OptInt64) {
|
||||
s.ID = val
|
||||
}
|
||||
|
||||
// SetFromScriptHash sets the value of FromScriptHash.
|
||||
func (s *ScriptPolicyFilter) SetFromScriptHash(val OptString) {
|
||||
s.FromScriptHash = val
|
||||
@ -969,17 +958,11 @@ func (s *SubmissionCreate) SetTargetAssetID(val OptInt64) {
|
||||
|
||||
// Ref: #/components/schemas/SubmissionFilter
|
||||
type SubmissionFilter struct {
|
||||
ID int64 `json:"ID"`
|
||||
DisplayName OptString `json:"DisplayName"`
|
||||
Creator OptString `json:"Creator"`
|
||||
GameID OptInt32 `json:"GameID"`
|
||||
}
|
||||
|
||||
// GetID returns the value of ID.
|
||||
func (s *SubmissionFilter) GetID() int64 {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
// GetDisplayName returns the value of DisplayName.
|
||||
func (s *SubmissionFilter) GetDisplayName() OptString {
|
||||
return s.DisplayName
|
||||
@ -995,11 +978,6 @@ func (s *SubmissionFilter) GetGameID() OptInt32 {
|
||||
return s.GameID
|
||||
}
|
||||
|
||||
// SetID sets the value of ID.
|
||||
func (s *SubmissionFilter) SetID(val int64) {
|
||||
s.ID = val
|
||||
}
|
||||
|
||||
// SetDisplayName sets the value of DisplayName.
|
||||
func (s *SubmissionFilter) SetDisplayName(val OptString) {
|
||||
s.DisplayName = val
|
||||
|
Loading…
Reference in New Issue
Block a user