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

Function GenValue

fuzz/fuzz.go:170–262  ·  view source on GitHub ↗
(b *bytes.Reader, context *super.Context, typ super.Type, builder *scode.Builder)

Source from the content-addressed store, hash-verified

168}
169
170func GenValue(b *bytes.Reader, context *super.Context, typ super.Type, builder *scode.Builder) {
171 if GenByte(b) == 0 {
172 builder.Append(nil)
173 return
174 }
175 switch typ {
176 case super.TypeUint8:
177 builder.Append(super.EncodeUint(uint64(GenByte(b))))
178 case super.TypeUint16:
179 builder.Append(super.EncodeUint(uint64(binary.LittleEndian.Uint16(GenBytes(b, 2)))))
180 case super.TypeUint32:
181 builder.Append(super.EncodeUint(uint64(binary.LittleEndian.Uint32(GenBytes(b, 4)))))
182 case super.TypeUint64:
183 builder.Append(super.EncodeUint(uint64(binary.LittleEndian.Uint64(GenBytes(b, 8)))))
184 case super.TypeInt8:
185 builder.Append(super.EncodeInt(int64(GenByte(b))))
186 case super.TypeInt16:
187 builder.Append(super.EncodeInt(int64(binary.LittleEndian.Uint16(GenBytes(b, 2)))))
188 case super.TypeInt32:
189 builder.Append(super.EncodeInt(int64(binary.LittleEndian.Uint32(GenBytes(b, 4)))))
190 case super.TypeInt64:
191 builder.Append(super.EncodeInt(int64(binary.LittleEndian.Uint64(GenBytes(b, 8)))))
192 case super.TypeDuration:
193 builder.Append(super.EncodeDuration(nano.Duration(int64(binary.LittleEndian.Uint64(GenBytes(b, 8))))))
194 case super.TypeTime:
195 builder.Append(super.EncodeTime(nano.Ts(int64(binary.LittleEndian.Uint64(GenBytes(b, 8))))))
196 case super.TypeFloat16:
197 builder.Append(super.EncodeFloat16(float32(float16.Frombits(binary.LittleEndian.Uint16(GenBytes(b, 4))))))
198 case super.TypeFloat32:
199 builder.Append(super.EncodeFloat32(math.Float32frombits(binary.LittleEndian.Uint32(GenBytes(b, 4)))))
200 case super.TypeFloat64:
201 builder.Append(super.EncodeFloat64(math.Float64frombits(binary.LittleEndian.Uint64(GenBytes(b, 8)))))
202 case super.TypeBool:
203 builder.Append(super.EncodeBool(GenByte(b) > 0))
204 case super.TypeBytes:
205 builder.Append(super.EncodeBytes(GenBytes(b, int(GenByte(b)))))
206 case super.TypeString:
207 builder.Append(super.EncodeString(string(GenBytes(b, int(GenByte(b))))))
208 case super.TypeIP:
209 builder.Append(super.EncodeIP(netip.AddrFrom16([16]byte(GenBytes(b, 16)))))
210 case super.TypeNet:
211 ip := netip.AddrFrom16([16]byte(GenBytes(b, 16)))
212 numBits := int(GenByte(b)) % ip.BitLen()
213 net, err := ip.Prefix(numBits)
214 if err != nil {
215 // Should be unreachable.
216 panic(err)
217 }
218 builder.Append(super.EncodeNet(net))
219 case super.TypeType:
220 typ := GenType(b, context, 3)
221 builder.Append(super.EncodeTypeValue(typ))
222 case super.TypeNull:
223 builder.Append(nil)
224 default:
225 switch typ := typ.(type) {
226 case *super.TypeRecord:
227 builder.BeginContainer()

Callers 1

GenValuesFunction · 0.85

Calls 15

EncodeUintFunction · 0.92
EncodeIntFunction · 0.92
EncodeDurationFunction · 0.92
DurationTypeAlias · 0.92
EncodeTimeFunction · 0.92
TsTypeAlias · 0.92
EncodeFloat16Function · 0.92
EncodeFloat32Function · 0.92
EncodeFloat64Function · 0.92
EncodeBoolFunction · 0.92
EncodeBytesFunction · 0.92
EncodeStringFunction · 0.92

Tested by

no test coverage detected