-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfixed.go
57 lines (53 loc) · 1.39 KB
/
fixed.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package avro
import (
"github.com/valyala/fastjson"
)
// FixedSchema -
type FixedSchema struct {
Type Type `json:"type"`
LogicalType LogicalType `json:"logicalType,omitempty"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Aliases []string `json:"aliases,omitempty"`
Documentation string `json:"doc,omitempty"`
Size int `json:"size"`
}
// TypeName -
func (t *FixedSchema) TypeName() Type {
if len(t.LogicalType) > 0 {
return Type(t.LogicalType)
}
return TypeFixed
}
func translateValueToFixedSchema(value *fastjson.Value) (Schema, error) {
if !value.Exists("size") {
return nil, ErrInvalidSchema
}
size, err := value.Get("size").Int()
if err != nil {
return nil, ErrInvalidSchema
}
if size < 0 {
return nil, ErrInvalidSchema
}
namespace, name, documentation, aliases, err := translateValueToMetaFields(value)
if err != nil {
return nil, err
}
var logicalType LogicalType
if value.Exists("logicalType") {
logicalType = LogicalType(value.GetStringBytes("logicalType"))
if logicalType != LogialTypeDuration || size != 12 {
return nil, ErrInvalidSchema
}
}
return &FixedSchema{
Type: TypeFixed,
LogicalType: logicalType,
Namespace: namespace,
Name: name,
Aliases: aliases,
Documentation: documentation,
Size: size,
}, nil
}