Serialize returns the Procedure as a byte slice. If the Procedure is invalid, then this returns a nil slice.
(ctx context.Context)
| 26 | |
| 27 | // Serialize returns the Procedure as a byte slice. If the Procedure is invalid, then this returns a nil slice. |
| 28 | func (procedure Procedure) Serialize(ctx context.Context) ([]byte, error) { |
| 29 | if !procedure.ID.IsValid() { |
| 30 | return nil, nil |
| 31 | } |
| 32 | |
| 33 | // Write all of the procedures to the writer |
| 34 | writer := utils.NewWriter(256) |
| 35 | writer.VariableUint(1) // Version |
| 36 | // Write the procedure data |
| 37 | writer.Id(procedure.ID.AsId()) |
| 38 | writer.StringSlice(procedure.ParameterNames) |
| 39 | writer.IdTypeSlice(procedure.ParameterTypes) |
| 40 | writer.String(procedure.Definition) |
| 41 | writer.String(procedure.ExtensionName) |
| 42 | writer.String(procedure.ExtensionSymbol) |
| 43 | writer.String(procedure.SQLDefinition) |
| 44 | // Write the parameter modes |
| 45 | writer.VariableUint(uint64(len(procedure.ParameterModes))) |
| 46 | for _, mode := range procedure.ParameterModes { |
| 47 | writer.Uint8(uint8(mode)) |
| 48 | } |
| 49 | // Write the operations |
| 50 | writer.VariableUint(uint64(len(procedure.Operations))) |
| 51 | for _, op := range procedure.Operations { |
| 52 | writer.Uint16(uint16(op.OpCode)) |
| 53 | writer.String(op.PrimaryData) |
| 54 | writer.StringSlice(op.SecondaryData) |
| 55 | writer.String(op.Target) |
| 56 | writer.Int32(int32(op.Index)) |
| 57 | writer.StringMap(op.Options) |
| 58 | } |
| 59 | // Write version 1 data |
| 60 | writer.StringSlice(procedure.ParameterDefaults) |
| 61 | // Returns the data |
| 62 | return writer.Data(), nil |
| 63 | } |
| 64 | |
| 65 | // DeserializeProcedure returns the Procedure that was serialized in the byte slice. Returns an empty Procedure (invalid |
| 66 | // ID) if data is nil or empty. |
no test coverage detected