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