aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml4
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.toml4
-rw-r--r--README.md2
-rw-r--r--src/event.rs4
-rw-r--r--src/gamedata.rs4
-rw-r--r--src/lib.rs6
-rw-r--r--src/raw/types.rs10
8 files changed, 33 insertions, 2 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e7c755f..4394a3e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ image: "rust"
tests:
script:
- - cargo test
+ - cargo test --all-features
format:
before_script:
@@ -14,4 +14,4 @@ clippy:
before_script:
- rustup component add clippy
script:
- - if cargo clippy 2>&1 | tee /dev/stderr | egrep "^(warning|error):" >/dev/null ; then exit 1 ; else exit 0 ; fi
+ - if cargo clippy --all-features 2>&1 | tee /dev/stderr | egrep "^(warning|error):" >/dev/null ; then exit 1 ; else exit 0 ; fi
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 645f723..60937a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
Sunqua Peak CM fight.
- `Log::gadgets` to retrieve all gadget agents.
- `Log::build_id` to retrieve the game's build id.
+- The `serde` optional feature to enable (de)serialization of API types.
### Changed
- `gamedata::Boss` has been split in `gamedata::Boss` and `gamedata::Encounter`
diff --git a/Cargo.toml b/Cargo.toml
index 66349f9..040137b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,6 +14,9 @@ include = [
"/LICENSE",
]
+[features]
+default = []
+
[dependencies]
num-traits = "0.2"
num-derive = "0.3"
@@ -21,3 +24,4 @@ thiserror = "1.0"
byteorder = "1"
getset = "0.1"
zip = "0.5"
+serde = { version = "1.0", optional = true, features = ["derive"] }
diff --git a/README.md b/README.md
index 2f7e4ab..2bcc2a6 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,8 @@ Features:
* A high-level interface, intended for consumption within Rust applications.
* Support for reading zipped evtc files (`.evtc.zip` or `.zevtc`).
* Backwards compatible for older revisions of the evtc format.
+* Optional: [serde](https://github.com/serde-rs/serde) integration for
+ (de)serialization support (enable the `serde` feature).
`evtclib` is currently in beta-stage. Not all evtc events are supported, and
the API is not yet set in stone.
diff --git a/src/event.rs b/src/event.rs
index f9ee8e5..f90ed3a 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -26,6 +26,7 @@ pub enum FromRawEventError {
/// A rusty enum for all possible combat events.
///
/// This makes dealing with [`CbtEvent`][raw::CbtEvent] a bit saner (and safer).
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub enum EventKind {
// State change events
@@ -213,6 +214,7 @@ pub enum EventKind {
///
/// Note that if you plan on re-using the raw event afterwards, you should use the implementation
/// that works on a reference instead: `Event::try_from(&raw_event)`.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, CopyGetters, Getters)]
pub struct Event {
/// The time when the event happened.
@@ -524,6 +526,7 @@ fn get_error_bytes(raw_event: &raw::CbtEvent) -> [u8; 32] {
}
/// The different weapon-sets in game.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum WeaponSet {
/// First water weapon set.
@@ -558,6 +561,7 @@ impl WeaponSet {
/// The different types to activate a skill.
///
/// The parameter is the animation time in milliseconds.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Activation {
/// The skill was activated with quickness.
diff --git a/src/gamedata.rs b/src/gamedata.rs
index 8d0bb7f..64b6731 100644
--- a/src/gamedata.rs
+++ b/src/gamedata.rs
@@ -15,6 +15,7 @@ use thiserror::Error;
///
/// This enum is non-exhaustive to ensure that future encounters can be added without
/// inducing a breaking change.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, FromPrimitive)]
#[non_exhaustive]
#[repr(u16)]
@@ -193,6 +194,7 @@ impl Display for Encounter {
///
/// This enum is non-exhaustive to ensure that future bosses can be added without
/// inducing a breaking change.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, FromPrimitive)]
#[non_exhaustive]
#[repr(u16)]
@@ -516,6 +518,7 @@ pub struct ParseProfessionError(String);
///
/// This only contains the 9 base professions. For elite specializations, see
/// [`EliteSpec`][EliteSpec].
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, FromPrimitive)]
pub enum Profession {
Guardian = 1,
@@ -576,6 +579,7 @@ pub struct ParseEliteSpecError(String);
/// Note that the numeric value of the enum variants correspond to the specialization ID in the API
/// as well. See [the official wiki](https://wiki.guildwars2.com/wiki/API:2/specializations) for
/// more information regarding the API usage.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, FromPrimitive)]
pub enum EliteSpec {
// Heart of Thorns elites:
diff --git a/src/lib.rs b/src/lib.rs
index 60b404c..5b35893 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,6 +145,7 @@ pub enum EvtcError {
/// Note that a `Player` is only the player character itself. Any additional entities that are
/// spawned by the player (clones, illusions, banners, ...) are either a [`Character`][Character]
/// or a [`Gadget`][Gadget].
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, CopyGetters)]
pub struct Player {
/// The player's profession.
@@ -186,6 +187,7 @@ impl Player {
/// Examples of this include the [banners](https://wiki.guildwars2.com/wiki/Banner) spawned by
/// Warriors, but also skill effects like the roots created by
/// [Entangle](https://wiki.guildwars2.com/wiki/Entangle) or the other objects in the arena.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, CopyGetters)]
pub struct Gadget {
/// The id of the gadget.
@@ -208,6 +210,7 @@ impl Gadget {
///
/// Characters are NPCs such as the bosses themselves, additional mobs that they spawn, but also
/// friendly characters like Mesmer's clones and illusions, Necromancer minions, and so on.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, CopyGetters)]
pub struct Character {
/// The id of the character.
@@ -242,6 +245,7 @@ impl Character {
/// // Convert it
/// let agent: AgentKind = raw_agent.try_into().unwrap();
/// ```
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum AgentKind {
/// The agent is a player.
@@ -440,6 +444,7 @@ impl TryFrom<&raw::Agent> for AgentKind {
/// `Kind`. An escape hatch is the method [`.erase()`][Agent::erase], which erases the kind
/// information and produces the default `Agent<()>`. Functions/methods that only take `Agent<()>`
/// can therefore be used by any other agent as well.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Getters, CopyGetters)]
// For the reasoning of #[repr(C)] see Agent::transmute.
#[repr(C)]
@@ -700,6 +705,7 @@ impl Agent<Character> {
}
/// A fully processed log file.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
pub struct Log {
agents: Vec<Agent>,
diff --git a/src/raw/types.rs b/src/raw/types.rs
index fe4a907..0f840bd 100644
--- a/src/raw/types.rs
+++ b/src/raw/types.rs
@@ -7,6 +7,7 @@ use std::{self, fmt};
use std::hash::{Hash, Hasher};
/// The "friend or foe" enum.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum IFF {
/// Green vs green, red vs red.
@@ -26,6 +27,7 @@ impl Default for IFF {
}
/// Combat result (physical)
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum CbtResult {
/// Good physical hit
@@ -59,6 +61,7 @@ impl Default for CbtResult {
}
/// Combat activation
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum CbtActivation {
/// Field is not used in this kind of event.
@@ -85,6 +88,7 @@ impl Default for CbtActivation {
///
/// The referenced fields are of the [`CbtEvent`](struct.CbtEvent.html)
/// struct.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum CbtStateChange {
/// Field is not used in this kind of event.
@@ -212,6 +216,7 @@ impl Default for CbtStateChange {
}
/// Combat buff remove type
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum CbtBuffRemove {
/// Field is not used in this kind of event.
@@ -235,6 +240,7 @@ impl Default for CbtBuffRemove {
}
/// Custom skill ids
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum CbtCustomSkill {
/// Not custom but important and unnamed.
@@ -246,6 +252,7 @@ pub enum CbtCustomSkill {
}
/// Language
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum Language {
/// English.
@@ -270,6 +277,7 @@ impl Default for Language {
/// arcdps.
///
/// The suffix `Inc` indicates an increase, whereas the suffix `Rec` stands for received.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum Attribute {
None,
@@ -294,6 +302,7 @@ pub enum Attribute {
}
/// Categories for [`BuffInfo`][CbtStateChange::BuffInfo] events.
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, FromPrimitive)]
pub enum BuffCategory {
Boon = 0,
@@ -314,6 +323,7 @@ pub enum BuffCategory {
/// to check the header.revision tag.
///
/// For conflicting data types, the bigger one is chosen (e.g. u32 over u16).
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct CbtEvent {
/// System time since Windows was started, in milliseconds.