github.com/aeternity/aepp-sdk-go/v4@v4.0.1/swagguard/node/models/oracle_query_tx_json.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"bytes"
    10  	"encoding/json"
    11  
    12  	strfmt "github.com/go-openapi/strfmt"
    13  
    14  	"github.com/go-openapi/errors"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/go-openapi/validate"
    17  )
    18  
    19  // OracleQueryTxJSON oracle query tx JSON
    20  // swagger:model OracleQueryTxJSON
    21  type OracleQueryTxJSON struct {
    22  	versionField *uint32
    23  
    24  	OracleQueryTx
    25  }
    26  
    27  // Type gets the type of this subtype
    28  func (m *OracleQueryTxJSON) Type() string {
    29  	return "OracleQueryTx"
    30  }
    31  
    32  // SetType sets the type of this subtype
    33  func (m *OracleQueryTxJSON) SetType(val string) {
    34  
    35  }
    36  
    37  // Version gets the version of this subtype
    38  func (m *OracleQueryTxJSON) Version() *uint32 {
    39  	return m.versionField
    40  }
    41  
    42  // SetVersion sets the version of this subtype
    43  func (m *OracleQueryTxJSON) SetVersion(val *uint32) {
    44  	m.versionField = val
    45  }
    46  
    47  // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
    48  func (m *OracleQueryTxJSON) UnmarshalJSON(raw []byte) error {
    49  	var data struct {
    50  		OracleQueryTx
    51  	}
    52  	buf := bytes.NewBuffer(raw)
    53  	dec := json.NewDecoder(buf)
    54  	dec.UseNumber()
    55  
    56  	if err := dec.Decode(&data); err != nil {
    57  		return err
    58  	}
    59  
    60  	var base struct {
    61  		/* Just the base type fields. Used for unmashalling polymorphic types.*/
    62  
    63  		Type string `json:"type"`
    64  
    65  		Version *uint32 `json:"version"`
    66  	}
    67  	buf = bytes.NewBuffer(raw)
    68  	dec = json.NewDecoder(buf)
    69  	dec.UseNumber()
    70  
    71  	if err := dec.Decode(&base); err != nil {
    72  		return err
    73  	}
    74  
    75  	var result OracleQueryTxJSON
    76  
    77  	if base.Type != result.Type() {
    78  		/* Not the type we're looking for. */
    79  		return errors.New(422, "invalid type value: %q", base.Type)
    80  	}
    81  
    82  	result.versionField = base.Version
    83  
    84  	result.OracleQueryTx = data.OracleQueryTx
    85  
    86  	*m = result
    87  
    88  	return nil
    89  }
    90  
    91  // MarshalJSON marshals this object with a polymorphic type to a JSON structure
    92  func (m OracleQueryTxJSON) MarshalJSON() ([]byte, error) {
    93  	var b1, b2, b3 []byte
    94  	var err error
    95  	b1, err = json.Marshal(struct {
    96  		OracleQueryTx
    97  	}{
    98  
    99  		OracleQueryTx: m.OracleQueryTx,
   100  	},
   101  	)
   102  	if err != nil {
   103  		return nil, err
   104  	}
   105  	b2, err = json.Marshal(struct {
   106  		Type string `json:"type"`
   107  
   108  		Version *uint32 `json:"version"`
   109  	}{
   110  
   111  		Type: m.Type(),
   112  
   113  		Version: m.Version(),
   114  	},
   115  	)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  
   120  	return swag.ConcatJSON(b1, b2, b3), nil
   121  }
   122  
   123  // Validate validates this oracle query tx JSON
   124  func (m *OracleQueryTxJSON) Validate(formats strfmt.Registry) error {
   125  	var res []error
   126  
   127  	if err := m.validateVersion(formats); err != nil {
   128  		res = append(res, err)
   129  	}
   130  
   131  	// validation for a type composition with OracleQueryTx
   132  	if err := m.OracleQueryTx.Validate(formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if len(res) > 0 {
   137  		return errors.CompositeValidationError(res...)
   138  	}
   139  	return nil
   140  }
   141  
   142  func (m *OracleQueryTxJSON) validateVersion(formats strfmt.Registry) error {
   143  
   144  	if err := validate.Required("version", "body", m.Version()); err != nil {
   145  		return err
   146  	}
   147  
   148  	return nil
   149  }
   150  
   151  // MarshalBinary interface implementation
   152  func (m *OracleQueryTxJSON) MarshalBinary() ([]byte, error) {
   153  	if m == nil {
   154  		return nil, nil
   155  	}
   156  	return swag.WriteJSON(m)
   157  }
   158  
   159  // UnmarshalBinary interface implementation
   160  func (m *OracleQueryTxJSON) UnmarshalBinary(b []byte) error {
   161  	var res OracleQueryTxJSON
   162  	if err := swag.ReadJSON(b, &res); err != nil {
   163  		return err
   164  	}
   165  	*m = res
   166  	return nil
   167  }