diff --git a/schema_parse.go b/schema_parse.go index 2be5a37..39f9cd1 100644 --- a/schema_parse.go +++ b/schema_parse.go @@ -20,11 +20,21 @@ func Parse(schema string) (Schema, error) { return ParseBytes([]byte(schema)) } +// Serialize serializes a schema object. +func Serialize(schema Schema) string { + return SerializeWithCache(schema, DefaultSchemaCache) +} + // ParseWithCache parses a schema string using the given namespace and schema cache. func ParseWithCache(schema, namespace string, cache *SchemaCache) (Schema, error) { return ParseBytesWithCache([]byte(schema), namespace, cache) } +// SerializeWithCache serializes a schema using the given namespace and schema cache. +func SerializeWithCache(schema Schema, cache *SchemaCache) string { + return serializeType(schema, cache) +} + // MustParse parses a schema string, panicing if there is an error. func MustParse(schema string) Schema { parsed, err := Parse(schema) @@ -93,6 +103,10 @@ func parseType(namespace string, v any, seen seenCache, cache *SchemaCache) (Sch return nil, fmt.Errorf("avro: unknown type: %v", v) } +func serializeType(schema Schema, cache *SchemaCache) string { + return schema.Resolve(cache) +} + func parsePrimitiveType(namespace, s string, cache *SchemaCache) (Schema, error) { typ := Type(s) switch typ {