| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "LibLsp/JsonRpc/serializer.h" |
| 4 |
|
| 5 |
struct lsRequestId |
| 6 |
{ |
| 7 |
// The client can send the request id as an int or a string. We should output |
| 8 |
// the same format we received. |
| 9 |
enum Type |
| 10 |
{ |
| 11 |
kNone, |
| 12 |
kInt, |
| 13 |
kString |
| 14 |
}; |
| 15 |
Type type = kNone; |
| 16 |
|
| 17 |
int value = -1; |
| 18 |
std::string k_string; |
| 19 |
bool has_value() const |
| 20 |
{ |
| 21 |
return type != kNone; |
| 22 |
} |
| 23 |
void swap(lsRequestId& arg) noexcept |
| 24 |
{ |
| 25 |
std::swap(arg, *this); |
| 26 |
} |
| 27 |
void set(int v) |
| 28 |
{ |
| 29 |
value = v; |
| 30 |
type = kInt; |
| 31 |
} |
| 32 |
void set(std::string const& v) |
| 33 |
{ |
| 34 |
k_string = v; |
| 35 |
type = kString; |
| 36 |
} |
| 37 |
bool operator==(lsRequestId const& rhs) const |
| 38 |
{ |
| 39 |
if (type != rhs.type) |
| 40 |
{ |
| 41 |
return false; |
| 42 |
} |
| 43 |
if (type == kInt) |
| 44 |
{ |
| 45 |
return value == rhs.value; |
| 46 |
} |
| 47 |
return k_string == rhs.k_string; |
| 48 |
} |
| 49 |
bool operator!=(lsRequestId const& rhs) const |
| 50 |
{ |
| 51 |
return !operator==(rhs); |
| 52 |
} |
| 53 |
bool operator<(lsRequestId const& rhs) const |
| 54 |
{ |
| 55 |
if (type != rhs.type) |
| 56 |
{ |
| 57 |
return false; |
| 58 |
} |
| 59 |
if (type == kInt) |
| 60 |
{ |
| 61 |
return value < rhs.value; |
| 62 |
} |
| 63 |
return k_string < rhs.k_string; |
| 64 |
} |
| 65 |
}; |
| 66 |
void Reflect(Reader& visitor, lsRequestId& value); |
| 67 |
void Reflect(Writer& visitor, lsRequestId& value); |
| 68 |
|
| 69 |
// Debug method to convert an id to a string. |
| 70 |
std::string ToString(lsRequestId const& id); |