Serialize returns the Sequence as a byte slice. If the Sequence is nil, then this returns a nil slice.
(ctx context.Context)
| 25 | |
| 26 | // Serialize returns the Sequence as a byte slice. If the Sequence is nil, then this returns a nil slice. |
| 27 | func (sequence *Sequence) Serialize(ctx context.Context) ([]byte, error) { |
| 28 | if sequence == nil { |
| 29 | return nil, nil |
| 30 | } |
| 31 | |
| 32 | // Create the writer |
| 33 | writer := utils.NewWriter(256) |
| 34 | writer.VariableUint(1) // Version |
| 35 | // Write the sequence data |
| 36 | writer.Id(sequence.Id.AsId()) |
| 37 | writer.Id(sequence.DataTypeID.AsId()) |
| 38 | writer.Uint8(uint8(sequence.Persistence)) |
| 39 | writer.Int64(sequence.Start) |
| 40 | writer.Int64(sequence.Current) |
| 41 | writer.Int64(sequence.Increment) |
| 42 | writer.Int64(sequence.Minimum) |
| 43 | writer.Int64(sequence.Maximum) |
| 44 | writer.Int64(sequence.Cache) |
| 45 | writer.Bool(sequence.Cycle) |
| 46 | writer.Bool(sequence.IsAtEnd) |
| 47 | writer.Bool(sequence.HasBeenCalled) |
| 48 | writer.Id(sequence.OwnerTable.AsId()) |
| 49 | writer.String(sequence.OwnerColumn) |
| 50 | // Returns the data |
| 51 | return writer.Data(), nil |
| 52 | } |
| 53 | |
| 54 | // DeserializeSequence returns the Sequence that was serialized in the byte slice. Returns an empty Sequence if data is |
| 55 | // nil or empty. |