Format prints the Format to w.
(w fmt.State, r rune)
| 45 | |
| 46 | // Format prints the Format to w. |
| 47 | func (f Format) Format(w fmt.State, r rune) { |
| 48 | buf := &bytes.Buffer{} |
| 49 | samplings, datatypes := unique{}, unique{} |
| 50 | for _, c := range f.Components { |
| 51 | fmt.Fprint(buf, c.Channel) |
| 52 | datatypes.check(c.DataType) |
| 53 | samplings.check(c.Sampling) |
| 54 | } |
| 55 | fmt.Fprint(buf, "_") |
| 56 | |
| 57 | defaultSampling := Sampling{} |
| 58 | |
| 59 | if !datatypes.unique || !samplings.unique { |
| 60 | for _, c := range f.Components { |
| 61 | if !samplings.unique && !c.Sampling.Is(defaultSampling) { |
| 62 | fmt.Fprintf(buf, "%c", c.Sampling) |
| 63 | } |
| 64 | fmt.Fprint(buf, c.DataType) |
| 65 | } |
| 66 | if samplings.unique && !proto.Equal(samplings.value, &defaultSampling) { |
| 67 | fmt.Fprint(buf, "_", *samplings.value.(*Sampling)) |
| 68 | } |
| 69 | } else { |
| 70 | if datatypes.unique { |
| 71 | fmt.Fprint(buf, *datatypes.value.(*DataType)) |
| 72 | } |
| 73 | if samplings.unique && !proto.Equal(samplings.value, &defaultSampling) { |
| 74 | fmt.Fprint(buf, "_", *samplings.value.(*Sampling)) |
| 75 | } |
| 76 | } |
| 77 | name := buf.String() |
| 78 | if alias, ok := aliases[name]; ok { |
| 79 | w.Write([]byte(alias)) |
| 80 | } else { |
| 81 | w.Write([]byte(name)) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Clone returns a copy of this format. |
| 86 | func (f *Format) Clone() *Format { |