github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/test/nested_test_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 NestedTestRecord struct {
    21  	NumberField NumberRecord `json:"NumberField"`
    22  
    23  	OtherField NestedRecord `json:"OtherField"`
    24  }
    25  
    26  const NestedTestRecordAvroCRC64Fingerprint = "b{m\\D\xbe\xaa\x96"
    27  
    28  func NewNestedTestRecord() NestedTestRecord {
    29  	r := NestedTestRecord{}
    30  	r.NumberField = NewNumberRecord()
    31  
    32  	r.OtherField = NewNestedRecord()
    33  
    34  	return r
    35  }
    36  
    37  func DeserializeNestedTestRecord(r io.Reader) (NestedTestRecord, error) {
    38  	t := NewNestedTestRecord()
    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 DeserializeNestedTestRecordFromSchema(r io.Reader, schema string) (NestedTestRecord, error) {
    49  	t := NewNestedTestRecord()
    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 writeNestedTestRecord(r NestedTestRecord, w io.Writer) error {
    61  	var err error
    62  	err = writeNumberRecord(r.NumberField, w)
    63  	if err != nil {
    64  		return err
    65  	}
    66  	err = writeNestedRecord(r.OtherField, w)
    67  	if err != nil {
    68  		return err
    69  	}
    70  	return err
    71  }
    72  
    73  func (r NestedTestRecord) Serialize(w io.Writer) error {
    74  	return writeNestedTestRecord(r, w)
    75  }
    76  
    77  func (r NestedTestRecord) Schema() string {
    78  	return "{\"fields\":[{\"name\":\"NumberField\",\"type\":{\"fields\":[{\"name\":\"IntField\",\"type\":\"int\"},{\"name\":\"LongField\",\"type\":\"long\"},{\"name\":\"FloatField\",\"type\":\"float\"},{\"name\":\"DoubleField\",\"type\":\"double\"}],\"name\":\"NumberRecord\",\"type\":\"record\"}},{\"name\":\"OtherField\",\"type\":{\"fields\":[{\"name\":\"StringField\",\"type\":\"string\"},{\"name\":\"BoolField\",\"type\":\"boolean\"},{\"name\":\"BytesField\",\"type\":\"bytes\"}],\"name\":\"NestedRecord\",\"type\":\"record\"}}],\"name\":\"NestedTestRecord\",\"type\":\"record\"}"
    79  }
    80  
    81  func (r NestedTestRecord) SchemaName() string {
    82  	return "NestedTestRecord"
    83  }
    84  
    85  func (_ NestedTestRecord) SetBoolean(v bool)    { panic("Unsupported operation") }
    86  func (_ NestedTestRecord) SetInt(v int32)       { panic("Unsupported operation") }
    87  func (_ NestedTestRecord) SetLong(v int64)      { panic("Unsupported operation") }
    88  func (_ NestedTestRecord) SetFloat(v float32)   { panic("Unsupported operation") }
    89  func (_ NestedTestRecord) SetDouble(v float64)  { panic("Unsupported operation") }
    90  func (_ NestedTestRecord) SetBytes(v []byte)    { panic("Unsupported operation") }
    91  func (_ NestedTestRecord) SetString(v string)   { panic("Unsupported operation") }
    92  func (_ NestedTestRecord) SetUnionElem(v int64) { panic("Unsupported operation") }
    93  
    94  func (r *NestedTestRecord) Get(i int) types.Field {
    95  	switch i {
    96  	case 0:
    97  		r.NumberField = NewNumberRecord()
    98  
    99  		w := types.Record{Target: &r.NumberField}
   100  
   101  		return w
   102  
   103  	case 1:
   104  		r.OtherField = NewNestedRecord()
   105  
   106  		w := types.Record{Target: &r.OtherField}
   107  
   108  		return w
   109  
   110  	}
   111  	panic("Unknown field index")
   112  }
   113  
   114  func (r *NestedTestRecord) SetDefault(i int) {
   115  	switch i {
   116  	}
   117  	panic("Unknown field index")
   118  }
   119  
   120  func (r *NestedTestRecord) NullField(i int) {
   121  	switch i {
   122  	}
   123  	panic("Not a nullable field index")
   124  }
   125  
   126  func (_ NestedTestRecord) AppendMap(key string) types.Field { panic("Unsupported operation") }
   127  func (_ NestedTestRecord) AppendArray() types.Field         { panic("Unsupported operation") }
   128  func (_ NestedTestRecord) HintSize(int)                     { panic("Unsupported operation") }
   129  func (_ NestedTestRecord) Finalize()                        {}
   130  
   131  func (_ NestedTestRecord) AvroCRC64Fingerprint() []byte {
   132  	return []byte(NestedTestRecordAvroCRC64Fingerprint)
   133  }
   134  
   135  func (r NestedTestRecord) MarshalJSON() ([]byte, error) {
   136  	var err error
   137  	output := make(map[string]json.RawMessage)
   138  	output["NumberField"], err = json.Marshal(r.NumberField)
   139  	if err != nil {
   140  		return nil, err
   141  	}
   142  	output["OtherField"], err = json.Marshal(r.OtherField)
   143  	if err != nil {
   144  		return nil, err
   145  	}
   146  	return json.Marshal(output)
   147  }
   148  
   149  func (r *NestedTestRecord) UnmarshalJSON(data []byte) error {
   150  	var fields map[string]json.RawMessage
   151  	if err := json.Unmarshal(data, &fields); err != nil {
   152  		return err
   153  	}
   154  
   155  	var val json.RawMessage
   156  	val = func() json.RawMessage {
   157  		if v, ok := fields["NumberField"]; ok {
   158  			return v
   159  		}
   160  		return nil
   161  	}()
   162  
   163  	if val != nil {
   164  		if err := json.Unmarshal([]byte(val), &r.NumberField); err != nil {
   165  			return err
   166  		}
   167  	} else {
   168  		return fmt.Errorf("no value specified for NumberField")
   169  	}
   170  	val = func() json.RawMessage {
   171  		if v, ok := fields["OtherField"]; ok {
   172  			return v
   173  		}
   174  		return nil
   175  	}()
   176  
   177  	if val != nil {
   178  		if err := json.Unmarshal([]byte(val), &r.OtherField); err != nil {
   179  			return err
   180  		}
   181  	} else {
   182  		return fmt.Errorf("no value specified for OtherField")
   183  	}
   184  	return nil
   185  }