12 if (value <= max_1byte)
15 return {
static_cast<uint8_t
>(value)};
18 if (value <= max_2byte)
22 static_cast<uint8_t
>(prefix_2byte | ((value >> 8) & value_mask)),
23 static_cast<uint8_t
>(value & 0xFF)
27 if (value <= max_4byte)
31 static_cast<uint8_t
>(prefix_4byte | ((value >> 24) & value_mask)),
32 static_cast<uint8_t
>((value >> 16) & 0xFF),
33 static_cast<uint8_t
>((value >> 8) & 0xFF),
34 static_cast<uint8_t
>(value & 0xFF)
46 static_cast<uint8_t
>(prefix_8byte | ((value >> 56) & value_mask)),
47 static_cast<uint8_t
>((value >> 48) & 0xFF),
48 static_cast<uint8_t
>((value >> 40) & 0xFF),
49 static_cast<uint8_t
>((value >> 32) & 0xFF),
50 static_cast<uint8_t
>((value >> 24) & 0xFF),
51 static_cast<uint8_t
>((value >> 16) & 0xFF),
52 static_cast<uint8_t
>((value >> 8) & 0xFF),
53 static_cast<uint8_t
>(value & 0xFF)
61 if (min_length != 1 && min_length != 2 && min_length != 4 && min_length != 8)
65 "Invalid minimum length",
67 "min_length must be 1, 2, 4, or 8"
72 uint64_t max_for_length = 0;
75 case 1: max_for_length = max_1byte;
break;
76 case 2: max_for_length = max_2byte;
break;
77 case 4: max_for_length = max_4byte;
break;
78 case 8: max_for_length = max_8byte;
break;
83 size_t actual_length = encoded_length(value);
86 size_t use_length = (min_length > actual_length) ? min_length : actual_length;
96 "Value exceeds maximum",
98 "Value exceeds 2^62 - 1"
103 std::vector<uint8_t> result;
107 result = {
static_cast<uint8_t
>(value)};
112 static_cast<uint8_t
>(prefix_2byte | ((value >> 8) & value_mask)),
113 static_cast<uint8_t
>(value & 0xFF)
119 static_cast<uint8_t
>(prefix_4byte | ((value >> 24) & value_mask)),
120 static_cast<uint8_t
>((value >> 16) & 0xFF),
121 static_cast<uint8_t
>((value >> 8) & 0xFF),
122 static_cast<uint8_t
>(value & 0xFF)
128 static_cast<uint8_t
>(prefix_8byte | ((value >> 56) & value_mask)),
129 static_cast<uint8_t
>((value >> 48) & 0xFF),
130 static_cast<uint8_t
>((value >> 40) & 0xFF),
131 static_cast<uint8_t
>((value >> 32) & 0xFF),
132 static_cast<uint8_t
>((value >> 24) & 0xFF),
133 static_cast<uint8_t
>((value >> 16) & 0xFF),
134 static_cast<uint8_t
>((value >> 8) & 0xFF),
135 static_cast<uint8_t
>(value & 0xFF)
143 return ok(std::move(result));