(ctx *WriteContext, value reflect.Value)
| 145 | } |
| 146 | |
| 147 | func (s *structSerializer) WriteData(ctx *WriteContext, value reflect.Value) { |
| 148 | // Early error check - skip all intermediate checks for normal path performance |
| 149 | if ctx.HasError() { |
| 150 | return |
| 151 | } |
| 152 | |
| 153 | // Lazy initialization |
| 154 | if !s.initialized { |
| 155 | if err := s.initialize(ctx.TypeResolver()); err != nil { |
| 156 | ctx.SetError(FromError(err)) |
| 157 | return |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | buf := ctx.Buffer() |
| 162 | |
| 163 | // Dereference pointer if needed |
| 164 | if value.Kind() == reflect.Ptr { |
| 165 | if value.IsNil() { |
| 166 | ctx.SetError(SerializationError("cannot write nil pointer")) |
| 167 | return |
| 168 | } |
| 169 | value = value.Elem() |
| 170 | } |
| 171 | |
| 172 | // In compatible mode with meta share, struct hash is not written |
| 173 | if !ctx.Compatible() { |
| 174 | buf.WriteInt32(s.structHash) |
| 175 | } |
| 176 | |
| 177 | // Ensure value is addressable for unsafe access |
| 178 | if !value.CanAddr() { |
| 179 | reuseCache := s.tempValue != nil |
| 180 | if ctx.RefResolver().refTracking && len(ctx.RefResolver().writtenObjects) > 0 { |
| 181 | reuseCache = false |
| 182 | } |
| 183 | if reuseCache { |
| 184 | tempValue := s.tempValue |
| 185 | s.tempValue = nil |
| 186 | defer func() { |
| 187 | tempValue.SetZero() |
| 188 | s.tempValue = tempValue |
| 189 | }() |
| 190 | addrValue := *tempValue |
| 191 | addrValue.Set(value) |
| 192 | value = addrValue |
| 193 | } else { |
| 194 | tmp := reflect.New(value.Type()).Elem() |
| 195 | tmp.Set(value) |
| 196 | value = tmp |
| 197 | } |
| 198 | } |
| 199 | ptr := unsafe.Pointer(value.UnsafeAddr()) |
| 200 | |
| 201 | // ========================================================================== |
| 202 | // Phase 1: Fixed-size primitives (bool, int8, int16, float32, float64) |
| 203 | // - Reserve once, inline unsafe writes with endian handling, update index once |
| 204 | // - field.WriteOffset computed at init time |
no test coverage detected