MCPcopy Create free account
hub / github.com/dolthub/doltgresql / DeserializeFunction

Function DeserializeFunction

core/functions/serialization.go:69–118  ·  view source on GitHub ↗

DeserializeFunction returns the Function that was serialized in the byte slice. Returns an empty Function (invalid ID) if data is nil or empty.

(ctx context.Context, data []byte)

Source from the content-addressed store, hash-verified

67// DeserializeFunction returns the Function that was serialized in the byte slice. Returns an empty Function (invalid
68// ID) if data is nil or empty.
69func DeserializeFunction(ctx context.Context, data []byte) (Function, error) {
70 if len(data) == 0 {
71 return Function{}, nil
72 }
73 reader := utils.NewReader(data)
74 version := reader.VariableUint()
75 if version > 3 {
76 return Function{}, errors.Errorf("version %d of functions is not supported, please upgrade the server", version)
77 }
78
79 // Read from the reader
80 f := Function{}
81 f.ID = id.Function(reader.Id())
82 f.ReturnType = id.Type(reader.Id())
83 f.ParameterNames = reader.StringSlice()
84 f.ParameterTypes = reader.IdTypeSlice()
85 f.Variadic = reader.Bool()
86 f.IsNonDeterministic = reader.Bool()
87 f.Strict = reader.Bool()
88 f.Definition = reader.String()
89 // Read the operations
90 opCount := reader.VariableUint()
91 f.Operations = make([]plpgsql.InterpreterOperation, opCount)
92 for opIdx := uint64(0); opIdx < opCount; opIdx++ {
93 op := plpgsql.InterpreterOperation{}
94 op.OpCode = plpgsql.OpCode(reader.Uint16())
95 op.PrimaryData = reader.String()
96 op.SecondaryData = reader.StringSlice()
97 op.Target = reader.String()
98 op.Index = int(reader.Int32())
99 op.Options = reader.StringMap()
100 f.Operations[opIdx] = op
101 }
102 if version >= 1 {
103 f.ExtensionName = reader.String()
104 f.ExtensionSymbol = reader.String()
105 }
106 if version >= 2 {
107 f.SQLDefinition = reader.String()
108 f.SetOf = reader.Bool()
109 }
110 if version >= 3 {
111 f.ParameterDefaults = reader.StringSlice()
112 }
113 if !reader.IsEmpty() {
114 return Function{}, errors.Errorf("extra data found while deserializing a function")
115 }
116 // Return the deserialized object
117 return f, nil
118}

Callers 2

DeserializeRootObjectMethod · 0.85
reloadCachesMethod · 0.85

Calls 15

VariableUintMethod · 0.95
IdMethod · 0.95
StringSliceMethod · 0.95
IdTypeSliceMethod · 0.95
BoolMethod · 0.95
StringMethod · 0.95
Uint16Method · 0.95
Int32Method · 0.95
StringMapMethod · 0.95
IsEmptyMethod · 0.95
NewReaderFunction · 0.92
FunctionTypeAlias · 0.92

Tested by

no test coverage detected