MCPcopy Create free account
hub / github.com/bet365/jingo / valueInst

Method valueInst

structencoder.go:293–430  ·  view source on GitHub ↗

valueInst works out the conversion function we need for `k` and creates an instruction to write it to the buffer

(k reflect.Kind, instr func(func(unsafe.Pointer, *Buffer)))

Source from the content-addressed store, hash-verified

291
292// valueInst works out the conversion function we need for `k` and creates an instruction to write it to the buffer
293func (e *StructEncoder) valueInst(k reflect.Kind, instr func(func(unsafe.Pointer, *Buffer))) {
294
295 switch k {
296
297 case reflect.Int:
298
299 /// fast path for int fields
300 if e.f.Type.Kind() == reflect.Ptr {
301 instr(ptrIntToBuf)
302 return
303 }
304 e.flunk()
305 e.instructions = append(e.instructions, instruction{offset: e.f.Offset, kind: kindInt})
306
307 case reflect.Bool,
308 reflect.Int8,
309 reflect.Int16,
310 reflect.Int32,
311 reflect.Int64,
312 reflect.Uint,
313 reflect.Uint8,
314 reflect.Uint16,
315 reflect.Uint32,
316 reflect.Uint64,
317 reflect.Float32,
318 reflect.Float64:
319 /// standard print
320 conv, ok := typeconv[k]
321 if !ok {
322 return
323 }
324 instr(conv)
325
326 case reflect.Array:
327 /// support for primitives in arrays (proabbly need arrayencoder.go here if we want to take this further)
328 e.chunk("[")
329
330 conv, ok := typeconv[e.f.Type.Elem().Kind()]
331 if !ok {
332 return
333 }
334
335 offset := e.f.Type.Elem().Size()
336 for i := 0; i < e.f.Type.Len(); i++ {
337 if i > 0 {
338 e.chunk(", ")
339 }
340
341 e.flunk()
342 f := e.f
343 i := i
344 e.appendInstructionFun(func(v unsafe.Pointer, w *Buffer) {
345 conv(unsafe.Pointer(uintptr(v)+f.Offset+(uintptr(i)*offset)), w)
346 })
347 }
348
349 e.chunk("]")
350

Callers 1

NewStructEncoderFunction · 0.95

Calls 8

flunkMethod · 0.95
chunkMethod · 0.95
appendInstructionFunMethod · 0.95
MarshalMethod · 0.95
ptrstringvalMethod · 0.95
NewSliceEncoderFunction · 0.85
NewStructEncoderFunction · 0.85
WriteMethod · 0.80

Tested by

no test coverage detected