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

     1  // Code generated by github.com/actgardner/gogen-avro/v10. DO NOT EDIT.
     2  /*
     3   * SOURCE:
     4   *     recursive.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 RecursiveUnionTestRecord struct {
    21  	RecursiveField *UnionNullRecursiveUnionTestRecord `json:"RecursiveField"`
    22  }
    23  
    24  const RecursiveUnionTestRecordAvroCRC64Fingerprint = "\xc6U)C\v\x8a\xa6\x89"
    25  
    26  func NewRecursiveUnionTestRecord() RecursiveUnionTestRecord {
    27  	r := RecursiveUnionTestRecord{}
    28  	return r
    29  }
    30  
    31  func DeserializeRecursiveUnionTestRecord(r io.Reader) (RecursiveUnionTestRecord, error) {
    32  	t := NewRecursiveUnionTestRecord()
    33  	deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
    34  	if err != nil {
    35  		return t, err
    36  	}
    37  
    38  	err = vm.Eval(r, deser, &t)
    39  	return t, err
    40  }
    41  
    42  func DeserializeRecursiveUnionTestRecordFromSchema(r io.Reader, schema string) (RecursiveUnionTestRecord, error) {
    43  	t := NewRecursiveUnionTestRecord()
    44  
    45  	deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
    46  	if err != nil {
    47  		return t, err
    48  	}
    49  
    50  	err = vm.Eval(r, deser, &t)
    51  	return t, err
    52  }
    53  
    54  func writeRecursiveUnionTestRecord(r RecursiveUnionTestRecord, w io.Writer) error {
    55  	var err error
    56  	err = writeUnionNullRecursiveUnionTestRecord(r.RecursiveField, w)
    57  	if err != nil {
    58  		return err
    59  	}
    60  	return err
    61  }
    62  
    63  func (r RecursiveUnionTestRecord) Serialize(w io.Writer) error {
    64  	return writeRecursiveUnionTestRecord(r, w)
    65  }
    66  
    67  func (r RecursiveUnionTestRecord) Schema() string {
    68  	return "{\"fields\":[{\"name\":\"RecursiveField\",\"type\":[\"null\",\"RecursiveUnionTestRecord\"]}],\"name\":\"RecursiveUnionTestRecord\",\"type\":\"record\"}"
    69  }
    70  
    71  func (r RecursiveUnionTestRecord) SchemaName() string {
    72  	return "RecursiveUnionTestRecord"
    73  }
    74  
    75  func (_ RecursiveUnionTestRecord) SetBoolean(v bool)    { panic("Unsupported operation") }
    76  func (_ RecursiveUnionTestRecord) SetInt(v int32)       { panic("Unsupported operation") }
    77  func (_ RecursiveUnionTestRecord) SetLong(v int64)      { panic("Unsupported operation") }
    78  func (_ RecursiveUnionTestRecord) SetFloat(v float32)   { panic("Unsupported operation") }
    79  func (_ RecursiveUnionTestRecord) SetDouble(v float64)  { panic("Unsupported operation") }
    80  func (_ RecursiveUnionTestRecord) SetBytes(v []byte)    { panic("Unsupported operation") }
    81  func (_ RecursiveUnionTestRecord) SetString(v string)   { panic("Unsupported operation") }
    82  func (_ RecursiveUnionTestRecord) SetUnionElem(v int64) { panic("Unsupported operation") }
    83  
    84  func (r *RecursiveUnionTestRecord) Get(i int) types.Field {
    85  	switch i {
    86  	case 0:
    87  		r.RecursiveField = NewUnionNullRecursiveUnionTestRecord()
    88  
    89  		return r.RecursiveField
    90  	}
    91  	panic("Unknown field index")
    92  }
    93  
    94  func (r *RecursiveUnionTestRecord) SetDefault(i int) {
    95  	switch i {
    96  	}
    97  	panic("Unknown field index")
    98  }
    99  
   100  func (r *RecursiveUnionTestRecord) NullField(i int) {
   101  	switch i {
   102  	case 0:
   103  		r.RecursiveField = nil
   104  		return
   105  	}
   106  	panic("Not a nullable field index")
   107  }
   108  
   109  func (_ RecursiveUnionTestRecord) AppendMap(key string) types.Field { panic("Unsupported operation") }
   110  func (_ RecursiveUnionTestRecord) AppendArray() types.Field         { panic("Unsupported operation") }
   111  func (_ RecursiveUnionTestRecord) HintSize(int)                     { panic("Unsupported operation") }
   112  func (_ RecursiveUnionTestRecord) Finalize()                        {}
   113  
   114  func (_ RecursiveUnionTestRecord) AvroCRC64Fingerprint() []byte {
   115  	return []byte(RecursiveUnionTestRecordAvroCRC64Fingerprint)
   116  }
   117  
   118  func (r RecursiveUnionTestRecord) MarshalJSON() ([]byte, error) {
   119  	var err error
   120  	output := make(map[string]json.RawMessage)
   121  	output["RecursiveField"], err = json.Marshal(r.RecursiveField)
   122  	if err != nil {
   123  		return nil, err
   124  	}
   125  	return json.Marshal(output)
   126  }
   127  
   128  func (r *RecursiveUnionTestRecord) UnmarshalJSON(data []byte) error {
   129  	var fields map[string]json.RawMessage
   130  	if err := json.Unmarshal(data, &fields); err != nil {
   131  		return err
   132  	}
   133  
   134  	var val json.RawMessage
   135  	val = func() json.RawMessage {
   136  		if v, ok := fields["RecursiveField"]; ok {
   137  			return v
   138  		}
   139  		return nil
   140  	}()
   141  
   142  	if val != nil {
   143  		if err := json.Unmarshal([]byte(val), &r.RecursiveField); err != nil {
   144  			return err
   145  		}
   146  	} else {
   147  		return fmt.Errorf("no value specified for RecursiveField")
   148  	}
   149  	return nil
   150  }