blob: a3151e2a5528d52fb86e49d5c98a6bfeda494c24 [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001package runtime
2
3import (
4 "github.com/golang/protobuf/proto"
5)
6
7// StringP returns a pointer to a string whose pointee is same as the given string value.
8func StringP(val string) (*string, error) {
9 return proto.String(val), nil
10}
11
12// BoolP parses the given string representation of a boolean value,
13// and returns a pointer to a bool whose value is same as the parsed value.
14func BoolP(val string) (*bool, error) {
15 b, err := Bool(val)
16 if err != nil {
17 return nil, err
18 }
19 return proto.Bool(b), nil
20}
21
22// Float64P parses the given string representation of a floating point number,
23// and returns a pointer to a float64 whose value is same as the parsed number.
24func Float64P(val string) (*float64, error) {
25 f, err := Float64(val)
26 if err != nil {
27 return nil, err
28 }
29 return proto.Float64(f), nil
30}
31
32// Float32P parses the given string representation of a floating point number,
33// and returns a pointer to a float32 whose value is same as the parsed number.
34func Float32P(val string) (*float32, error) {
35 f, err := Float32(val)
36 if err != nil {
37 return nil, err
38 }
39 return proto.Float32(f), nil
40}
41
42// Int64P parses the given string representation of an integer
43// and returns a pointer to a int64 whose value is same as the parsed integer.
44func Int64P(val string) (*int64, error) {
45 i, err := Int64(val)
46 if err != nil {
47 return nil, err
48 }
49 return proto.Int64(i), nil
50}
51
52// Int32P parses the given string representation of an integer
53// and returns a pointer to a int32 whose value is same as the parsed integer.
54func Int32P(val string) (*int32, error) {
55 i, err := Int32(val)
56 if err != nil {
57 return nil, err
58 }
59 return proto.Int32(i), err
60}
61
62// Uint64P parses the given string representation of an integer
63// and returns a pointer to a uint64 whose value is same as the parsed integer.
64func Uint64P(val string) (*uint64, error) {
65 i, err := Uint64(val)
66 if err != nil {
67 return nil, err
68 }
69 return proto.Uint64(i), err
70}
71
72// Uint32P parses the given string representation of an integer
73// and returns a pointer to a uint32 whose value is same as the parsed integer.
74func Uint32P(val string) (*uint32, error) {
75 i, err := Uint32(val)
76 if err != nil {
77 return nil, err
78 }
79 return proto.Uint32(i), err
80}