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

Function deserializeArray

server/types/array.go:140–169  ·  view source on GitHub ↗

deserializeArray deserializes an array of given base type.

(ctx *sql.Context, data []byte, baseType *DoltgresType)

Source from the content-addressed store, hash-verified

138
139// deserializeArray deserializes an array of given base type.
140func deserializeArray(ctx *sql.Context, data []byte, baseType *DoltgresType) ([]any, error) {
141 // Check for the nil value, then ensure the minimum length of the slice
142 if len(data) == 0 {
143 return nil, nil
144 }
145 if len(data) < 4 {
146 return nil, errors.Errorf("deserializing non-nil array value has invalid length of %d", len(data))
147 }
148 // Grab the number of elements and construct an output slice of the appropriate size
149 elementCount := binary.LittleEndian.Uint32(data)
150 output := make([]any, elementCount)
151 // Read all elements
152 for i := uint32(0); i < elementCount; i++ {
153 // We read from i+1 to account for the element count at the beginning
154 offset := binary.LittleEndian.Uint32(data[(i+1)*4:])
155 // If the value is null, then we can skip it, since the output slice default initializes all values to nil
156 if data[offset] == 1 {
157 continue
158 }
159 // The element data is everything from the offset to the next offset, excluding the null determinant
160 nextOffset := binary.LittleEndian.Uint32(data[(i+2)*4:])
161 o, err := baseType.DeserializeValue(ctx, data[offset+1:nextOffset])
162 if err != nil {
163 return nil, err
164 }
165 output[i] = o
166 }
167 // Returns all read elements
168 return output, nil
169}

Callers 3

deserializeTypeArrayFunction · 0.85
deserializeTypeOidvectorFunction · 0.85

Calls 3

DeserializeValueMethod · 0.80
ErrorfMethod · 0.65
Uint32Method · 0.65

Tested by

no test coverage detected