Skip to content

Commit 4a55ddc

Browse files
committed
serialize entity as number
1 parent 0c39f46 commit 4a55ddc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

bindings_wasm/src/consent_state.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ impl From<ConsentState> for XmtpConsentState {
3535
}
3636

3737
#[wasm_bindgen]
38-
#[derive(Clone, Serialize, Deserialize)]
38+
#[derive(Copy, Clone, Serialize, Deserialize)]
39+
#[repr(u16)]
3940
pub enum ConsentEntityType {
40-
GroupId,
41-
InboxId,
42-
Address,
41+
GroupId = 0,
42+
InboxId = 1,
43+
Address = 2,
4344
}
4445

4546
impl From<ConsentEntityType> for XmtpConsentType {
@@ -52,11 +53,19 @@ impl From<ConsentEntityType> for XmtpConsentType {
5253
}
5354
}
5455

56+
fn entity_to_u16<S>(consent_entity_type: &ConsentEntityType, s: S) -> Result<S::Ok, S::Error>
57+
where
58+
S: serde::Serializer,
59+
{
60+
let num: u16 = (*consent_entity_type) as u16;
61+
s.serialize_u16(num)
62+
}
63+
5564
#[wasm_bindgen(getter_with_clone)]
5665
#[derive(Clone, Serialize, Deserialize)]
5766
pub struct Consent {
5867
#[wasm_bindgen(js_name = entityType)]
59-
#[serde(rename = "entityType")]
68+
#[serde(rename = "entityType", serialize_with = "entity_to_u16")]
6069
pub entity_type: ConsentEntityType,
6170
pub state: ConsentState,
6271
pub entity: String,

0 commit comments

Comments
 (0)