MCPcopy Create free account
hub / github.com/google/gapid / encodeValue

Method encodeValue

gapil/compiler/plugins/encoder/encoder.go:418–578  ·  view source on GitHub ↗

encodeValue encodes the proto value to buf.

(s *compiler.S, ptr, buf *codegen.Value, ty semantic.Type)

Source from the content-addressed store, hash-verified

416
417// encodeValue encodes the proto value to buf.
418func (e *encoder) encodeValue(s *compiler.S, ptr, buf *codegen.Value, ty semantic.Type) {
419 ty = semantic.Underlying(ty)
420 switch ty := ty.(type) {
421 case *semantic.Builtin:
422 switch ty {
423 case semantic.Int8Type,
424 semantic.Int16Type,
425 semantic.Int32Type,
426 semantic.Int64Type,
427 semantic.IntType,
428 semantic.CharType:
429 e.writeZigzag(s, buf, ptr.Load().Cast(e.T.Int64)) // Sign-ext
430 return
431 case semantic.Uint8Type,
432 semantic.Uint16Type,
433 semantic.Uint32Type,
434 semantic.Uint64Type,
435 semantic.UintType,
436 semantic.SizeType,
437 semantic.BoolType:
438 e.writeZigzag(s, buf, ptr.Load().Cast(e.T.Uint64)) // No sign-ext
439 return
440 case semantic.Float32Type:
441 e.writeFixed32(s, buf, ptr.Load())
442 return
443 case semantic.Float64Type:
444 e.writeFixed64(s, buf, ptr.Load())
445 return
446 case semantic.StringType:
447 strPtr := ptr.Load()
448 size := strPtr.Index(0, compiler.StringLength).Load().Cast(e.T.Uint32)
449 bytes := strPtr.Index(0, compiler.StringData, 0)
450 e.debug(s, "encoding string at %p: size: %d, refcount: %d, str: %s",
451 strPtr, size, strPtr.Index(0, compiler.StringRefCount).Load(), bytes)
452 e.writeBytes(s, buf, size, bytes)
453 return
454 }
455 case *semantic.Enum:
456 e.encodeValue(s, ptr, buf, ty.NumberType)
457 return
458 case *semantic.Pointer:
459 e.encodeValue(s, ptr, buf, semantic.Uint64Type)
460 return
461 case *semantic.StaticArray:
462 panic("Must be handled in encodeField")
463 case *semantic.Class:
464 e.writeBlob(s, buf, func(buf *codegen.Value) {
465 s.Call(e.funcs.encodeToBuf[ty], ptr, s.Ctx, buf)
466 })
467 return
468 case *semantic.Reference:
469 refPtr := ptr.Load()
470 s.If(s.NotEqual(refPtr, s.Zero(refPtr.Type())), func(s *compiler.S) {
471 signedRefID := s.Call(e.callbacks.encodeBackref, s.Ctx, refPtr.Cast(e.T.VoidPtr))
472 newRef := s.GreaterOrEqualTo(signedRefID, s.Scalar(int64(0)))
473 refID := s.Select(newRef, signedRefID, s.Negate(signedRefID))
474
475 e.writeBlob(s, buf, func(buf *codegen.Value) {

Callers 1

encodeFieldMethod · 0.95

Calls 15

writeZigzagMethod · 0.95
writeFixed32Method · 0.95
writeFixed64Method · 0.95
debugMethod · 0.95
writeBytesMethod · 0.95
writeBlobMethod · 0.95
writeWireAndTagMethod · 0.95
entMethod · 0.95
newBufMethod · 0.95
writeBufferMethod · 0.95
writeVarintMethod · 0.95
NotEqualMethod · 0.80

Tested by

no test coverage detected