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 /// Whether reference tracking is enabled.
38 /// When enabled, shared references and circular references are tracked
39 /// and preserved during serialization/deserialization.
40 pub track_ref: bool,
41}
42
43impl Default for Config {
44 fn default() -> Self {
45 Config {
46 compatible: false,
47 xlang: false,
48 share_meta: false,
49 compress_string: false,
50 max_dyn_depth: 5,
51 check_struct_version: false,
52 track_ref: false,
53 }
54 }
55}
56
57impl Config {
58 /// Creates a new Config with default values.
59 pub fn new() -> Self {
60 Self::default()
61 }
62
63 /// Check if compatible mode is enabled.
64 #[inline(always)]
65 pub fn is_compatible(&self) -> bool {
66 self.compatible
67 }
68
69 /// Check if cross-language mode is enabled.
70 #[inline(always)]
71 pub fn is_xlang(&self) -> bool {
72 self.xlang
73 }
74
75 /// Check if meta sharing is enabled.
76 #[inline(always)]
77 pub fn is_share_meta(&self) -> bool {
78 self.share_meta
79 }
80
81 /// Check if string compression is enabled.
82 #[inline(always)]
83 pub fn is_compress_string(&self) -> bool {
84 self.compress_string
85 }
86
87 /// Get maximum dynamic depth.
88 #[inline(always)]
89 pub fn max_dyn_depth(&self) -> u32 {
90 self.max_dyn_depth
91 }
92
93 /// Check if class version checking is enabled.
94 #[inline(always)]
95 pub fn is_check_struct_version(&self) -> bool {
96 self.check_struct_version
97 }
98
99 /// Check if reference tracking is enabled.
100 #[inline(always)]
101 pub fn is_track_ref(&self) -> bool {
102 self.track_ref
103 }
104}