diff --git a/src/proto/environment/data_encoding.mli b/src/proto/environment/data_encoding.mli index c9fda6c94..32320d469 100644 --- a/src/proto/environment/data_encoding.mli +++ b/src/proto/environment/data_encoding.mli @@ -147,6 +147,8 @@ val merge_tups : 'a1 encoding -> 'a2 encoding -> ('a1 * 'a2) encoding val array : 'a encoding -> 'a array encoding val list : 'a encoding -> 'a list encoding +val assoc : 'a encoding -> (string * 'a) list encoding + type 't case val case : ?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case diff --git a/src/utils/data_encoding.ml b/src/utils/data_encoding.ml index 9e601a3fc..e1c0f6798 100644 --- a/src/utils/data_encoding.ml +++ b/src/utils/data_encoding.ml @@ -719,6 +719,10 @@ module Encoding = struct `Variable in make @@ Mu (kind, name, self) + let assoc enc = + let json = Json_encoding.assoc (Json.get_json enc) in + let binary = list (tup2 string enc) in + raw_splitted ~json ~binary end include Encoding diff --git a/src/utils/data_encoding.mli b/src/utils/data_encoding.mli index 130ff4066..176d9edf1 100644 --- a/src/utils/data_encoding.mli +++ b/src/utils/data_encoding.mli @@ -155,6 +155,8 @@ val merge_tups : 'a1 encoding -> 'a2 encoding -> ('a1 * 'a2) encoding val array : 'a encoding -> 'a array encoding val list : 'a encoding -> 'a list encoding +val assoc : 'a encoding -> (string * 'a) list encoding + type 't case val case : ?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case