deserializeArray deserializes an array of given base type.
(ctx *sql.Context, data []byte, baseType *DoltgresType)
| 138 | |
| 139 | // deserializeArray deserializes an array of given base type. |
| 140 | func 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 | } |
no test coverage detected