1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
// Allow fluvio_protocol_derive to use fluvio_protocol exports
// See https://github.com/rust-lang/rust/issues/56409
extern crate self as fluvio_protocol;
pub mod core;
#[cfg(feature = "derive")]
pub use inner_deriver::*;
#[cfg(feature = "derive")]
pub use fluvio_protocol_derive as derive;
#[cfg(feature = "api")]
pub mod api;
#[cfg(feature = "codec")]
pub mod codec;
#[cfg(feature = "record")]
pub mod record;
#[cfg(feature = "types")]
pub mod types {
pub use fluvio_types::*;
}
#[cfg(feature = "link")]
pub mod link;
#[cfg(feature = "fixture")]
pub mod fixture;
#[cfg(all(unix, feature = "store"))]
pub mod store;
pub use self::core::ByteBuf;
pub use self::core::Decoder;
pub use self::core::DecoderVarInt;
pub use self::core::Encoder;
pub use self::core::EncoderVarInt;
pub use self::core::Version;
pub use bytes;
#[cfg(feature = "derive")]
mod inner_deriver {
/// Custom derive for encoding structure or enum to bytes using Kafka protocol format.
/// This assumes all fields(or enum variants) implement kafka encode traits.
///
/// # Examples
///
/// ```
/// use fluvio_protocol::Encoder;
///
/// #[derive(Encoder)]
/// pub struct SimpleRecord {
/// val: u8
/// }
///
/// let mut data = vec![];
///
/// let record = SimpleRecord { val: 4 };
/// record.encode(&mut data,0);
///
/// assert_eq!(data[0],4);
/// ```
///
/// Encoder applies to either Struct of Enum.
///
/// Encoder respects version attributes. See Decoder derive.
pub use fluvio_protocol_derive::Encoder;
/// Custom derive for decoding structure or enum from bytes using fluvio protocol format.
/// This assumes all fields implement fluvio decode traits.
///
/// # Examples
///
/// ```
/// use std::io::Cursor;
/// use fluvio_protocol::Decoder;
///
/// #[derive(Default, Decoder)]
/// pub struct SimpleRecord {
/// val: u8
/// }
///
/// let data = [
/// 0x04
/// ];
///
/// let record = SimpleRecord::decode_from(&mut Cursor::new(&data),0).expect("decode");
/// assert_eq!(record.val, 4);
/// ```
///
///
/// Decoder applies to either Struct of Enum. For enum, it implements `TryFrom` trait.
/// Currently it only supports integer variants.
///
/// So this works
///
/// ```
/// # use fluvio_protocol::Decoder;
/// # impl Default for ThreeChoice { fn default() -> Self { unimplemented!() } }
/// #[derive(Decoder)]
/// #[fluvio(encode_discriminant)]
/// pub enum ThreeChoice {
/// First = 1,
/// Second = 2,
/// Third = 3
/// }
/// ```
///
/// Also, enum without integer literal works as well
///
/// ```
/// # use fluvio_protocol::Decoder;
/// # impl Default for ThreeChoice { fn default() -> Self { unimplemented!() } }
/// #[derive(Decoder)]
/// pub enum ThreeChoice {
/// #[fluvio(tag = 0)]
/// First,
/// #[fluvio(tag = 1)]
/// Second,
/// #[fluvio(tag = 2)]
/// Third
/// }
/// ```
///
/// In this case, 1 is decoded as First, 2 as Second, 3 as Third.
///
/// Currently, mixing enum variants are not supported.
///
///
/// Decoder support container and field level attributes.
/// Container level applies to struct.
/// For field attributes
/// * `#[varint]` force decode using varint format.
/// * `#[trace]` print out debug information during decoding
/// * `#fluvio(min_version = <version>)]` decodes only if version is equal or greater than min_version
/// * `#fluvio(max_version = <version>)]`decodes only if version is less or equal than max_version
///
pub use fluvio_protocol_derive::Decoder;
/// Custom derive for implementing Request trait.
/// This derives requires `fluvio`
///
/// # Examples
///
/// ```
/// use fluvio_protocol::{Encoder, Decoder};
/// use fluvio_protocol::api::Request;
/// use fluvio_protocol::derive::RequestApi as Request;
///
/// #[fluvio(default,api_min_version = 5, api_max_version = 6, api_key = 10, response = "SimpleResponse")]
/// #[derive(Debug, Default, Encoder, Decoder, Request)]
/// pub struct SimpleRequest {
/// val: u8
/// }
///
/// #[derive(Debug, Default, Encoder, Decoder)]
/// #[fluvio(default)]
/// pub struct SimpleResponse {
/// pub value: i8,
/// }
/// ```
///
/// RequestApi derives respects following attributes in `fluvio`
///
/// * `api_min_version`: min version that API supports. This is required
/// * `api_max_version`: max version that API supports. This is optional.
/// * `api_key`: API number. This is required
/// * `response`: Response struct. This is required
///
///
#[cfg(feature = "api")]
pub use fluvio_protocol_derive::RequestApi;
/// Custom derive for generating default structure
///
/// Example:
///
/// ```
/// use fluvio_protocol::FluvioDefault;
///
/// #[derive(FluvioDefault)]
/// #[fluvio(default)]
/// pub struct SimpleRecord {
/// #[fluvio(default = "12")]
/// val: u8
/// }
///
/// let record = SimpleRecord::default();
/// assert_eq!(record.val, 12);
/// ```
///
/// `default` assignment can be any Rust expression.
pub use fluvio_protocol_derive::FluvioDefault;
}