internal

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 关系分隔符定义
	SepRemarkAt     = "@" // 补充关系
	SepLineDot      = "." // 线性递进
	SepSetXX        = "+" // 并列集合
	SepMapping      = ":" // 映射关系
	SepCombineSpace = " " // 组合关系
)
View Source
const (
	ModeA = 'a' // Double Base58
	ModeC = 'c' // Double Base64URL
	ModeQ = 'q' // Hybrid + Global Base64URL
	ModeP = 'p' // Hybrid Plaintext

	//编码标识符,PQ模式专用
	EncodedExclaim = "!" //混编转义符,标明这是一个被强制编码的非原文token
)

编码模式

Variables

This section is empty.

Functions

func CML2A

func CML2A(encoded string) (string, error)

将cml编码,转换成a模式的cml

func CML2C

func CML2C(encoded string) (string, error)

将cml编码,转换成c模式的cml

func CML2P

func CML2P(encoded string) (string, error)

将cml编码,转换成p模式的cml

func CML2Q

func CML2Q(encoded string) (string, error)

将cml编码,转换成q模式的cml

func IsCML

func IsCML(encoded string) error

* 检查CML编码是否合法

Types

type CmlElement

type CmlElement struct {
	Type  CmlElementType
	Value string
}

语义基元,构建单序列的单元

type CmlElementType

type CmlElementType int

基元类型

const (
	TypeToken CmlElementType = iota
	TypeSeparator
)

type CmlElements

type CmlElements []*CmlElement

* 由于Go语言限制,[]*CmlElement 不能直接作为类型接收者挂载方法 所以需要别名抽象来实现

func CML2Elements

func CML2Elements(encoded string) (*CmlElements, error)

CML2Elements 将CML字符串解析为基元序列

func (*CmlElements) EncodeA

func (elements *CmlElements) EncodeA() (string, error)

EncodeA 编码成 a 模式,双层base58,字符集普适性最好,但性能不利于大规模场景

func (*CmlElements) EncodeC

func (elements *CmlElements) EncodeC() (string, error)

EncodeC 编码成 c 模式(高性能 base64)

func (*CmlElements) EncodeP

func (elements *CmlElements) EncodeP() (string, error)

EncodeP 编码成 p 模式(单层明文混编,最小熵增)

func (*CmlElements) EncodeQ

func (elements *CmlElements) EncodeQ() (string, error)

EncodeQ 编码成 q 模式(双层混编,在不可读的前提上,提供最小熵增)

func (*CmlElements) IsValid

func (elements *CmlElements) IsValid() error

检查 CML 基元序列的奇偶交替特征是否合法

type CmlFragments

type CmlFragments struct {
	Tokens    []string // 所有的实体内容
	Relations []string // 所有的关系符 (@, ., +, :, 空格)
}

语义基元集合,两类基元的双序列

func CML2Fragments

func CML2Fragments(encoded string) (*CmlFragments, error)

CML2Elements 将编码后的CML字符串解析为基元序列

func New

func New(arr []string) (*CmlFragments, error)

New 将平铺的字符串切片转换为双列表结构的 CmlFragments 输入示例: []string{"user", "@", "domain", ".", "com"} 输出示例: Tokens: ["user", "domain", "com"], Relations: ["@", "."]

func (*CmlFragments) EncodeA

func (f *CmlFragments) EncodeA() (string, error)

EncodeA 编码成 a 模式:双层 base58 字符集普适性最好,但性能不理想,适用于对字符集安全性要求极高的场景

func (*CmlFragments) EncodeC

func (f *CmlFragments) EncodeC() (string, error)

EncodeC 编码成 c 模式:双层 base64 (高性能) 适合大规模、高并发处理场景

func (*CmlFragments) EncodeP

func (f *CmlFragments) EncodeP() (string, error)

EncodeP 编码成 p 模式:单层明文混编 保持最小熵增,提供最佳的可读性与长度比

func (*CmlFragments) EncodeQ

func (f *CmlFragments) EncodeQ() (string, error)

EncodeQ 编码成 q 模式:双层混编 在不可读的前提下,通过智能判断减少不必要的 Base64 转换,提供最小熵增

func (*CmlFragments) IsValid

func (f *CmlFragments) IsValid() error

检查 CmlFragments 是否符合奇偶性特征 CML 规则:Token 数量必须比 Relations 数量多 1 (即:T R T R T)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL