Skip to content

Commit fa7439a

Browse files
committed
Ensure sharding codec chains is parsed during construction.
1 parent e5caead commit fa7439a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/codecs/array_to_bytes.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ end = struct
203203

204204
type t = shard_config
205205

206+
let parse_chain repr chain =
207+
List.fold_left
208+
(fun acc c ->
209+
acc >>= fun r ->
210+
ArrayToArray.parse r c >>= fun () ->
211+
ArrayToArray.compute_encoded_representation c r) (Ok repr) chain.a2a
212+
>>= fun repr' ->
213+
ArrayToBytes.parse repr' chain.a2b
214+
206215
let parse
207216
: type a b.
208217
(a, b) Util.array_repr ->
@@ -217,15 +226,18 @@ end = struct
217226
the decoded representaton of a shard." in
218227
Result.error @@ `Sharding (t.chunk_shape, repr.shape, msg))
219228
>>= fun () ->
220-
match
229+
(match
221230
Array.for_all2 (fun x y -> (x mod y) = 0) repr.shape t.chunk_shape
222231
with
223232
| true -> Ok ()
224233
| false ->
225234
let msg =
226235
"sharding chunk_shape must evenly divide the size of the shard shape."
227236
in
228-
Result.error @@ `Sharding (t.chunk_shape, repr.shape, msg)
237+
Result.error @@ `Sharding (t.chunk_shape, repr.shape, msg))
238+
>>= fun () ->
239+
parse_chain repr t.codecs >>= fun () ->
240+
parse_chain repr t.index_codecs
229241

230242
let compute_encoded_size input_size t =
231243
List.fold_left BytesToBytes.compute_encoded_size

0 commit comments

Comments
 (0)