-
Notifications
You must be signed in to change notification settings - Fork 10
/
map.go
31 lines (27 loc) · 606 Bytes
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package avro
import (
"github.com/valyala/fastjson"
)
// MapSchema -
type MapSchema struct {
Type Type `json:"type"`
Value Schema `json:"values"`
}
// TypeName -
func (t *MapSchema) TypeName() Type {
return TypeMap
}
func translateValueToMapSchema(value *fastjson.Value, additionalTypes ...Type) (Schema, error) {
if !value.Exists("values") {
return nil, ErrInvalidSchema
}
valueVal := value.Get("values")
valueSchema, err := translateValue2AnySchema(valueVal, additionalTypes...)
if err != nil {
return nil, err
}
return &MapSchema{
Type: TypeMap,
Value: valueSchema,
}, nil
}