Skip to content

How to Determine the Type of a Message #347

Answered by jcready
ballcoach12 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the message type guards:

function publish(connection: Connection,  message: ForceValueMessage  | UnforceValueMessage){
 
if(ForceValueMessage.is(message)){
// take one action if the message is a force value
}
else {
// take another action if the message is an unforce value
}
}

Or use a proto oneof:

message UnforceValueMessage {
  required string topic   = 1; 
}
message ForceValueMessage {
  required string topic               = 1;
  required bytes data                 = 2;
  required DataMapItemType itemType   = 3;
}
message ValueMessage {
  oneof force {
    UnforceValueMessage no = 1;
    ForceValueMessage  yes = 2;
  }
}
function publish(connection: Connection,  message: Va…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ballcoach12
Comment options

Answer selected by ballcoach12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants