pddb: add explicit discriminants to enums

In order to ensure the API is stable, add explicit opcodes to enums
within pddb.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-06-25 11:00:41 +08:00
parent 4319ac4f45
commit 19532c5634

View file

@ -85,59 +85,59 @@ pub(crate) const BCRYPT_COST: u32 = 7; // 10 is the minimum recommended by OWA
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum Opcode { pub(crate) enum Opcode {
IsMounted, IsMounted = 0,
TryMount, TryMount = 1,
ListBasis, ListBasis = 2,
LatestBasis, LatestBasis = 3,
/// Note that creating a basis does not automatically open it! /// Note that creating a basis does not automatically open it!
CreateBasis, CreateBasis = 4,
OpenBasis, OpenBasis = 5,
CloseBasis, CloseBasis = 6,
/// warning, the Delete routines have not been well tested /// warning, the Delete routines have not been well tested
DeleteBasis, DeleteBasis = 7,
DeleteKey, DeleteKey = 8,
DeleteDict, DeleteDict = 9,
KeyAttributes, KeyAttributes = 10,
// routines to list available resources // routines to list available resources
KeyCountInDict, KeyCountInDict = 11,
GetKeyNameAtIndex, GetKeyNameAtIndex = 12,
DictCountInBasis, DictCountInBasis = 13,
GetDictNameAtIndex, GetDictNameAtIndex = 14,
/// primary method for accessing the database /// primary method for accessing the database
KeyRequest, KeyRequest = 15,
// pddbkey methods // pddbkey methods
ReadKey, ReadKey = 16,
WriteKey, WriteKey = 17,
WriteKeyFlush, WriteKeyFlush = 18,
// GC methods // GC methods
PeriodicScrub, PeriodicScrub = 19,
/// drops any connection state associated with a given key /// drops any connection state associated with a given key
KeyDrop, KeyDrop = 20,
/// Menu opcodes /// Menu opcodes
MenuListBasis, MenuListBasis = 21,
/// Security state checks /// Security state checks
IsEfuseSecured, IsEfuseSecured = 22,
/// Suspend/resume callback /// Suspend/resume callback
SuspendResume, SuspendResume = 23,
/// quit the server /// quit the server
Quit, Quit = 24,
/// Write debug dump (only available in hosted mode) /// Write debug dump (only available in hosted mode)
#[cfg(not(any(target_os = "none", target_os = "xous")))] #[cfg(not(any(target_os = "none", target_os = "xous")))]
DangerousDebug, DangerousDebug = 25,
} }
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum PollOp { pub(crate) enum PollOp {
Poll, Poll = 0,
Quit, Quit = 1,
} }
pub type ApiToken = [u32; 3]; pub type ApiToken = [u32; 3];
@ -150,17 +150,17 @@ pub struct PddbBasisList {
} }
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub enum PddbRequestCode { pub enum PddbRequestCode {
Create, Create = 0,
Open, Open = 1,
Close, Close = 2,
Delete, Delete = 3,
NoErr, NoErr = 4,
NotMounted, NotMounted = 5,
NoFreeSpace, NoFreeSpace = 6,
NotFound, NotFound = 7,
InternalError, InternalError = 8,
AccessDenied, AccessDenied = 9,
Uninit, Uninit = 10,
} }
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
@ -342,8 +342,8 @@ pub struct PddbDangerousDebug {
#[cfg(not(any(target_os = "none", target_os = "xous")))] #[cfg(not(any(target_os = "none", target_os = "xous")))]
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub enum DebugRequest { pub enum DebugRequest {
Dump, Dump = 0,
Remount, Remount = 1,
} }
#[cfg(test)] #[cfg(test)]