MongoKeyEscaper
public final class MongoKeyEscaper
io/agentscope/extensions/mongodb/MongoKeyEscaper.java:36–157Mongo 键 Escaper,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.extensions.mongodb 包。核心成员包括 escape、unescape。
Recursively escapes and restores MongoDB field names inside arbitrary Map values.
MongoDB rejects '.' and a leading '$' in field names. Since state/BaseStore
values are caller-supplied Map<String, Object>, their keys can contain such characters
and would otherwise fail the write at encode time. This utility uses a backslash-prefix
encoding on write and its inverse on read so callers are not restricted by MongoDB naming rules.
The encoding is collision-free: . → \E, $ → \$, \0
→ \N, and a literal backslash → \\. Escaping the backslash itself is what
guarantees a bijective round-trip — a key that literally contains \E is stored as
\\E and restored to \E, never confused with an escaped dot.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static Map<String, Object> escape(Map<String, Object> map)static | 设置该参数。 Escapes every map key recursively (nested maps and list elements included). |
public static Map<String, Object> unescape(Map<String, Object> map)static | 设置该参数。 Restores every map key recursively (nested maps and list elements included). |
方法详情Method Detail
escape
public static Map<String, Object> escape(Map<String, Object> map)
设置该参数。
Escapes every map key recursively (nested maps and list elements included).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
map | Map<String, Object> | 映射(类型 `Map`)。the map to escape; must not be `null` |
Map<String, Object>io/agentscope/extensions/mongodb/MongoKeyEscaper.java:52–58unescape
public static Map<String, Object> unescape(Map<String, Object> map)
设置该参数。
Restores every map key recursively (nested maps and list elements included).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
map | Map<String, Object> | 映射(类型 `Map`)。the map to unescape; must not be `null` |
Map<String, Object>io/agentscope/extensions/mongodb/MongoKeyEscaper.java:66–72