Encode serializes apis to a byte slice.
(apis []*semantic.API, mappings *semantic.Mappings)
| 171 | |
| 172 | // Encode serializes apis to a byte slice. |
| 173 | func Encode(apis []*semantic.API, mappings *semantic.Mappings) ([]byte, error) { |
| 174 | e := &encoder{instances: &Instances{}} |
| 175 | e.maps.build() |
| 176 | content := &Content{ |
| 177 | Instances: e.instances, |
| 178 | Apis: make([]uint64, len(apis)), |
| 179 | } |
| 180 | |
| 181 | // Serialize the APIs. |
| 182 | for i, api := range apis { |
| 183 | content.Apis[i] = e.api(api) |
| 184 | } |
| 185 | |
| 186 | // Serialize the mappings. |
| 187 | content.Mappings = e.mappings(mappings) |
| 188 | |
| 189 | data, err := proto.Marshal(content) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | return data, nil |
| 194 | } |
| 195 | |
| 196 | func (e *encoder) mappings(m *semantic.Mappings) *Mappings { |
| 197 | out := Mappings{} |