@@ -23,15 +23,17 @@ use std::{borrow::Cow, fmt};
2323
2424use ndarray:: { Array , Array1 , ArrayBase , ArrayD , ArrayViewMutD , Data , Dimension , ShapeError } ;
2525use numcodecs:: {
26- serialize_codec_config_with_id , AnyArray , AnyArrayDType , AnyArrayView , AnyArrayViewMut ,
27- AnyCowArray , Codec , StaticCodec ,
26+ AnyArray , AnyArrayDType , AnyArrayView , AnyArrayViewMut , AnyCowArray , Codec , StaticCodec ,
27+ StaticCodecConfig ,
2828} ;
29- use serde:: { de:: DeserializeOwned , Deserialize , Deserializer , Serialize , Serializer } ;
29+ use schemars:: { JsonSchema , JsonSchema_repr } ;
30+ use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
3031use serde_repr:: { Deserialize_repr , Serialize_repr } ;
3132use thiserror:: Error ;
3233use twofloat:: TwoFloat ;
3334
34- #[ derive( Clone , Serialize , Deserialize ) ]
35+ #[ derive( Clone , Serialize , Deserialize , JsonSchema ) ]
36+ #[ serde( deny_unknown_fields) ]
3537/// Lossy codec to reduce the precision of floating point data.
3638///
3739/// The data is quantized to unsigned integers of the best-fitting type.
@@ -44,7 +46,8 @@ pub struct LinearQuantizeCodec {
4446}
4547
4648/// Data types which the [`LinearQuantizeCodec`] can quantize
47- #[ derive( Copy , Clone , Debug , serde:: Serialize , serde:: Deserialize ) ]
49+ #[ derive( Copy , Clone , Debug , Serialize , Deserialize , JsonSchema ) ]
50+ #[ schemars( extend( "enum" = [ "f32" , "float32" , "f64" , "float64" ] ) ) ]
4851#[ allow( missing_docs) ]
4952pub enum LinearQuantizeDType {
5053 #[ serde( rename = "f32" , alias = "float32" ) ]
@@ -67,7 +70,7 @@ impl fmt::Display for LinearQuantizeDType {
6770/// The binary `#[repr(u8)]` value of each variant is equivalent to the binary
6871/// logarithm of the number of bins, i.e. the binary precision or the number of
6972/// bits used.
70- #[ derive( Copy , Clone , Serialize_repr , Deserialize_repr ) ]
73+ #[ derive( Copy , Clone , Serialize_repr , Deserialize_repr , JsonSchema_repr ) ]
7174#[ repr( u8 ) ]
7275#[ rustfmt:: skip]
7376#[ allow( missing_docs) ]
@@ -382,17 +385,19 @@ impl Codec for LinearQuantizeCodec {
382385
383386 Ok ( ( ) )
384387 }
385-
386- fn get_config < S : Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
387- serialize_codec_config_with_id ( self , self , serializer)
388- }
389388}
390389
391390impl StaticCodec for LinearQuantizeCodec {
392391 const CODEC_ID : & ' static str = "linear-quantize" ;
393392
394- fn from_config < ' de , D : Deserializer < ' de > > ( config : D ) -> Result < Self , D :: Error > {
395- Self :: deserialize ( config)
393+ type Config < ' de > = Self ;
394+
395+ fn from_config ( config : Self :: Config < ' _ > ) -> Self {
396+ config
397+ }
398+
399+ fn get_config ( & self ) -> StaticCodecConfig < Self > {
400+ StaticCodecConfig :: from ( self )
396401 }
397402}
398403
@@ -714,7 +719,7 @@ impl Unsigned for u64 {
714719 const ZERO : Self = 0 ;
715720}
716721
717- #[ derive( serde :: Serialize , serde :: Deserialize ) ]
722+ #[ derive( Serialize , Deserialize ) ]
718723#[ serde( bound = "" ) ]
719724struct CompressionHeader < ' a , T : Float > {
720725 #[ serde( borrow) ]
0 commit comments