DeserializeCast returns the Cast that was serialized in the byte slice. Returns an empty Cast (invalid ID) if data is nil or empty.
(ctx context.Context, data []byte)
| 44 | // DeserializeCast returns the Cast that was serialized in the byte slice. Returns an empty Cast (invalid ID) if data is |
| 45 | // nil or empty. |
| 46 | func DeserializeCast(ctx context.Context, data []byte) (Cast, error) { |
| 47 | if len(data) == 0 { |
| 48 | return Cast{}, nil |
| 49 | } |
| 50 | reader := utils.NewReader(data) |
| 51 | version := reader.VariableUint() |
| 52 | if version != 0 { |
| 53 | return Cast{}, errors.Errorf("version %d of casts is not supported, please upgrade the server", version) |
| 54 | } |
| 55 | |
| 56 | // Read from the reader |
| 57 | t := Cast{} |
| 58 | t.ID = id.Cast(reader.Id()) |
| 59 | t.CastType = CastType(reader.Uint8()) |
| 60 | t.Function = id.Function(reader.Id()) |
| 61 | t.UseInOut = reader.Bool() |
| 62 | if !reader.IsEmpty() { |
| 63 | return Cast{}, errors.Errorf("extra data found while deserializing a cast") |
| 64 | } |
| 65 | // Return the deserialized object |
| 66 | return t, nil |
| 67 | } |