DeserializeExtension returns the Extension that was serialized in the byte slice. Returns an empty Extension (has an invalid ID) if data is nil or empty.
(ctx context.Context, data []byte)
| 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. |
| 47 | func DeserializeExtension(ctx context.Context, data []byte) (Extension, error) { |
| 48 | if len(data) == 0 { |
| 49 | return Extension{}, nil |
| 50 | } |
| 51 | reader := utils.NewReader(data) |
| 52 | version := reader.VariableUint() |
| 53 | if version != 0 { |
| 54 | return Extension{}, errors.Errorf("version %d of extensions are not supported, please upgrade the server", version) |
| 55 | } |
| 56 | |
| 57 | // Read from the reader |
| 58 | ext := Extension{} |
| 59 | ext.ExtName = id.Extension(reader.Id()) |
| 60 | ext.Namespace = id.Namespace(reader.Id()) |
| 61 | ext.Relocatable = reader.Bool() |
| 62 | ext.LibIdentifier = LibraryIdentifier(reader.String()) |
| 63 | if !reader.IsEmpty() { |
| 64 | return Extension{}, errors.Errorf("extra data found while deserializing an extension") |
| 65 | } |
| 66 | // Return the deserialized object |
| 67 | return ext, nil |
| 68 | } |
no test coverage detected