Skip to content

Commit 03c99a0

Browse files
committed
MOD: Improve Python record enum field getters
1 parent 0ee424c commit 03c99a0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 0.43.0 - TBD
44

5+
### Enhancements
6+
- Made `Unset` a fully-supported variant of `SystemCode` and `ErrorCode`
7+
58
### Breaking changes
69
- Removed `mode` parameter in `Historical::MetadataGetCost()`
710

include/databento/enums.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ enum ErrorCode : std::uint8_t {
609609
InvalidSubscription = 5,
610610
// An error occurred in the gateway.
611611
InternalError = 6,
612+
// No error code was specified or this record was upgraded from a version 1 struct
613+
// where the code field didn't exist.
612614
Unset = 255,
613615
};
614616
} // namespace error_code
@@ -630,6 +632,8 @@ enum SystemCode : std::uint8_t {
630632
// Signals that all records for interval-based schemas have been published for the
631633
// given timestamp.
632634
EndOfInterval = 4,
635+
// No system code was specified or this record was upgraded from a version 1 struct
636+
// where the code field didn't exist.
633637
Unset = 255,
634638
};
635639
} // namespace system_code

src/enums.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ const char* ToString(ErrorCode error_code) {
776776
case ErrorCode::InternalError: {
777777
return "internal_error";
778778
}
779+
case ErrorCode::Unset: {
780+
return "unset";
781+
}
779782
default: {
780783
return "Unknown";
781784
}
@@ -798,6 +801,9 @@ const char* ToString(SystemCode system_code) {
798801
case SystemCode::EndOfInterval: {
799802
return "end_of_interval";
800803
}
804+
case SystemCode::Unset: {
805+
return "unset";
806+
}
801807
default: {
802808
return "Unknown";
803809
}
@@ -1219,6 +1225,9 @@ ErrorCode FromString(const std::string& str) {
12191225
if (str == "internal_error") {
12201226
return ErrorCode::InternalError;
12211227
}
1228+
if (str == "unset") {
1229+
return ErrorCode::Unset;
1230+
}
12221231
throw InvalidArgumentError{"FromString<ErrorCode>", "str",
12231232
"unknown value '" + str + '\''};
12241233
}
@@ -1239,6 +1248,9 @@ SystemCode FromString(const std::string& str) {
12391248
if (str == "end_of_interval") {
12401249
return SystemCode::EndOfInterval;
12411250
}
1251+
if (str == "unset") {
1252+
return SystemCode::Unset;
1253+
}
12421254
throw InvalidArgumentError{"FromString<SystemCode>", "str",
12431255
"unknown value '" + str + '\''};
12441256
}

0 commit comments

Comments
 (0)