//use std::fmt::Debug; use std::io::Cursor; use fluvio_protocol::{Decoder, Encoder}; #[derive(Encoder)] pub struct SimpleStructE { value: R, } type SSByte = SimpleStructE; #[test] fn test_generic_with_bounds() { let record = SSByte { value: 3 }; let mut src = vec![]; record.encode(&mut src, 0).expect("encode"); assert_eq!(src.len(), 1); } #[derive(Encoder)] pub struct SimpleVec { value: Vec, } type SV8 = SimpleVec; #[test] fn test_generic_with_bounds_vec() { let record = SV8 { value: vec![3] }; let mut src = vec![]; record.encode(&mut src, 0).expect("encode"); assert_eq!(src.len(), 5); } /* #[derive(Encoder)] #[fluvio(trace)] pub struct SimpleStructWithTrace { value: R, } type SSByteTrace = SimpleStructWithTrace; #[test] fn test_generic_with_bounds_with_trace() { let record = SSByteTrace { value: 3 }; let mut src = vec![]; let result = record.encode(&mut src, 0); assert!(result.is_ok()); assert_eq!(src.len(), 1); } */ #[derive(Decoder, Default)] pub struct SimpleStructD { value: R, } type SSByteD = SimpleStructD; #[test] fn test_decoding_generic() { let src = vec![3]; let d = SSByteD::decode_from(&mut Cursor::new(&src), 0).expect("decoded"); assert_eq!(d.value, 3); } #[derive(Decoder, Default)] pub struct SimpleVecD { value: Vec, } type _SVD8 = SimpleVecD; /* #[test] fn test_decoding_generic_with_vec() { let mut src = vec![]; src.push(3); let d = SVD8::decode_from(&mut Cursor::new(&src), 0).expect("decoded"); //assert_eq!(d.value, 3); } */ /* #[derive(Encoder, Decoder, Default, Debug)] pub struct GenericRecord where R: Encoder + Decoder + Debug, { len: i64, value: R, } #[test] fn test_generic() { let record = GenericRecord { len: 20, value: 25_i64, }; let mut src = vec![]; let result = record.encode(&mut src, 0); assert!(result.is_ok()); assert_eq!(src.len(), 16); let result2 = GenericRecord::::decode_from(&mut Cursor::new(&src), 0); assert!(result2.is_ok()); let decoded_record = result2.expect("is ok"); assert_eq!(decoded_record.len, 20); assert_eq!(decoded_record.value, 25); } */ #[derive(Default, Debug)] pub struct Root { pub topic: String, pub stream_id: u32, pub partition: Child, } #[derive(Default, Debug)] pub struct Child { pub value: R, } #[derive(Default, Decoder, Debug)] pub struct Root2 { pub topic: String, pub stream_id: u32, pub partition: Child2, } #[derive(Default, Decoder, Debug)] pub struct Child2 { pub value: R, }