Serialize returns the Extension as a byte slice. If the Extension is invalid (invalid ExtName), then this returns a nil slice.
(ctx context.Context)
| 26 | // Serialize returns the Extension as a byte slice. If the Extension is invalid (invalid ExtName), then this returns a |
| 27 | // nil slice. |
| 28 | func (ext Extension) Serialize(ctx context.Context) ([]byte, error) { |
| 29 | if !ext.ExtName.IsValid() { |
| 30 | return nil, nil |
| 31 | } |
| 32 | |
| 33 | // Initialize the writer |
| 34 | writer := utils.NewWriter(256) |
| 35 | writer.VariableUint(0) // Version |
| 36 | // Write the extension data |
| 37 | writer.Id(ext.ExtName.AsId()) |
| 38 | writer.Id(ext.Namespace.AsId()) |
| 39 | writer.Bool(ext.Relocatable) |
| 40 | writer.String(string(ext.LibIdentifier)) |
| 41 | // Returns the data |
| 42 | return writer.Data(), nil |
| 43 | } |
| 44 | |
| 45 | // DeserializeExtension returns the Extension that was serialized in the byte slice. Returns an empty Extension (has an |
| 46 | // invalid ID) if data is nil or empty. |