use std::sync::Arc;
use kafka_client_core::GroupPositionFence;
#[derive(Debug, Eq, PartialEq)]
pub struct GroupConsumerAssignmentPartition {
topic: Arc<str>,
partition: i32,
}
impl GroupConsumerAssignmentPartition {
pub(in crate::consumer) const fn new(topic: Arc<str>, partition: i32) -> Self {
Self { topic, partition }
}
pub fn topic(&self) -> &str {
&self.topic
}
pub const fn partition(&self) -> i32 {
self.partition
}
}
#[derive(Debug, Eq, PartialEq)]
pub struct GroupConsumerAssignment {
assignment_epoch: u64,
partitions: Box<[GroupConsumerAssignmentPartition]>,
}
impl GroupConsumerAssignment {
pub(in crate::consumer) fn new(
assignment_epoch: u64,
partitions: Vec<GroupConsumerAssignmentPartition>,
) -> Self {
Self {
assignment_epoch,
partitions: partitions.into_boxed_slice(),
}
}
pub const fn assignment_epoch(&self) -> u64 {
self.assignment_epoch
}
pub fn partitions(&self) -> &[GroupConsumerAssignmentPartition] {
&self.partitions
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum GroupConsumerMembershipEpoch {
Classic {
generation_id: i32,
},
Consumer {
member_epoch: i32,
},
}
impl GroupConsumerMembershipEpoch {
pub(crate) const fn generation_id_or_member_epoch(self) -> i32 {
match self {
Self::Classic { generation_id } => generation_id,
Self::Consumer { member_epoch } => member_epoch,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GroupConsumerMetadata {
group: Arc<str>,
group_instance_id: Option<Arc<str>>,
member: Arc<str>,
transaction_group_instance_id: Option<Arc<str>>,
membership_epoch: GroupConsumerMembershipEpoch,
assignment_epoch: u64,
position_fence: GroupPositionFence,
}
impl GroupConsumerMetadata {
pub(crate) const fn new_with_group_instance_id(
group: Arc<str>,
group_instance_id: Option<Arc<str>>,
member: Arc<str>,
transaction_group_instance_id: Option<Arc<str>>,
membership_epoch: GroupConsumerMembershipEpoch,
assignment_epoch: u64,
position_fence: GroupPositionFence,
) -> Self {
Self {
group,
group_instance_id,
member,
transaction_group_instance_id,
membership_epoch,
assignment_epoch,
position_fence,
}
}
pub fn group(&self) -> &str {
&self.group
}
pub fn group_instance_id(&self) -> Option<&str> {
self.group_instance_id.as_deref()
}
pub fn member(&self) -> &str {
&self.member
}
pub const fn membership_epoch(&self) -> GroupConsumerMembershipEpoch {
self.membership_epoch
}
pub(crate) const fn generation_id_or_member_epoch(&self) -> i32 {
self.membership_epoch.generation_id_or_member_epoch()
}
pub const fn assignment_epoch(&self) -> u64 {
self.assignment_epoch
}
pub(crate) fn group_arc(&self) -> Arc<str> {
Arc::clone(&self.group)
}
pub(crate) fn member_arc(&self) -> Arc<str> {
Arc::clone(&self.member)
}
pub(crate) fn group_instance_id_arc(&self) -> Option<Arc<str>> {
self.transaction_group_instance_id.as_ref().map(Arc::clone)
}
pub(crate) const fn position_fence(&self) -> GroupPositionFence {
self.position_fence
}
}
#[derive(Debug, Eq, PartialEq)]
pub struct GroupConsumerState {
assignment: GroupConsumerAssignment,
metadata: GroupConsumerMetadata,
}
impl GroupConsumerState {
pub(in crate::consumer) const fn new(
assignment: GroupConsumerAssignment,
metadata: GroupConsumerMetadata,
) -> Self {
Self {
assignment,
metadata,
}
}
pub const fn assignment(&self) -> &GroupConsumerAssignment {
&self.assignment
}
pub const fn metadata(&self) -> &GroupConsumerMetadata {
&self.metadata
}
pub fn into_parts(self) -> (GroupConsumerAssignment, GroupConsumerMetadata) {
(self.assignment, self.metadata)
}
}
#[derive(Debug, Eq, PartialEq)]
pub enum GroupConsumerEvent {
PartitionsAssigned(GroupConsumerAssignment),
PartitionsRevoked(GroupConsumerAssignment),
PartitionsLost(GroupConsumerAssignment),
}