ReadFile reads the descriptors from a file.
(filename string)
| 134 | |
| 135 | // ReadFile reads the descriptors from a file. |
| 136 | func ReadFile(filename string) (MessageDescriptorMap, error) { |
| 137 | bytes, err := os.ReadFile(filename) |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | descriptors := make(MessageDescriptorMap) |
| 142 | err = json.Unmarshal(bytes, &descriptors) |
| 143 | if err != nil { |
| 144 | return nil, err |
| 145 | } |
| 146 | for id, descriptor := range descriptors { |
| 147 | descriptor.id = id |
| 148 | } |
| 149 | return descriptors, nil |
| 150 | } |
| 151 | |
| 152 | // MarshalJSON marshals the descriptors to JSON. |
| 153 | func (m MessageDescriptorMap) MarshalJSON() ([]byte, error) { |