unmarshalRowField decodes a single protojson RowValue oneof field.
(key string, val json.RawMessage)
| 271 | |
| 272 | // unmarshalRowField decodes a single protojson RowValue oneof field. |
| 273 | func unmarshalRowField(key string, val json.RawMessage) (any, bool) { |
| 274 | switch key { |
| 275 | case "nullValue": |
| 276 | return nil, true |
| 277 | case "boolValue": |
| 278 | return unmarshalAs[bool](val) |
| 279 | case "stringValue": |
| 280 | return unmarshalAs[string](val) |
| 281 | case "int32Value": |
| 282 | return unmarshalAs[int32](val) |
| 283 | case "int64Value": |
| 284 | // protojson encodes int64 as string. |
| 285 | if v, ok := unmarshalAs[string](val); ok { |
| 286 | return v, true |
| 287 | } |
| 288 | return unmarshalAs[int64](val) |
| 289 | case "doubleValue", "floatValue": |
| 290 | return unmarshalAs[float64](val) |
| 291 | case "timestampValue", "timestampTzValue": |
| 292 | return unmarshalTimestamp(val) |
| 293 | default: |
| 294 | if v, ok := unmarshalAs[string](val); ok { |
| 295 | return v, true |
| 296 | } |
| 297 | return string(val), true |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // unmarshalAs attempts to decode JSON into the given type. |
| 302 | func unmarshalAs[T any](val json.RawMessage) (T, bool) { |
no test coverage detected