krishvishal commented on code in PR #2887:
URL: https://github.com/apache/iggy/pull/2887#discussion_r2909078476


##########
core/common/src/types/consensus/header.rs:
##########
@@ -449,19 +517,21 @@ impl ConsensusHeader for PrepareOkHeader {
     const COMMAND: Command2 = Command2::PrepareOk;
 
     fn operation(&self) -> Operation {
-        self.operation
+        Operation::try_from(self.operation).expect("validate() must be called 
first")
     }
     fn command(&self) -> Command2 {

Review Comment:
   Done. 



##########
core/common/src/types/consensus/header.rs:
##########
@@ -124,6 +153,40 @@ pub enum Operation {
     Reserved = 200,
 }
 
+impl TryFrom<u8> for Operation {
+    type Error = u8;
+
+    fn try_from(value: u8) -> Result<Self, Self::Error> {
+        match value {
+            0 => Ok(Operation::Default),
+            128 => Ok(Operation::CreateStream),
+            129 => Ok(Operation::UpdateStream),
+            130 => Ok(Operation::DeleteStream),
+            131 => Ok(Operation::PurgeStream),
+            132 => Ok(Operation::CreateTopic),
+            133 => Ok(Operation::UpdateTopic),
+            134 => Ok(Operation::DeleteTopic),
+            135 => Ok(Operation::PurgeTopic),
+            136 => Ok(Operation::CreatePartitions),
+            137 => Ok(Operation::DeletePartitions),
+            138 => Ok(Operation::DeleteSegments),
+            139 => Ok(Operation::CreateConsumerGroup),
+            140 => Ok(Operation::DeleteConsumerGroup),
+            141 => Ok(Operation::CreateUser),
+            142 => Ok(Operation::UpdateUser),
+            143 => Ok(Operation::DeleteUser),
+            144 => Ok(Operation::ChangePassword),
+            145 => Ok(Operation::UpdatePermissions),
+            146 => Ok(Operation::CreatePersonalAccessToken),
+            147 => Ok(Operation::DeletePersonalAccessToken),
+            160 => Ok(Operation::SendMessages),
+            161 => Ok(Operation::StoreConsumerOffset),
+            200 => Ok(Operation::Reserved),

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to