github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/protocol/kbgitkbfs1/disk_block_cache.go (about) 1 // Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler) 2 // Input file: avdl/kbgitkbfs1/disk_block_cache.avdl 3 4 package kbgitkbfs1 5 6 import ( 7 "fmt" 8 "github.com/keybase/go-framed-msgpack-rpc/rpc" 9 context "golang.org/x/net/context" 10 "time" 11 ) 12 13 type PrefetchStatus int 14 15 const ( 16 PrefetchStatus_NO_PREFETCH PrefetchStatus = 0 17 PrefetchStatus_TRIGGERED_PREFETCH PrefetchStatus = 1 18 PrefetchStatus_FINISHED_PREFETCH PrefetchStatus = 2 19 ) 20 21 func (o PrefetchStatus) DeepCopy() PrefetchStatus { return o } 22 23 var PrefetchStatusMap = map[string]PrefetchStatus{ 24 "NO_PREFETCH": 0, 25 "TRIGGERED_PREFETCH": 1, 26 "FINISHED_PREFETCH": 2, 27 } 28 29 var PrefetchStatusRevMap = map[PrefetchStatus]string{ 30 0: "NO_PREFETCH", 31 1: "TRIGGERED_PREFETCH", 32 2: "FINISHED_PREFETCH", 33 } 34 35 func (e PrefetchStatus) String() string { 36 if v, ok := PrefetchStatusRevMap[e]; ok { 37 return v 38 } 39 return fmt.Sprintf("%v", int(e)) 40 } 41 42 // GetCachedBlockRes is the response from GetBlock. 43 type GetBlockRes struct { 44 Buf []byte `codec:"buf" json:"buf"` 45 ServerHalf []byte `codec:"serverHalf" json:"serverHalf"` 46 PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"` 47 } 48 49 func (o GetBlockRes) DeepCopy() GetBlockRes { 50 return GetBlockRes{ 51 Buf: (func(x []byte) []byte { 52 if x == nil { 53 return nil 54 } 55 return append([]byte{}, x...) 56 })(o.Buf), 57 ServerHalf: (func(x []byte) []byte { 58 if x == nil { 59 return nil 60 } 61 return append([]byte{}, x...) 62 })(o.ServerHalf), 63 PrefetchStatus: o.PrefetchStatus.DeepCopy(), 64 } 65 } 66 67 // DeleteBlocksRes is the response from DeleteBlocks. 68 type DeleteBlocksRes struct { 69 NumRemoved int `codec:"numRemoved" json:"numRemoved"` 70 SizeRemoved int64 `codec:"sizeRemoved" json:"sizeRemoved"` 71 } 72 73 func (o DeleteBlocksRes) DeepCopy() DeleteBlocksRes { 74 return DeleteBlocksRes{ 75 NumRemoved: o.NumRemoved, 76 SizeRemoved: o.SizeRemoved, 77 } 78 } 79 80 type GetBlockArg struct { 81 TlfID []byte `codec:"tlfID" json:"tlfID"` 82 BlockID []byte `codec:"blockID" json:"blockID"` 83 } 84 85 type GetPrefetchStatusArg struct { 86 TlfID []byte `codec:"tlfID" json:"tlfID"` 87 BlockID []byte `codec:"blockID" json:"blockID"` 88 } 89 90 type PutBlockArg struct { 91 TlfID []byte `codec:"tlfID" json:"tlfID"` 92 BlockID []byte `codec:"blockID" json:"blockID"` 93 Buf []byte `codec:"buf" json:"buf"` 94 ServerHalf []byte `codec:"serverHalf" json:"serverHalf"` 95 } 96 97 type DeleteBlocksArg struct { 98 BlockIDs [][]byte `codec:"blockIDs" json:"blockIDs"` 99 } 100 101 type UpdateBlockMetadataArg struct { 102 TlfID []byte `codec:"tlfID" json:"tlfID"` 103 BlockID []byte `codec:"blockID" json:"blockID"` 104 PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"` 105 } 106 107 // DiskBlockCacheInterface specifies how to access a disk cache remotely. 108 type DiskBlockCacheInterface interface { 109 // GetBlock gets a block from the disk cache. 110 GetBlock(context.Context, GetBlockArg) (GetBlockRes, error) 111 // GetPrefetchStatus gets the prefetch status from the disk cache. 112 GetPrefetchStatus(context.Context, GetPrefetchStatusArg) (PrefetchStatus, error) 113 // PutBlock puts a block into the disk cache. 114 PutBlock(context.Context, PutBlockArg) error 115 // DeleteBlocks deletes a set of blocks from the disk cache. 116 DeleteBlocks(context.Context, [][]byte) (DeleteBlocksRes, error) 117 // UpdateBlockMetadata updates the metadata for a block in the disk cache. 118 UpdateBlockMetadata(context.Context, UpdateBlockMetadataArg) error 119 } 120 121 func DiskBlockCacheProtocol(i DiskBlockCacheInterface) rpc.Protocol { 122 return rpc.Protocol{ 123 Name: "kbgitkbfs.1.DiskBlockCache", 124 Methods: map[string]rpc.ServeHandlerDescription{ 125 "GetBlock": { 126 MakeArg: func() interface{} { 127 var ret [1]GetBlockArg 128 return &ret 129 }, 130 Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) { 131 typedArgs, ok := args.(*[1]GetBlockArg) 132 if !ok { 133 err = rpc.NewTypeError((*[1]GetBlockArg)(nil), args) 134 return 135 } 136 ret, err = i.GetBlock(ctx, typedArgs[0]) 137 return 138 }, 139 }, 140 "GetPrefetchStatus": { 141 MakeArg: func() interface{} { 142 var ret [1]GetPrefetchStatusArg 143 return &ret 144 }, 145 Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) { 146 typedArgs, ok := args.(*[1]GetPrefetchStatusArg) 147 if !ok { 148 err = rpc.NewTypeError((*[1]GetPrefetchStatusArg)(nil), args) 149 return 150 } 151 ret, err = i.GetPrefetchStatus(ctx, typedArgs[0]) 152 return 153 }, 154 }, 155 "PutBlock": { 156 MakeArg: func() interface{} { 157 var ret [1]PutBlockArg 158 return &ret 159 }, 160 Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) { 161 typedArgs, ok := args.(*[1]PutBlockArg) 162 if !ok { 163 err = rpc.NewTypeError((*[1]PutBlockArg)(nil), args) 164 return 165 } 166 err = i.PutBlock(ctx, typedArgs[0]) 167 return 168 }, 169 }, 170 "DeleteBlocks": { 171 MakeArg: func() interface{} { 172 var ret [1]DeleteBlocksArg 173 return &ret 174 }, 175 Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) { 176 typedArgs, ok := args.(*[1]DeleteBlocksArg) 177 if !ok { 178 err = rpc.NewTypeError((*[1]DeleteBlocksArg)(nil), args) 179 return 180 } 181 ret, err = i.DeleteBlocks(ctx, typedArgs[0].BlockIDs) 182 return 183 }, 184 }, 185 "UpdateBlockMetadata": { 186 MakeArg: func() interface{} { 187 var ret [1]UpdateBlockMetadataArg 188 return &ret 189 }, 190 Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) { 191 typedArgs, ok := args.(*[1]UpdateBlockMetadataArg) 192 if !ok { 193 err = rpc.NewTypeError((*[1]UpdateBlockMetadataArg)(nil), args) 194 return 195 } 196 err = i.UpdateBlockMetadata(ctx, typedArgs[0]) 197 return 198 }, 199 }, 200 }, 201 } 202 } 203 204 type DiskBlockCacheClient struct { 205 Cli rpc.GenericClient 206 } 207 208 // GetBlock gets a block from the disk cache. 209 func (c DiskBlockCacheClient) GetBlock(ctx context.Context, __arg GetBlockArg) (res GetBlockRes, err error) { 210 err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.GetBlock", []interface{}{__arg}, &res, 0*time.Millisecond) 211 return 212 } 213 214 // GetPrefetchStatus gets the prefetch status from the disk cache. 215 func (c DiskBlockCacheClient) GetPrefetchStatus(ctx context.Context, __arg GetPrefetchStatusArg) (res PrefetchStatus, err error) { 216 err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.GetPrefetchStatus", []interface{}{__arg}, &res, 0*time.Millisecond) 217 return 218 } 219 220 // PutBlock puts a block into the disk cache. 221 func (c DiskBlockCacheClient) PutBlock(ctx context.Context, __arg PutBlockArg) (err error) { 222 err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.PutBlock", []interface{}{__arg}, nil, 0*time.Millisecond) 223 return 224 } 225 226 // DeleteBlocks deletes a set of blocks from the disk cache. 227 func (c DiskBlockCacheClient) DeleteBlocks(ctx context.Context, blockIDs [][]byte) (res DeleteBlocksRes, err error) { 228 __arg := DeleteBlocksArg{BlockIDs: blockIDs} 229 err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.DeleteBlocks", []interface{}{__arg}, &res, 0*time.Millisecond) 230 return 231 } 232 233 // UpdateBlockMetadata updates the metadata for a block in the disk cache. 234 func (c DiskBlockCacheClient) UpdateBlockMetadata(ctx context.Context, __arg UpdateBlockMetadataArg) (err error) { 235 err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.UpdateBlockMetadata", []interface{}{__arg}, nil, 0*time.Millisecond) 236 return 237 }