Kinetica   C#   API  Version 7.2.3.0
GenericFixed.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 namespace Avro.Generic
24 {
28  public class GenericFixed
29  {
30  protected readonly byte[] value;
31  private FixedSchema schema;
32 
33  public FixedSchema Schema
34  {
35  get
36  {
37  return schema;
38  }
39 
40  set
41  {
42  if (!(value is FixedSchema))
43  throw new AvroException("Schema " + value.Name + " in set is not FixedSchema");
44 
45  if ((value as FixedSchema).Size != this.value.Length)
46  throw new AvroException("Schema " + value.Name + " Size " + (value as FixedSchema).Size + "is not equal to bytes length " + this.value.Length);
47 
48  schema = value;
49  }
50  }
51 
52  public GenericFixed(FixedSchema schema)
53  {
54  value = new byte[schema.Size];
55  this.Schema = schema;
56  }
57 
58  public GenericFixed(FixedSchema schema, byte[] value)
59  {
60  this.value = new byte[schema.Size];
61  this.Schema = schema;
62  Value = value;
63  }
64 
65  protected GenericFixed(uint size)
66  {
67  this.value = new byte[size];
68  }
69 
70  public byte[] Value
71  {
72  get { return this.value; }
73  set
74  {
75  if (value.Length == this.value.Length)
76  {
77  Array.Copy(value, this.value, value.Length);
78  return;
79  }
80  throw new AvroException("Invalid length for fixed: " + value.Length + ", (" + Schema + ")");
81  }
82  }
83 
84  public override bool Equals(object obj)
85  {
86  if (this == obj) return true;
87  if (obj != null && obj is GenericFixed)
88  {
89  GenericFixed that = obj as GenericFixed;
90  if (that.Schema.Equals(this.Schema))
91  {
92  for (int i = 0; i < value.Length; i++) if (this.value[i] != that.value[i]) return false;
93  return true;
94  }
95  }
96  return false;
97  }
98 
99  public override int GetHashCode()
100  {
101  int result = Schema.GetHashCode();
102  foreach (byte b in value)
103  {
104  result += 23 * b;
105  }
106  return result;
107  }
108  }
109 }
override bool Equals(object obj)
Compares two fixed schemas
Definition: FixedSchema.cs:83
override int GetHashCode()
Hash code function
Definition: Schema.cs:272
Base class for all schema types
Definition: Schema.cs:29
Class for fixed schemas
Definition: FixedSchema.cs:28
GenericFixed(FixedSchema schema)
Definition: GenericFixed.cs:52
int Size
Fixed size for the bytes
Definition: FixedSchema.cs:33
GenericFixed(FixedSchema schema, byte[] value)
Definition: GenericFixed.cs:58
override int GetHashCode()
Definition: GenericFixed.cs:99
override bool Equals(object obj)
Definition: GenericFixed.cs:84
readonly byte [] value
Definition: GenericFixed.cs:30
The default type used by GenericReader and GenericWriter for objects for FixedSchema
Definition: GenericFixed.cs:28