Kinetica   C#   API  Version 7.2.3.0
FixedSchema.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 using Newtonsoft.Json.Linq;
22 
23 namespace Avro
24 {
28  public class FixedSchema : NamedSchema
29  {
33  public int Size { get; set; }
34 
42  internal static FixedSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
43  {
44  SchemaName name = NamedSchema.GetName(jtok, encspace);
45  var aliases = NamedSchema.GetAliases(jtok, name.Space, name.EncSpace);
46 
47  return new FixedSchema(name, aliases, JsonHelper.GetRequiredInteger(jtok, "size"), props, names);
48  }
49 
57  private FixedSchema(SchemaName name, IList<SchemaName> aliases, int size, PropertyMap props, SchemaNames names)
58  : base(Type.Fixed, name, aliases, props, names)
59  {
60  if (null == name.Name) throw new SchemaParseException("name cannot be null for fixed schema.");
61  if (size <= 0) throw new ArgumentOutOfRangeException("size", "size must be greater than zero.");
62  this.Size = size;
63  }
64 
71  protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
72  {
73  base.WriteJsonFields(writer, names, encspace);
74  writer.WritePropertyName("size");
75  writer.WriteValue(this.Size);
76  }
77 
83  public override bool Equals(object obj)
84  {
85  if (obj == this) return true;
86 
87  if (obj != null && obj is FixedSchema)
88  {
89  FixedSchema that = obj as FixedSchema;
90  return SchemaName.Equals(that.SchemaName) && Size == that.Size && areEqual(that.Props, this.Props);
91  }
92  return false;
93  }
94 
99  public override int GetHashCode()
100  {
101  return 53 * SchemaName.GetHashCode() + 47 * Size + getHashCode(Props);
102  }
103 
109  public override bool CanRead(Schema writerSchema)
110  {
111  if (writerSchema.Tag != Tag) return false;
112  FixedSchema that = writerSchema as FixedSchema;
113  if (that.Size != Size) return false;
114  if (that.SchemaName.Equals(SchemaName))
115  return true;
116  else
117  return InAliases(that.SchemaName);
118  }
119  }
120 }
static SchemaName GetName(JToken jtok, string encspace)
Parses the name and namespace from the given JSON schema object then creates SchemaName object includ...
Definition: NamedSchema.cs:116
static int getHashCode(object obj)
Hash code helper function
Definition: Schema.cs:301
override bool Equals(object obj)
Compares two fixed schemas
Definition: FixedSchema.cs:83
static IList< SchemaName > GetAliases(JToken jtok, string space, string encspace)
Parses the 'aliases' property from the given JSON token
Definition: NamedSchema.cs:130
bool InAliases(SchemaName name)
Definition: NamedSchema.cs:150
Base class for all schema types
Definition: Schema.cs:29
override int GetHashCode()
Hash code function
Definition: FixedSchema.cs:99
Class for fixed schemas
Definition: FixedSchema.cs:28
Type
Enum for schema types
Definition: Schema.cs:34
int Size
Fixed size for the bytes
Definition: FixedSchema.cs:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Class to store schema name, namespace and enclosing namespace
Definition: SchemaName.cs:27
A class that contains a list of named schemas.
Definition: SchemaName.cs:146
override int GetHashCode()
Definition: SchemaName.cs:136
override bool Equals(Object obj)
Compares two schema names
Definition: SchemaName.cs:114
override bool CanRead(Schema writerSchema)
Checks if this schema can read data written by the given schema.
Definition: FixedSchema.cs:109
String EncSpace
Namespace from the most tightly enclosing schema
Definition: SchemaName.cs:42
static bool areEqual(object o1, object o2)
Compares two objects, null is equal to null
Definition: Schema.cs:291
String Space
Namespace specified within the schema
Definition: SchemaName.cs:37
internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
Writes the fixed schema class in JSON format
Definition: FixedSchema.cs:71
Type Tag
Schema type property
Definition: Schema.cs:56
static int GetRequiredInteger(JToken jtok, string field)
Retrieves the required int property value for the given property name from the given JSON object.
Definition: JsonHelper.cs:70
Base class for all named schemas: fixed, enum, record
Definition: NamedSchema.cs:29
SchemaName SchemaName
Name of the schema, contains name, namespace and enclosing namespace
Definition: NamedSchema.cs:34