Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,14 @@ func (c *Codec) SchemaCRC64Avro() int64 {
return int64(c.Rabin)
}

// Name returns the name of the Avro schema used to create the Codec.
func (c *Codec) Name() (string, error) {
if c.typeName == nil {
return "", fmt.Errorf("codec has no name")
}
return c.typeName.String(), nil
}

// convert a schema data structure to a codec, prefixing with specified
// namespace
func buildCodec(st map[string]*Codec, enclosingNamespace string, schema interface{}, cb *codecBuilder) (*Codec, error) {
Expand Down
16 changes: 16 additions & 0 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ func ExampleCodec_CanonicalSchema() {
// Output: {"type":"map","values":{"name":"foo","type":"enum","symbols":["alpha","bravo"]}}
}

func ExampleCodec_Name() {
schema := `{"type":"record","name":"name","namespace":"com.domain","fields":[{"name":"key","type":{"type":"string"}}]}`
codec, err := NewCodec(schema)
if err != nil {
fmt.Println(err)
} else {
name, errName := codec.Name()
if errName != nil {
fmt.Println(errName)
} else {
fmt.Println(name)
}
}
// Output: com.domain.name
}

func TestCodecRabin(t *testing.T) {
cases := []struct {
Schema string
Expand Down