File: autoshim.go

package info (click to toggle)
golang-github-tinylib-msgp 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,168 kB
  • sloc: makefile: 45
file content (159 lines) | stat: -rw-r--r-- 4,559 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package msgp

import "strconv"

// AutoShim provides helper functions for converting between string and
// numeric types.
type AutoShim struct{}

// ParseUint converts a string to a uint.
func (a AutoShim) ParseUint(s string) (uint, error) {
	v, err := strconv.ParseUint(s, 10, strconv.IntSize)
	return uint(v), err
}

// ParseUint8 converts a string to a uint8.
func (a AutoShim) ParseUint8(s string) (uint8, error) {
	v, err := strconv.ParseUint(s, 10, 8)
	return uint8(v), err
}

// ParseUint16 converts a string to a uint16.
func (a AutoShim) ParseUint16(s string) (uint16, error) {
	v, err := strconv.ParseUint(s, 10, 16)
	return uint16(v), err
}

// ParseUint32 converts a string to a uint32.
func (a AutoShim) ParseUint32(s string) (uint32, error) {
	v, err := strconv.ParseUint(s, 10, 32)
	return uint32(v), err
}

// ParseUint64 converts a string to a uint64.
func (a AutoShim) ParseUint64(s string) (uint64, error) {
	v, err := strconv.ParseUint(s, 10, 64)
	return uint64(v), err
}

// ParseInt converts a string to an int.
func (a AutoShim) ParseInt(s string) (int, error) {
	v, err := strconv.ParseInt(s, 10, strconv.IntSize)
	return int(v), err
}

// ParseInt8 converts a string to an int8.
func (a AutoShim) ParseInt8(s string) (int8, error) {
	v, err := strconv.ParseInt(s, 10, 8)
	return int8(v), err
}

// ParseInt16 converts a string to an int16.
func (a AutoShim) ParseInt16(s string) (int16, error) {
	v, err := strconv.ParseInt(s, 10, 16)
	return int16(v), err
}

// ParseInt32 converts a string to an int32.
func (a AutoShim) ParseInt32(s string) (int32, error) {
	v, err := strconv.ParseInt(s, 10, 32)
	return int32(v), err
}

// ParseInt64 converts a string to an int64.
func (a AutoShim) ParseInt64(s string) (int64, error) {
	v, err := strconv.ParseInt(s, 10, 64)
	return int64(v), err
}

// ParseBool converts a string to a bool.
func (a AutoShim) ParseBool(s string) (bool, error) {
	return strconv.ParseBool(s)
}

// ParseFloat64 converts a string to a float64.
func (a AutoShim) ParseFloat64(s string) (float64, error) {
	return strconv.ParseFloat(s, 64)
}

// ParseFloat32 converts a string to a float32.
func (a AutoShim) ParseFloat32(s string) (float32, error) {
	v, err := strconv.ParseFloat(s, 32)
	return float32(v), err
}

// ParseByte converts a string to a byte.
func (a AutoShim) ParseByte(s string) (byte, error) {
	v, err := strconv.ParseUint(s, 10, 8)
	return byte(v), err
}

// Uint8String returns the string representation of a uint8.
func (a AutoShim) Uint8String(v uint8) string {
	return strconv.FormatUint(uint64(v), 10)
}

// UintString returns the string representation of a uint.
func (a AutoShim) UintString(v uint) string {
	return strconv.FormatUint(uint64(v), 10)
}

// Uint16String returns the string representation of a uint16.
func (a AutoShim) Uint16String(v uint16) string {
	return strconv.FormatUint(uint64(v), 10)
}

// Uint32String returns the string representation of a uint32.
func (a AutoShim) Uint32String(v uint32) string {
	return strconv.FormatUint(uint64(v), 10)
}

// Uint64String returns the string representation of a uint64.
func (a AutoShim) Uint64String(v uint64) string {
	return strconv.FormatUint(v, 10)
}

// IntString returns the string representation of an int.
func (a AutoShim) IntString(v int) string {
	return strconv.FormatInt(int64(v), 10)
}

// Int8String returns the string representation of an int8.
func (a AutoShim) Int8String(v int8) string {
	return strconv.FormatInt(int64(v), 10)
}

// Int16String returns the string representation of an int16.
func (a AutoShim) Int16String(v int16) string {
	return strconv.FormatInt(int64(v), 10)
}

// Int32String returns the string representation of an int32.
func (a AutoShim) Int32String(v int32) string {
	return strconv.FormatInt(int64(v), 10)
}

// Int64String returns the string representation of an int64.
func (a AutoShim) Int64String(v int64) string {
	return strconv.FormatInt(v, 10)
}

// BoolString returns the string representation of a bool.
func (a AutoShim) BoolString(v bool) string {
	return strconv.FormatBool(v)
}

// Float64String returns the string representation of a float64.
func (a AutoShim) Float64String(v float64) string {
	return strconv.FormatFloat(v, 'g', -1, 64)
}

// Float32String returns the string representation of a float32.
func (a AutoShim) Float32String(v float32) string {
	return strconv.FormatFloat(float64(v), 'g', -1, 32)
}

// ByteString returns the string representation of a byte.
func (a AutoShim) ByteString(v byte) string {
	return strconv.FormatUint(uint64(v), 10)
}