(tag string)
| 530 | } |
| 531 | |
| 532 | func parseStructTag(tag string) (structTag, error) { |
| 533 | t := structTag{ |
| 534 | version: 2, |
| 535 | extensions: make(map[string]string), |
| 536 | } |
| 537 | |
| 538 | for i, f := range splitFields(tag) { |
| 539 | switch i { |
| 540 | case 0: |
| 541 | switch f { |
| 542 | case "varint": |
| 543 | t.wireType = Varint |
| 544 | case "bytes": |
| 545 | t.wireType = Varlen |
| 546 | case "fixed32": |
| 547 | t.wireType = Fixed32 |
| 548 | case "fixed64": |
| 549 | t.wireType = Fixed64 |
| 550 | case "zigzag32": |
| 551 | t.wireType = Varint |
| 552 | t.zigzag = true |
| 553 | case "zigzag64": |
| 554 | t.wireType = Varint |
| 555 | t.zigzag = true |
| 556 | default: |
| 557 | return t, fmt.Errorf("unsupported wire type in struct tag %q: %s", tag, f) |
| 558 | } |
| 559 | |
| 560 | case 1: |
| 561 | n, err := strconv.Atoi(f) |
| 562 | if err != nil { |
| 563 | return t, fmt.Errorf("unsupported field number in struct tag %q: %w", tag, err) |
| 564 | } |
| 565 | t.fieldNumber = FieldNumber(n) |
| 566 | |
| 567 | case 2: |
| 568 | switch f { |
| 569 | case "opt": |
| 570 | // not sure what this is for |
| 571 | case "rep": |
| 572 | t.repeated = true |
| 573 | default: |
| 574 | return t, fmt.Errorf("unsupported field option in struct tag %q: %s", tag, f) |
| 575 | } |
| 576 | |
| 577 | default: |
| 578 | name, value := splitNameValue(f) |
| 579 | switch name { |
| 580 | case "name": |
| 581 | t.name = value |
| 582 | case "enum": |
| 583 | t.enum = value |
| 584 | case "json": |
| 585 | t.json = value |
| 586 | case "proto3": |
| 587 | t.version = 3 |
| 588 | default: |
| 589 | t.extensions[name] = value |
searching dependent graphs…