11use crate :: { api_bail, api_error} ;
2-
2+ use bytes :: Bytes ;
33use super :: schema:: * ;
44use anyhow:: Result ;
55use base64:: prelude:: * ;
@@ -73,7 +73,7 @@ impl<'de> Deserialize<'de> for RangeValue {
7373/// Value of key.
7474#[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
7575pub enum KeyValue {
76- Bytes ( Arc < [ u8 ] > ) ,
76+ Bytes ( Bytes ) ,
7777 Str ( Arc < str > ) ,
7878 Bool ( bool ) ,
7979 Int64 ( i64 ) ,
@@ -83,15 +83,15 @@ pub enum KeyValue {
8383 Struct ( Vec < KeyValue > ) ,
8484}
8585
86- impl From < Arc < [ u8 ] > > for KeyValue {
87- fn from ( value : Arc < [ u8 ] > ) -> Self {
86+ impl From < Bytes > for KeyValue {
87+ fn from ( value : Bytes ) -> Self {
8888 KeyValue :: Bytes ( value)
8989 }
9090}
9191
9292impl From < Vec < u8 > > for KeyValue {
9393 fn from ( value : Vec < u8 > ) -> Self {
94- KeyValue :: Bytes ( Arc :: from ( value) )
94+ KeyValue :: Bytes ( Bytes :: from ( value) )
9595 }
9696}
9797
@@ -197,7 +197,7 @@ impl KeyValue {
197197 . ok_or_else ( || api_error ! ( "Key parts less than expected" ) ) ?;
198198 match basic_type {
199199 BasicValueType :: Bytes { .. } => {
200- KeyValue :: Bytes ( Arc :: from ( BASE64_STANDARD . decode ( v) ?) )
200+ KeyValue :: Bytes ( Bytes :: from ( BASE64_STANDARD . decode ( v) ?) )
201201 }
202202 BasicValueType :: Str { .. } => KeyValue :: Str ( Arc :: from ( v) ) ,
203203 BasicValueType :: Bool => KeyValue :: Bool ( v. parse ( ) ?) ,
@@ -275,7 +275,7 @@ impl KeyValue {
275275 }
276276 }
277277
278- pub fn bytes_value ( & self ) -> Result < & Arc < [ u8 ] > > {
278+ pub fn bytes_value ( & self ) -> Result < & Bytes > {
279279 match self {
280280 KeyValue :: Bytes ( v) => Ok ( v) ,
281281 _ => anyhow:: bail!( "expected bytes value, but got {}" , self . kind_str( ) ) ,
@@ -342,7 +342,7 @@ impl KeyValue {
342342
343343#[ derive( Debug , Clone ) ]
344344pub enum BasicValue {
345- Bytes ( Arc < [ u8 ] > ) ,
345+ Bytes ( Bytes ) ,
346346 Str ( Arc < str > ) ,
347347 Bool ( bool ) ,
348348 Int64 ( i64 ) ,
@@ -358,15 +358,15 @@ pub enum BasicValue {
358358 Vector ( Arc < [ BasicValue ] > ) ,
359359}
360360
361- impl From < Arc < [ u8 ] > > for BasicValue {
362- fn from ( value : Arc < [ u8 ] > ) -> Self {
361+ impl From < Bytes > for BasicValue {
362+ fn from ( value : Bytes ) -> Self {
363363 BasicValue :: Bytes ( value)
364364 }
365365}
366366
367367impl From < Vec < u8 > > for BasicValue {
368368 fn from ( value : Vec < u8 > ) -> Self {
369- BasicValue :: Bytes ( Arc :: from ( value) )
369+ BasicValue :: Bytes ( Bytes :: from ( value) )
370370 }
371371}
372372
@@ -674,7 +674,7 @@ impl<VS> Value<VS> {
674674 }
675675 }
676676
677- pub fn as_bytes ( & self ) -> Result < & Arc < [ u8 ] > > {
677+ pub fn as_bytes ( & self ) -> Result < & Bytes > {
678678 match self {
679679 Value :: Basic ( BasicValue :: Bytes ( v) ) => Ok ( v) ,
680680 _ => anyhow:: bail!( "expected bytes value, but got {}" , self . kind( ) ) ,
@@ -870,7 +870,7 @@ impl BasicValue {
870870 pub fn from_json ( value : serde_json:: Value , schema : & BasicValueType ) -> Result < Self > {
871871 let result = match ( value, schema) {
872872 ( serde_json:: Value :: String ( v) , BasicValueType :: Bytes { .. } ) => {
873- BasicValue :: Bytes ( Arc :: from ( BASE64_STANDARD . decode ( v) ?) )
873+ BasicValue :: Bytes ( Bytes :: from ( BASE64_STANDARD . decode ( v) ?) )
874874 }
875875 ( serde_json:: Value :: String ( v) , BasicValueType :: Str { .. } ) => {
876876 BasicValue :: Str ( Arc :: from ( v) )
0 commit comments