fory_core/
config.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18/// Configuration for Fory serialization.
19///
20/// This struct holds all the configuration options that control how Fory
21/// serializes and deserializes data. It is shared between the main `Fory`
22/// instance and the `WriteContext`/`ReadContext` to ensure consistent behavior.
23#[derive(Clone, Debug)]
24pub struct Config {
25    /// Whether compatible mode is enabled for schema evolution support.
26    pub compatible: bool,
27    /// Whether cross-language serialization is enabled.
28    pub xlang: bool,
29    /// Whether metadata sharing is enabled.
30    pub share_meta: bool,
31    /// Whether meta string compression is enabled.
32    pub compress_string: bool,
33    /// Maximum depth for nested dynamic object serialization.
34    pub max_dyn_depth: u32,
35    /// Whether class version checking is enabled.
36    pub check_struct_version: bool,
37}
38
39impl Default for Config {
40    fn default() -> Self {
41        Config {
42            compatible: false,
43            xlang: false,
44            share_meta: false,
45            compress_string: false,
46            max_dyn_depth: 5,
47            check_struct_version: false,
48        }
49    }
50}
51
52impl Config {
53    /// Creates a new Config with default values.
54    pub fn new() -> Self {
55        Self::default()
56    }
57
58    /// Check if compatible mode is enabled.
59    #[inline(always)]
60    pub fn is_compatible(&self) -> bool {
61        self.compatible
62    }
63
64    /// Check if cross-language mode is enabled.
65    #[inline(always)]
66    pub fn is_xlang(&self) -> bool {
67        self.xlang
68    }
69
70    /// Check if meta sharing is enabled.
71    #[inline(always)]
72    pub fn is_share_meta(&self) -> bool {
73        self.share_meta
74    }
75
76    /// Check if string compression is enabled.
77    #[inline(always)]
78    pub fn is_compress_string(&self) -> bool {
79        self.compress_string
80    }
81
82    /// Get maximum dynamic depth.
83    #[inline(always)]
84    pub fn max_dyn_depth(&self) -> u32 {
85        self.max_dyn_depth
86    }
87
88    /// Check if class version checking is enabled.
89    #[inline(always)]
90    pub fn is_check_struct_version(&self) -> bool {
91        self.check_struct_version
92    }
93}