diff --git a/src/minutils/data_encoding.ml b/src/minutils/data_encoding.ml index 3de84af44..2da130d06 100644 --- a/src/minutils/data_encoding.ml +++ b/src/minutils/data_encoding.ml @@ -1178,4 +1178,14 @@ let rec length : type x. x t -> x -> int = fun e -> let to_bytes = to_bytes let length = length + + let fixed_length e = + match classify e with + | `Fixed n -> Some n + | `Dynamic | `Variable -> None + let fixed_length_exn e = + match fixed_length e with + | Some n -> n + | None -> invalid_arg "Data_encoding.Binary.fixed_length_exn" + end diff --git a/src/minutils/data_encoding.mli b/src/minutils/data_encoding.mli index be410b820..8bac5d62f 100644 --- a/src/minutils/data_encoding.mli +++ b/src/minutils/data_encoding.mli @@ -236,4 +236,7 @@ module Binary : sig val to_bytes : 'a encoding -> 'a -> MBytes.t val of_bytes : 'a encoding -> MBytes.t -> 'a option + val fixed_length : 'a encoding -> int option + val fixed_length_exn : 'a encoding -> int + end