(msgDescriptor protoreflect.MessageDescriptor, value string)
| 286 | } |
| 287 | |
| 288 | func parseMessage(msgDescriptor protoreflect.MessageDescriptor, value string) (protoreflect.Value, error) { |
| 289 | var msg proto.Message |
| 290 | switch msgDescriptor.FullName() { |
| 291 | case "google.protobuf.Timestamp": |
| 292 | t, err := time.Parse(time.RFC3339Nano, value) |
| 293 | if err != nil { |
| 294 | return protoreflect.Value{}, err |
| 295 | } |
| 296 | timestamp := timestamppb.New(t) |
| 297 | if ok := timestamp.IsValid(); !ok { |
| 298 | return protoreflect.Value{}, fmt.Errorf("%s before 0001-01-01", value) |
| 299 | } |
| 300 | msg = timestamp |
| 301 | case "google.protobuf.Duration": |
| 302 | d, err := time.ParseDuration(value) |
| 303 | if err != nil { |
| 304 | return protoreflect.Value{}, err |
| 305 | } |
| 306 | msg = durationpb.New(d) |
| 307 | case "google.protobuf.DoubleValue": |
| 308 | v, err := strconv.ParseFloat(value, 64) |
| 309 | if err != nil { |
| 310 | return protoreflect.Value{}, err |
| 311 | } |
| 312 | msg = wrapperspb.Double(v) |
| 313 | case "google.protobuf.FloatValue": |
| 314 | v, err := strconv.ParseFloat(value, 32) |
| 315 | if err != nil { |
| 316 | return protoreflect.Value{}, err |
| 317 | } |
| 318 | msg = wrapperspb.Float(float32(v)) |
| 319 | case "google.protobuf.Int64Value": |
| 320 | v, err := strconv.ParseInt(value, 10, 64) |
| 321 | if err != nil { |
| 322 | return protoreflect.Value{}, err |
| 323 | } |
| 324 | msg = wrapperspb.Int64(v) |
| 325 | case "google.protobuf.Int32Value": |
| 326 | v, err := strconv.ParseInt(value, 10, 32) |
| 327 | if err != nil { |
| 328 | return protoreflect.Value{}, err |
| 329 | } |
| 330 | msg = wrapperspb.Int32(int32(v)) |
| 331 | case "google.protobuf.UInt64Value": |
| 332 | v, err := strconv.ParseUint(value, 10, 64) |
| 333 | if err != nil { |
| 334 | return protoreflect.Value{}, err |
| 335 | } |
| 336 | msg = wrapperspb.UInt64(v) |
| 337 | case "google.protobuf.UInt32Value": |
| 338 | v, err := strconv.ParseUint(value, 10, 32) |
| 339 | if err != nil { |
| 340 | return protoreflect.Value{}, err |
| 341 | } |
| 342 | msg = wrapperspb.UInt32(uint32(v)) |
| 343 | case "google.protobuf.BoolValue": |
| 344 | v, err := strconv.ParseBool(value) |
| 345 | if err != nil { |
no test coverage detected