mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
PsbValue now use BTreeMap
This commit is contained in:
@@ -11,7 +11,7 @@ use json::JsonValue;
|
|||||||
use serde::ser::SerializeStruct;
|
use serde::ser::SerializeStruct;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::PartialEq;
|
use std::cmp::PartialEq;
|
||||||
use std::collections::HashMap;
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
const NONE: PsbValueFixed = PsbValueFixed::None;
|
const NONE: PsbValueFixed = PsbValueFixed::None;
|
||||||
@@ -408,7 +408,7 @@ impl PsbValueFixed {
|
|||||||
PsbValueFixed::List(PsbListFixed { values })
|
PsbValueFixed::List(PsbListFixed { values })
|
||||||
}
|
}
|
||||||
JsonValue::Object(obj) => {
|
JsonValue::Object(obj) => {
|
||||||
let mut values = HashMap::new();
|
let mut values = BTreeMap::new();
|
||||||
for (key, value) in obj.iter() {
|
for (key, value) in obj.iter() {
|
||||||
values.insert(key.to_owned(), PsbValueFixed::from_json(value));
|
values.insert(key.to_owned(), PsbValueFixed::from_json(value));
|
||||||
}
|
}
|
||||||
@@ -496,7 +496,7 @@ impl IndexMut<&str> for PsbValueFixed {
|
|||||||
PsbValueFixed::Object(o) => o.index_mut(index),
|
PsbValueFixed::Object(o) => o.index_mut(index),
|
||||||
_ => {
|
_ => {
|
||||||
*self = PsbValueFixed::Object(PsbObjectFixed {
|
*self = PsbValueFixed::Object(PsbObjectFixed {
|
||||||
values: HashMap::new(),
|
values: BTreeMap::new(),
|
||||||
});
|
});
|
||||||
self.index_mut(index)
|
self.index_mut(index)
|
||||||
}
|
}
|
||||||
@@ -798,13 +798,13 @@ impl PsbListExt for PsbList {
|
|||||||
/// Represents a PSB object with key-value pairs.
|
/// Represents a PSB object with key-value pairs.
|
||||||
pub struct PsbObjectFixed {
|
pub struct PsbObjectFixed {
|
||||||
/// The key-value pairs in the object.
|
/// The key-value pairs in the object.
|
||||||
pub values: HashMap<String, PsbValueFixed>,
|
pub values: BTreeMap<String, PsbValueFixed>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PsbObjectFixed {
|
impl PsbObjectFixed {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
values: HashMap::new(),
|
values: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +893,7 @@ impl PsbObjectFixed {
|
|||||||
/// Converts a JSON object to a PSB object.
|
/// Converts a JSON object to a PSB object.
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
pub fn from_json(obj: &JsonValue) -> Self {
|
pub fn from_json(obj: &JsonValue) -> Self {
|
||||||
let mut values = HashMap::new();
|
let mut values = BTreeMap::new();
|
||||||
for (key, value) in obj.entries() {
|
for (key, value) in obj.entries() {
|
||||||
values.insert(key.to_owned(), PsbValueFixed::from_json(value));
|
values.insert(key.to_owned(), PsbValueFixed::from_json(value));
|
||||||
}
|
}
|
||||||
@@ -951,7 +951,7 @@ pub trait PsbObjectExt {
|
|||||||
|
|
||||||
impl PsbObjectExt for PsbObject {
|
impl PsbObjectExt for PsbObject {
|
||||||
fn to_psb_fixed(self) -> PsbObjectFixed {
|
fn to_psb_fixed(self) -> PsbObjectFixed {
|
||||||
let mut hash_map = HashMap::new();
|
let mut hash_map = BTreeMap::new();
|
||||||
for (key, value) in self.unwrap() {
|
for (key, value) in self.unwrap() {
|
||||||
hash_map.insert(key, PsbValue::to_psb_fixed(value));
|
hash_map.insert(key, PsbValue::to_psb_fixed(value));
|
||||||
}
|
}
|
||||||
@@ -961,7 +961,7 @@ impl PsbObjectExt for PsbObject {
|
|||||||
|
|
||||||
/// Iterator for a slice of PSB values in an object.
|
/// Iterator for a slice of PSB values in an object.
|
||||||
pub struct ObjectIter<'a> {
|
pub struct ObjectIter<'a> {
|
||||||
inner: std::collections::hash_map::Iter<'a, String, PsbValueFixed>,
|
inner: std::collections::btree_map::Iter<'a, String, PsbValueFixed>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ObjectIter<'a> {
|
impl<'a> ObjectIter<'a> {
|
||||||
@@ -981,15 +981,23 @@ impl<'a> Iterator for ObjectIter<'a> {
|
|||||||
self.inner.next()
|
self.inner.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExactSizeIterator for ObjectIter<'a> {
|
impl<'a> ExactSizeIterator for ObjectIter<'a> {
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.inner.len()
|
self.inner.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> DoubleEndedIterator for ObjectIter<'a> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
|
self.inner.next_back()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Mutable iterator for a slice of PSB values in an object.
|
/// Mutable iterator for a slice of PSB values in an object.
|
||||||
pub struct ObjectIterMut<'a> {
|
pub struct ObjectIterMut<'a> {
|
||||||
inner: std::collections::hash_map::IterMut<'a, String, PsbValueFixed>,
|
inner: std::collections::btree_map::IterMut<'a, String, PsbValueFixed>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ObjectIterMut<'a> {
|
impl<'a> ObjectIterMut<'a> {
|
||||||
@@ -1016,6 +1024,13 @@ impl<'a> ExactSizeIterator for ObjectIterMut<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> DoubleEndedIterator for ObjectIterMut<'a> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
|
self.inner.next_back()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a fixed version of a virtual PSB.
|
/// Represents a fixed version of a virtual PSB.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct VirtualPsbFixed {
|
pub struct VirtualPsbFixed {
|
||||||
|
|||||||
Reference in New Issue
Block a user