@@ -44,6 +44,17 @@ pub enum ClientMessage {
44
44
Close ( SubscriptionId ) ,
45
45
/// Auth
46
46
Auth ( Box < Event > ) ,
47
+ /// Negentropy Open
48
+ NegOpen {
49
+ /// Subscription ID
50
+ subscription_id : SubscriptionId ,
51
+ /// Filter
52
+ filter : Box < Filter > ,
53
+ /// ID size (MUST be between 8 and 32, inclusive)
54
+ id_size : u8 ,
55
+ /// Initial message
56
+ initial_message : String ,
57
+ } ,
47
58
}
48
59
49
60
impl Serialize for ClientMessage {
@@ -150,6 +161,20 @@ impl ClientMessage {
150
161
}
151
162
Self :: Close ( subscription_id) => json ! ( [ "CLOSE" , subscription_id] ) ,
152
163
Self :: Auth ( event) => json ! ( [ "AUTH" , event] ) ,
164
+ Self :: NegOpen {
165
+ subscription_id,
166
+ filter,
167
+ id_size,
168
+ initial_message,
169
+ } => {
170
+ json ! ( [
171
+ "NEG-OPEN" ,
172
+ subscription_id,
173
+ filter,
174
+ id_size,
175
+ initial_message
176
+ ] )
177
+ }
153
178
}
154
179
}
155
180
@@ -243,6 +268,26 @@ impl ClientMessage {
243
268
return Ok ( Self :: new_auth ( event) ) ;
244
269
}
245
270
271
+ // Negentropy Open
272
+ // ["NEG-OPEN", <subscription ID string>, <filter>, <idSize>, <initialMessage, lowercase hex-encoded>]
273
+ if v[ 0 ] == "NEG-OPEN" {
274
+ if v_len != 5 {
275
+ return Err ( MessageHandleError :: InvalidMessageFormat ) ;
276
+ }
277
+ let subscription_id = SubscriptionId :: new ( v[ 1 ] . to_string ( ) ) ;
278
+ let filter = Filter :: from_json ( v[ 2 ] . to_string ( ) ) ?;
279
+ let id_size = v[ 3 ]
280
+ . as_u64 ( )
281
+ . ok_or ( MessageHandleError :: InvalidMessageFormat ) ? as u8 ;
282
+ let initial_message = v[ 4 ] . to_string ( ) ;
283
+ return Ok ( Self :: NegOpen {
284
+ subscription_id,
285
+ filter : Box :: new ( filter) ,
286
+ id_size,
287
+ initial_message,
288
+ } ) ;
289
+ }
290
+
246
291
Err ( MessageHandleError :: InvalidMessageFormat )
247
292
}
248
293
0 commit comments