diff --git a/client/src/activity.vala b/client/src/activity.vala index 11a3429..ed42137 100644 --- a/client/src/activity.vala +++ b/client/src/activity.vala @@ -7,7 +7,9 @@ namespace StudySystemClient { public enum ActivityType { READING = 0, - EXERCISES = 1; + EXERCISES = 1, + + COUNT; public string to_string() { switch (this) { diff --git a/client/src/response.vala b/client/src/response.vala index ad0c3db..4baa4d9 100644 --- a/client/src/response.vala +++ b/client/src/response.vala @@ -67,7 +67,9 @@ namespace StudySystemClient.Response { public enum Value { INVALID_REQUEST = 0, INVALID_ARGUMENTS = 1, - SERVER_ERROR = 2; + SERVER_ERROR = 2, + + COUNT; public string to_string() { switch (this) { @@ -91,9 +93,9 @@ namespace StudySystemClient.Response { throw new DecodeError.INVALID_BODY( "Error was not an ENUMERATED"); } - if (enumerated.value < 0 || enumerated.value > 2) { + if (enumerated.value < 0 || enumerated.value >= Value.COUNT) { throw new DecodeError.INVALID_BODY( - "Error type was not in range 0..2"); + "Error type was not in range 0..$(Value.COUNT)"); } value = (Value)enumerated.value; } @@ -162,7 +164,7 @@ namespace StudySystemClient.Response { string name, Der.Datum datum) throws DecodeError { if (datum is Der.Enumerated) { var value = datum.value; - if (0 <= value <= 1) + if (0 <= value < ActivityType.COUNT) return (ActivityType)value; throw new DecodeError.INVALID_BODY( "Invalid value for ActivityType: %lld", value);