readSliceRefAndType handles reference and type reading for slice serializers. Returns (true, 0) if a reference was resolved (value already set). Returns (false, typeId) if data should be written and typeId was read (if readType=true).
(ctx *ReadContext, refMode RefMode, readType bool, value reflect.Value)
| 74 | // Returns (true, 0) if a reference was resolved (value already set). |
| 75 | // Returns (false, typeId) if data should be written and typeId was read (if readType=true). |
| 76 | func readSliceRefAndType(ctx *ReadContext, refMode RefMode, readType bool, value reflect.Value) (bool, uint32) { |
| 77 | buf := ctx.Buffer() |
| 78 | ctxErr := ctx.Err() |
| 79 | switch refMode { |
| 80 | case RefModeTracking: |
| 81 | refID, refErr := ctx.RefResolver().TryPreserveRefId(buf) |
| 82 | if refErr != nil { |
| 83 | ctx.SetError(FromError(refErr)) |
| 84 | return true, 0 |
| 85 | } |
| 86 | if refID < int32(NotNullValueFlag) { |
| 87 | obj := ctx.RefResolver().GetReadObject(refID) |
| 88 | if obj.IsValid() { |
| 89 | value.Set(obj) |
| 90 | } |
| 91 | return true, 0 |
| 92 | } |
| 93 | case RefModeNullOnly: |
| 94 | flag := buf.ReadInt8(ctxErr) |
| 95 | if flag == NullFlag { |
| 96 | return true, 0 |
| 97 | } |
| 98 | } |
| 99 | var typeId uint32 |
| 100 | if readType { |
| 101 | typeId = uint32(buf.ReadUint8(ctxErr)) |
| 102 | } |
| 103 | return false, typeId |
| 104 | } |
| 105 | |
| 106 | // Helper function to check if a value is null/nil |
| 107 | func isNull(v reflect.Value) bool { |
no test coverage detected