github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/test/number_record.go (about)

     1  // Code generated by github.com/actgardner/gogen-avro/v10. DO NOT EDIT.
     2  /*
     3   * SOURCE:
     4   *     nested.avsc
     5   */
     6  package test
     7  
     8  import (
     9  	"encoding/json"
    10  	"fmt"
    11  	"io"
    12  
    13  	"github.com/actgardner/gogen-avro/v10/compiler"
    14  	"github.com/actgardner/gogen-avro/v10/vm"
    15  	"github.com/actgardner/gogen-avro/v10/vm/types"
    16  )
    17  
    18  var _ = fmt.Printf
    19  
    20  type NumberRecord struct {
    21  	IntField int32 `json:"IntField"`
    22  
    23  	LongField int64 `json:"LongField"`
    24  
    25  	FloatField float32 `json:"FloatField"`
    26  
    27  	DoubleField float64 `json:"DoubleField"`
    28  }
    29  
    30  const NumberRecordAvroCRC64Fingerprint = "\xf4Zu\xd5Nt'~"
    31  
    32  func NewNumberRecord() NumberRecord {
    33  	r := NumberRecord{}
    34  	return r
    35  }
    36  
    37  func DeserializeNumberRecord(r io.Reader) (NumberRecord, error) {
    38  	t := NewNumberRecord()
    39  	deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
    40  	if err != nil {
    41  		return t, err
    42  	}
    43  
    44  	err = vm.Eval(r, deser, &t)
    45  	return t, err
    46  }
    47  
    48  func DeserializeNumberRecordFromSchema(r io.Reader, schema string) (NumberRecord, error) {
    49  	t := NewNumberRecord()
    50  
    51  	deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
    52  	if err != nil {
    53  		return t, err
    54  	}
    55  
    56  	err = vm.Eval(r, deser, &t)
    57  	return t, err
    58  }
    59  
    60  func writeNumberRecord(r NumberRecord, w io.Writer) error {
    61  	var err error
    62  	err = vm.WriteInt(r.IntField, w)
    63  	if err != nil {
    64  		return err
    65  	}
    66  	err = vm.WriteLong(r.LongField, w)
    67  	if err != nil {
    68  		return err
    69  	}
    70  	err = vm.WriteFloat(r.FloatField, w)
    71  	if err != nil {
    72  		return err
    73  	}
    74  	err = vm.WriteDouble(r.DoubleField, w)
    75  	if err != nil {
    76  		return err
    77  	}
    78  	return err
    79  }
    80  
    81  func (r NumberRecord) Serialize(w io.Writer) error {
    82  	return writeNumberRecord(r, w)
    83  }
    84  
    85  func (r NumberRecord) Schema() string {
    86  	return "{\"fields\":[{\"name\":\"IntField\",\"type\":\"int\"},{\"name\":\"LongField\",\"type\":\"long\"},{\"name\":\"FloatField\",\"type\":\"float\"},{\"name\":\"DoubleField\",\"type\":\"double\"}],\"name\":\"NumberRecord\",\"type\":\"record\"}"
    87  }
    88  
    89  func (r NumberRecord) SchemaName() string {
    90  	return "NumberRecord"
    91  }
    92  
    93  func (_ NumberRecord) SetBoolean(v bool)    { panic("Unsupported operation") }
    94  func (_ NumberRecord) SetInt(v int32)       { panic("Unsupported operation") }
    95  func (_ NumberRecord) SetLong(v int64)      { panic("Unsupported operation") }
    96  func (_ NumberRecord) SetFloat(v float32)   { panic("Unsupported operation") }
    97  func (_ NumberRecord) SetDouble(v float64)  { panic("Unsupported operation") }
    98  func (_ NumberRecord) SetBytes(v []byte)    { panic("Unsupported operation") }
    99  func (_ NumberRecord) SetString(v string)   { panic("Unsupported operation") }
   100  func (_ NumberRecord) SetUnionElem(v int64) { panic("Unsupported operation") }
   101  
   102  func (r *NumberRecord) Get(i int) types.Field {
   103  	switch i {
   104  	case 0:
   105  		w := types.Int{Target: &r.IntField}
   106  
   107  		return w
   108  
   109  	case 1:
   110  		w := types.Long{Target: &r.LongField}
   111  
   112  		return w
   113  
   114  	case 2:
   115  		w := types.Float{Target: &r.FloatField}
   116  
   117  		return w
   118  
   119  	case 3:
   120  		w := types.Double{Target: &r.DoubleField}
   121  
   122  		return w
   123  
   124  	}
   125  	panic("Unknown field index")
   126  }
   127  
   128  func (r *NumberRecord) SetDefault(i int) {
   129  	switch i {
   130  	}
   131  	panic("Unknown field index")
   132  }
   133  
   134  func (r *NumberRecord) NullField(i int) {
   135  	switch i {
   136  	}
   137  	panic("Not a nullable field index")
   138  }
   139  
   140  func (_ NumberRecord) AppendMap(key string) types.Field { panic("Unsupported operation") }
   141  func (_ NumberRecord) AppendArray() types.Field         { panic("Unsupported operation") }
   142  func (_ NumberRecord) HintSize(int)                     { panic("Unsupported operation") }
   143  func (_ NumberRecord) Finalize()                        {}
   144  
   145  func (_ NumberRecord) AvroCRC64Fingerprint() []byte {
   146  	return []byte(NumberRecordAvroCRC64Fingerprint)
   147  }
   148  
   149  func (r NumberRecord) MarshalJSON() ([]byte, error) {
   150  	var err error
   151  	output := make(map[string]json.RawMessage)
   152  	output["IntField"], err = json.Marshal(r.IntField)
   153  	if err != nil {
   154  		return nil, err
   155  	}
   156  	output["LongField"], err = json.Marshal(r.LongField)
   157  	if err != nil {
   158  		return nil, err
   159  	}
   160  	output["FloatField"], err = json.Marshal(r.FloatField)
   161  	if err != nil {
   162  		return nil, err
   163  	}
   164  	output["DoubleField"], err = json.Marshal(r.DoubleField)
   165  	if err != nil {
   166  		return nil, err
   167  	}
   168  	return json.Marshal(output)
   169  }
   170  
   171  func (r *NumberRecord) UnmarshalJSON(data []byte) error {
   172  	var fields map[string]json.RawMessage
   173  	if err := json.Unmarshal(data, &fields); err != nil {
   174  		return err
   175  	}
   176  
   177  	var val json.RawMessage
   178  	val = func() json.RawMessage {
   179  		if v, ok := fields["IntField"]; ok {
   180  			return v
   181  		}
   182  		return nil
   183  	}()
   184  
   185  	if val != nil {
   186  		if err := json.Unmarshal([]byte(val), &r.IntField); err != nil {
   187  			return err
   188  		}
   189  	} else {
   190  		return fmt.Errorf("no value specified for IntField")
   191  	}
   192  	val = func() json.RawMessage {
   193  		if v, ok := fields["LongField"]; ok {
   194  			return v
   195  		}
   196  		return nil
   197  	}()
   198  
   199  	if val != nil {
   200  		if err := json.Unmarshal([]byte(val), &r.LongField); err != nil {
   201  			return err
   202  		}
   203  	} else {
   204  		return fmt.Errorf("no value specified for LongField")
   205  	}
   206  	val = func() json.RawMessage {
   207  		if v, ok := fields["FloatField"]; ok {
   208  			return v
   209  		}
   210  		return nil
   211  	}()
   212  
   213  	if val != nil {
   214  		if err := json.Unmarshal([]byte(val), &r.FloatField); err != nil {
   215  			return err
   216  		}
   217  	} else {
   218  		return fmt.Errorf("no value specified for FloatField")
   219  	}
   220  	val = func() json.RawMessage {
   221  		if v, ok := fields["DoubleField"]; ok {
   222  			return v
   223  		}
   224  		return nil
   225  	}()
   226  
   227  	if val != nil {
   228  		if err := json.Unmarshal([]byte(val), &r.DoubleField); err != nil {
   229  			return err
   230  		}
   231  	} else {
   232  		return fmt.Errorf("no value specified for DoubleField")
   233  	}
   234  	return nil
   235  }