MCPcopy
hub / github.com/dgraph-io/dgraph / convertToType

Function convertToType

worker/task.go:187–207  ·  view source on GitHub ↗

Returns nil byte on error

(v types.Val, typ types.TypeID)

Source from the content-addressed store, hash-verified

185
186// Returns nil byte on error
187func convertToType(v types.Val, typ types.TypeID) (*pb.TaskValue, error) {
188 result := &pb.TaskValue{ValType: typ.Enum(), Val: x.Nilbyte}
189 if v.Tid == typ {
190 result.Val = v.Value.([]byte)
191 return result, nil
192 }
193
194 // convert data from binary to appropriate format
195 val, err := types.Convert(v, typ)
196 if err != nil {
197 return result, err
198 }
199 // Marshal
200 data := types.ValueForType(types.BinaryID)
201 err = types.Marshal(val, &data)
202 if err != nil {
203 return result, errors.Errorf("Failed convertToType during Marshal")
204 }
205 result.Val = data.Value.([]byte)
206 return result, nil
207}
208
209// FuncType represents the type of a query function (aggregation, has, etc).
210type FuncType int

Callers 1

handleValuePostingsMethod · 0.85

Calls 5

ConvertFunction · 0.92
ValueForTypeFunction · 0.92
MarshalFunction · 0.92
EnumMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected