11//! Tags RPC protocol
2+ use bytes:: Bytes ;
23use nested_enum_utils:: enum_conversions;
34use quic_rpc_derive:: rpc_requests;
45use serde:: { Deserialize , Serialize } ;
56
67use super :: { RpcResult , RpcService } ;
7- use crate :: { net_protocol:: BatchId , rpc:: client:: tags:: TagInfo , HashAndFormat , Tag } ;
8+ use crate :: {
9+ net_protocol:: BatchId ,
10+ rpc:: client:: tags:: TagInfo ,
11+ util:: { increment_vec, next_prefix} ,
12+ HashAndFormat , Tag ,
13+ } ;
814
915#[ allow( missing_docs) ]
1016#[ derive( strum:: Display , Debug , Serialize , Deserialize ) ]
@@ -73,14 +79,53 @@ pub struct ListRequest {
7379 pub raw : bool ,
7480 /// List hash seq tags
7581 pub hash_seq : bool ,
82+ /// From tag
83+ pub from : Option < Tag > ,
84+ /// To tag (exclusive)
85+ pub to : Option < Tag > ,
7686}
7787
7888impl ListRequest {
89+ /// List tags with a prefix
90+ pub fn prefix ( prefix : & [ u8 ] ) -> Self {
91+ let from = prefix. to_vec ( ) ;
92+ let mut to = from. clone ( ) ;
93+ let from = Bytes :: from ( from) . into ( ) ;
94+ let to = if next_prefix ( & mut to) {
95+ Some ( Bytes :: from ( to) . into ( ) )
96+ } else {
97+ None
98+ } ;
99+ Self {
100+ raw : true ,
101+ hash_seq : true ,
102+ from : Some ( from) ,
103+ to,
104+ }
105+ }
106+
107+ /// List a single tag
108+ pub fn single ( name : & [ u8 ] ) -> Self {
109+ let from = name. to_vec ( ) ;
110+ let mut next = from. clone ( ) ;
111+ increment_vec ( & mut next) ;
112+ let from = Bytes :: from ( from) . into ( ) ;
113+ let to = Bytes :: from ( next) . into ( ) ;
114+ Self {
115+ raw : true ,
116+ hash_seq : true ,
117+ from : Some ( from) ,
118+ to : Some ( to) ,
119+ }
120+ }
121+
79122 /// List all tags
80123 pub fn all ( ) -> Self {
81124 Self {
82125 raw : true ,
83126 hash_seq : true ,
127+ from : None ,
128+ to : None ,
84129 }
85130 }
86131
@@ -89,6 +134,8 @@ impl ListRequest {
89134 Self {
90135 raw : true ,
91136 hash_seq : false ,
137+ from : None ,
138+ to : None ,
92139 }
93140 }
94141
@@ -97,6 +144,8 @@ impl ListRequest {
97144 Self {
98145 raw : false ,
99146 hash_seq : true ,
147+ from : None ,
148+ to : None ,
100149 }
101150 }
102151}
0 commit comments