AS AgentScopeAPI 手册 / API Reference

MongoKeyEscaper

public final class MongoKeyEscaper
源码Source io/agentscope/extensions/mongodb/MongoKeyEscaper.java:36–157

Mongo 键 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)
static

设置该参数。

Escapes every map key recursively (nested maps and list elements included).

参数Parameters
名称Name类型Type说明Description
mapMap<String, Object>映射(类型 `Map`)。the map to escape; must not be `null`
返回Returns Map<String, Object>
返回映射。a new map with escaped keys, sharing non-map leaf values with the input
源码Source io/agentscope/extensions/mongodb/MongoKeyEscaper.java:52–58

unescape

public static Map<String, Object> unescape(Map<String, Object> map)
static

设置该参数。

Restores every map key recursively (nested maps and list elements included).

参数Parameters
名称Name类型Type说明Description
mapMap<String, Object>映射(类型 `Map`)。the map to unescape; must not be `null`
返回Returns Map<String, Object>
返回映射。a new map with unescaped keys, sharing non-map leaf values with the input
源码Source io/agentscope/extensions/mongodb/MongoKeyEscaper.java:66–72
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.