github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/test/union_null_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  type UnionNullRecursiveUnionTestRecordTypeEnum int
    19  
    20  const (
    21  	UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord UnionNullRecursiveUnionTestRecordTypeEnum = 1
    22  )
    23  
    24  type UnionNullRecursiveUnionTestRecord struct {
    25  	Null                     *types.NullVal
    26  	RecursiveUnionTestRecord RecursiveUnionTestRecord
    27  	UnionType                UnionNullRecursiveUnionTestRecordTypeEnum
    28  }
    29  
    30  func writeUnionNullRecursiveUnionTestRecord(r *UnionNullRecursiveUnionTestRecord, w io.Writer) error {
    31  
    32  	if r == nil {
    33  		err := vm.WriteLong(0, w)
    34  		return err
    35  	}
    36  
    37  	err := vm.WriteLong(int64(r.UnionType), w)
    38  	if err != nil {
    39  		return err
    40  	}
    41  	switch r.UnionType {
    42  	case UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord:
    43  		return writeRecursiveUnionTestRecord(r.RecursiveUnionTestRecord, w)
    44  	}
    45  	return fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
    46  }
    47  
    48  func NewUnionNullRecursiveUnionTestRecord() *UnionNullRecursiveUnionTestRecord {
    49  	return &UnionNullRecursiveUnionTestRecord{}
    50  }
    51  
    52  func (r *UnionNullRecursiveUnionTestRecord) Serialize(w io.Writer) error {
    53  	return writeUnionNullRecursiveUnionTestRecord(r, w)
    54  }
    55  
    56  func DeserializeUnionNullRecursiveUnionTestRecord(r io.Reader) (*UnionNullRecursiveUnionTestRecord, error) {
    57  	t := NewUnionNullRecursiveUnionTestRecord()
    58  	deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
    59  	if err != nil {
    60  		return t, err
    61  	}
    62  
    63  	err = vm.Eval(r, deser, t)
    64  
    65  	if err != nil {
    66  		return t, err
    67  	}
    68  	return t, err
    69  }
    70  
    71  func DeserializeUnionNullRecursiveUnionTestRecordFromSchema(r io.Reader, schema string) (*UnionNullRecursiveUnionTestRecord, error) {
    72  	t := NewUnionNullRecursiveUnionTestRecord()
    73  	deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
    74  	if err != nil {
    75  		return t, err
    76  	}
    77  
    78  	err = vm.Eval(r, deser, t)
    79  
    80  	if err != nil {
    81  		return t, err
    82  	}
    83  	return t, err
    84  }
    85  
    86  func (r *UnionNullRecursiveUnionTestRecord) Schema() string {
    87  	return "[\"null\",{\"fields\":[{\"name\":\"RecursiveField\",\"type\":[\"null\",\"RecursiveUnionTestRecord\"]}],\"name\":\"RecursiveUnionTestRecord\",\"type\":\"record\"}]"
    88  }
    89  
    90  func (_ *UnionNullRecursiveUnionTestRecord) SetBoolean(v bool)   { panic("Unsupported operation") }
    91  func (_ *UnionNullRecursiveUnionTestRecord) SetInt(v int32)      { panic("Unsupported operation") }
    92  func (_ *UnionNullRecursiveUnionTestRecord) SetFloat(v float32)  { panic("Unsupported operation") }
    93  func (_ *UnionNullRecursiveUnionTestRecord) SetDouble(v float64) { panic("Unsupported operation") }
    94  func (_ *UnionNullRecursiveUnionTestRecord) SetBytes(v []byte)   { panic("Unsupported operation") }
    95  func (_ *UnionNullRecursiveUnionTestRecord) SetString(v string)  { panic("Unsupported operation") }
    96  
    97  func (r *UnionNullRecursiveUnionTestRecord) SetLong(v int64) {
    98  
    99  	r.UnionType = (UnionNullRecursiveUnionTestRecordTypeEnum)(v)
   100  }
   101  
   102  func (r *UnionNullRecursiveUnionTestRecord) Get(i int) types.Field {
   103  
   104  	switch i {
   105  	case 0:
   106  		return r.Null
   107  	case 1:
   108  		r.RecursiveUnionTestRecord = NewRecursiveUnionTestRecord()
   109  		return &types.Record{Target: (&r.RecursiveUnionTestRecord)}
   110  	}
   111  	panic("Unknown field index")
   112  }
   113  func (_ *UnionNullRecursiveUnionTestRecord) NullField(i int)  { panic("Unsupported operation") }
   114  func (_ *UnionNullRecursiveUnionTestRecord) HintSize(i int)   { panic("Unsupported operation") }
   115  func (_ *UnionNullRecursiveUnionTestRecord) SetDefault(i int) { panic("Unsupported operation") }
   116  func (_ *UnionNullRecursiveUnionTestRecord) AppendMap(key string) types.Field {
   117  	panic("Unsupported operation")
   118  }
   119  func (_ *UnionNullRecursiveUnionTestRecord) AppendArray() types.Field { panic("Unsupported operation") }
   120  func (_ *UnionNullRecursiveUnionTestRecord) Finalize()                {}
   121  
   122  func (r *UnionNullRecursiveUnionTestRecord) MarshalJSON() ([]byte, error) {
   123  
   124  	if r == nil {
   125  		return []byte("null"), nil
   126  	}
   127  
   128  	switch r.UnionType {
   129  	case UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord:
   130  		return json.Marshal(map[string]interface{}{"RecursiveUnionTestRecord": r.RecursiveUnionTestRecord})
   131  	}
   132  	return nil, fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
   133  }
   134  
   135  func (r *UnionNullRecursiveUnionTestRecord) UnmarshalJSON(data []byte) error {
   136  
   137  	var fields map[string]json.RawMessage
   138  	if err := json.Unmarshal(data, &fields); err != nil {
   139  		return err
   140  	}
   141  	if len(fields) > 1 {
   142  		return fmt.Errorf("more than one type supplied for union")
   143  	}
   144  	if value, ok := fields["RecursiveUnionTestRecord"]; ok {
   145  		r.UnionType = 1
   146  		return json.Unmarshal([]byte(value), &r.RecursiveUnionTestRecord)
   147  	}
   148  	return fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
   149  }