MCPcopy Create free account
hub / github.com/brimdata/super / BuildPrimitive

Function BuildPrimitive

sup/builder.go:56–169  ·  view source on GitHub ↗
(b *scode.Builder, val Primitive)

Source from the content-addressed store, hash-verified

54}
55
56func BuildPrimitive(b *scode.Builder, val Primitive) error {
57 switch super.TypeUnder(val.Type).(type) {
58 case *super.TypeOfUint8, *super.TypeOfUint16, *super.TypeOfUint32, *super.TypeOfUint64:
59 v, err := strconv.ParseUint(val.Text, 10, 64)
60 if err != nil {
61 return fmt.Errorf("invalid unsigned integer: %s", val.Text)
62 }
63 b.Append(super.EncodeUint(v))
64 return nil
65 case *super.TypeOfInt8, *super.TypeOfInt16, *super.TypeOfInt32, *super.TypeOfInt64:
66 v, err := strconv.ParseInt(val.Text, 10, 64)
67 if err != nil {
68 return fmt.Errorf("invalid integer: %s", val.Text)
69 }
70 b.Append(super.EncodeInt(v))
71 return nil
72 case *super.TypeOfDuration:
73 d, err := nano.ParseDuration(val.Text)
74 if err != nil {
75 return fmt.Errorf("invalid duration: %s", val.Text)
76 }
77 b.Append(super.EncodeDuration(d))
78 return nil
79 case *super.TypeOfTime:
80 t, err := time.Parse(time.RFC3339Nano, val.Text)
81 if err != nil {
82 return fmt.Errorf("invalid ISO time: %s", val.Text)
83 }
84 if nano.MaxTs.Time().Sub(t) < 0 {
85 return fmt.Errorf("time overflow: %s (max: %s)", val.Text, nano.MaxTs)
86 }
87 b.Append(super.EncodeTime(nano.TimeToTs(t)))
88 return nil
89 case *super.TypeOfFloat16:
90 v, err := strconv.ParseFloat(val.Text, 32)
91 if err != nil {
92 return fmt.Errorf("invalid floating point: %s", val.Text)
93 }
94
95 b.Append(super.EncodeFloat16(float32(v)))
96 return nil
97 case *super.TypeOfFloat32:
98 v, err := strconv.ParseFloat(val.Text, 32)
99 if err != nil {
100 return fmt.Errorf("invalid floating point: %s", val.Text)
101 }
102 b.Append(super.EncodeFloat32(float32(v)))
103 return nil
104 case *super.TypeOfFloat64:
105 v, err := strconv.ParseFloat(val.Text, 64)
106 if err != nil {
107 return fmt.Errorf("invalid floating point: %s", val.Text)
108 }
109 b.Append(super.EncodeFloat64(v))
110 return nil
111 case *super.TypeOfBool:
112 var v bool
113 if val.Text == "true" {

Callers 3

decodePrimitiveMethod · 0.92
buildValueFunction · 0.85
ParsePrimitiveFunction · 0.85

Calls 15

TypeUnderFunction · 0.92
EncodeUintFunction · 0.92
EncodeIntFunction · 0.92
ParseDurationFunction · 0.92
EncodeDurationFunction · 0.92
EncodeTimeFunction · 0.92
TimeToTsFunction · 0.92
EncodeFloat16Function · 0.92
EncodeFloat32Function · 0.92
EncodeFloat64Function · 0.92
EncodeBoolFunction · 0.92
BytesTypeAlias · 0.92

Tested by

no test coverage detected