-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslice_factory.go
69 lines (56 loc) · 2.05 KB
/
slice_factory.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
//
// DISCLAIMER
//
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//
package velocypack
import "encoding/binary"
// NoneSlice creates a slice of type None
func NoneSlice() Slice { return Slice{0x00} }
// IllegalSlice creates a slice of type Illegal
func IllegalSlice() Slice { return Slice{0x17} }
// NullSlice creates a slice of type Null
func NullSlice() Slice { return Slice{0x18} }
// FalseSlice creates a slice of type Boolean with false value
func FalseSlice() Slice { return Slice{0x19} }
// TrueSlice creates a slice of type Boolean with true value
func TrueSlice() Slice { return Slice{0x1a} }
// ZeroSlice creates a slice of type Smallint(0)
func ZeroSlice() Slice { return Slice{0x30} }
// EmptyArraySlice creates a slice of type Array, empty
func EmptyArraySlice() Slice { return Slice{0x01} }
// EmptyObjectSlice creates a slice of type Object, empty
func EmptyObjectSlice() Slice { return Slice{0x0a} }
// MinKeySlice creates a slice of type MinKey
func MinKeySlice() Slice { return Slice{0x1e} }
// MaxKeySlice creates a slice of type MaxKey
func MaxKeySlice() Slice { return Slice{0x1f} }
// StringSlice creates a slice of type String with given string value
func StringSlice(s string) Slice {
raw := []byte(s)
l := len(raw)
if l <= 126 {
return Slice(append([]byte{byte(0x40 + l)}, raw...))
}
buf := make([]byte, 1+8+l)
buf[0] = 0xbf
binary.LittleEndian.PutUint64(buf[1:], uint64(l))
copy(buf[1+8:], raw)
return buf
}