Skip to content

Commit

Permalink
Serialize schemas feature hamba#400
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic-pourrat committed May 17, 2024
1 parent e9a0f43 commit 57422ee
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions schema_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 57422ee

Please sign in to comment.