public static string ToAvroFull(this AvroSchema schema) { var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) WriteAvroFull(sw, schema); return(sb.ToString()); }
private static void WritePrimitive(TextWriter writer, AvroSchema schema, WriterMode mode) { switch (mode) { case WriterMode.Canonical: writer.Write(@""""); writer.Write(schema.ToString()); writer.Write(@""""); break; case WriterMode.Full: writer.Write(@"{ ""type"": """); writer.Write(schema.ToString()); writer.Write(@""" }"); break; default: writer.Write(@""""); writer.Write(schema.ToString()); writer.Write(@""""); break; } }
public static long CRC64Value(AvroSchema s) { var bytes = Encoding.UTF8.GetBytes(s.ToAvroCanonical()); return(Fingerprint64(bytes)); }
public static void WriteAvroCanonical(TextWriter writer, AvroSchema schema) { Write(writer, schema, WriterMode.Canonical, null, null, false); }
public static void WriteAvroFull(TextWriter writer, AvroSchema schema) { Write(writer, schema, WriterMode.Full, null, null, false); }
private static void Write(TextWriter writer, AvroSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var ns = parentNamespace; if (namedSchemas == null) { namedSchemas = new HashSet <string>(); } if (schema is NamedSchema) { var namedSchema = schema as NamedSchema; var name = namedSchema.FullName; if (stripNs && namedSchema.Namespace == parentNamespace) { name = namedSchema.Name; } if (namedSchemas.Contains(namedSchema.FullName)) { writer.Write(@""""); writer.Write(name); writer.Write(@""""); return; } namedSchemas.Add(namedSchema.FullName); ns = namedSchema.Namespace; } switch (schema) { case NullSchema _: case BooleanSchema _: case IntSchema _: case LongSchema _: case FloatSchema _: case DoubleSchema _: case BytesSchema _: case StringSchema _: WritePrimitive(writer, schema, mode); break; case ArraySchema s: WriteArray(writer, s, mode, ns, namedSchemas, stripNs); break; case MapSchema s: WriteMap(writer, s, mode, ns, namedSchemas, stripNs); break; case UnionSchema s: WriteUnion(writer, s, mode, ns, namedSchemas, stripNs); break; case FixedSchema s: WriteFixed(writer, s, ns, mode, stripNs); break; case EnumSchema s: WriteEnum(writer, s, ns, mode, stripNs); break; case ErrorSchema s: WriteError(writer, s, mode, ns, namedSchemas, stripNs); break; case RecordSchema s: WriteRecord(writer, s, mode, ns, namedSchemas, stripNs); break; case DecimalSchema s: WriteDecimal(writer, s, mode, ns, namedSchemas, stripNs); break; case LogicalSchema s: WriteLogicalType(writer, s, mode, ns, namedSchemas, stripNs); break; default: throw new AvroException($"Unknown schema type: '{schema.GetType().FullName}'"); } }