-
Notifications
You must be signed in to change notification settings - Fork 1
/
element.go
95 lines (89 loc) · 2.33 KB
/
element.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (C) 2022 PuzzleDB Contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package document
type ElementType int8
const (
// 0x0x (Reserved).
// 0x1x (Reserved - Collection).
ArrayType ElementType = 0x10
MapType ElementType = 0x11
// 0x20 Integer.
Int8Type ElementType = 0x20
Int16Type ElementType = 0x21
Int32Type ElementType = 0x22
Int64Type ElementType = 0x23
// 0x30 StringType.
StringType ElementType = 0x30
BinaryType ElementType = 0x31
// 0x40 Floating-point.
Float32Type ElementType = 0x40
Float64Type ElementType = 0x41
// 0x70 Special.
TimestampType ElementType = 0x70
BoolType ElementType = 0x71
)
type Element interface {
// Name returns the unique name.
Name() string
// Type returns the index type.
Type() ElementType
// Data returns the raw representation data in memory.
Data() any
// SetName sets the specified name to the element.
SetName(name string) Element
// SetType sets the specified type to the element.
SetType(t ElementType) Element
}
// NewElementTypeWith returns an element type from the specified parameters.
func NewElementTypeWith(v any) (ElementType, error) {
switch et := v.(type) {
case ElementType:
return et, nil
case int8:
return ElementType(et), nil
case uint8:
return ElementType(et), nil
}
return 0, newErrElementTypeInvalid(v)
}
// String represents the string representation.
func (et ElementType) String() string {
switch et {
case ArrayType:
return "array"
case MapType:
return "map"
case Int8Type:
return "int8"
case Int16Type:
return "int16"
case Int32Type:
return "int32"
case Int64Type:
return "int64"
case StringType:
return "string"
case BinaryType:
return "binary"
case Float32Type:
return "float32"
case Float64Type:
return "float64"
case TimestampType:
return "datetime"
case BoolType:
return "bool"
}
return ""
}