Shell: add Data_encoding.Binary.fixed_length

This commit is contained in:
Vincent Bernardoff 2017-01-14 13:13:41 +01:00 committed by Grégoire Henry
parent 22ae4dbf45
commit 5eb8d0077a
2 changed files with 13 additions and 0 deletions

View File

@ -1178,4 +1178,14 @@ let rec length : type x. x t -> x -> int = fun e ->
let to_bytes = to_bytes let to_bytes = to_bytes
let length = length 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 end

View File

@ -236,4 +236,7 @@ module Binary : sig
val to_bytes : 'a encoding -> 'a -> MBytes.t val to_bytes : 'a encoding -> 'a -> MBytes.t
val of_bytes : 'a encoding -> MBytes.t -> 'a option val of_bytes : 'a encoding -> MBytes.t -> 'a option
val fixed_length : 'a encoding -> int option
val fixed_length_exn : 'a encoding -> int
end end