簡單寫下cli的使用
先下載:
MetaMessage
改個名,方便使用:
mv mm_0.1.8_darwin_arm64 mm
一個簡單的jsonc:
cat input.jsonc
{
"a":2,
}
序列化:
./mm -e -i input.jsonc -o output.mm
Encoding Mode, Input: input.jsonc, Output: output.mm
看下大小:
ll output.mm
-rw-r--r-- 1 lizongying staff 5 5月 7 20:27 output.mm
反序列化:
./mm -d -i output.mm
Decoding Mode, Input: output.mm, Output:
{
"a": 2,
}
生成golang的結構體和綁定後的數據:
./mm -g -i input.jsonc -l go
Generation Mode, Input: input.jsonc, Output: , Target Language: go
// Code generated by mm. DO NOT EDIT.
package main
type Obj struct {
A int
}
var _ = Obj{
A: 2,
}
幫助信息:
./mm
Error: A mode must be specified! Valid options: -encode / -decode / -generate
Usage: ./mm [OPTIONS]
Mode (mutually exclusive, choose one):
-encode, -e Encode JSONC to MetaMessage format
-decode, -d Decode MetaMessage to JSONC format
-generate, -g Generate value code from JSONC
Common Options:
-in, -i string Input file path (empty = read from stdin)
-out, -o string Output file path (empty = write to stdout)
-force, -f Overwrite output file if it exists (default: false)
Generate Options (only for -gen):
-lang, -l string Target language (default: , support: go, java, ts, kt, py, js, cs, rs, swift, php)
Examples:
# Encode JSONC to MetaMessage (stdin -> stdout)
./mm -encode -in input.jsonc -out output.MetaMessage
# Decode MetaMessage to JSONC (stdin -> stdout)
./mm -decode < input.MetaMessage > output.jsonc
# Generate Go struct from JSONC
./mm -gen -lang go -in input.jsonc -out output.go
# Generate Java struct from JSONC
./mm -gen -lang java -in input.jsonc -out output.java
# Generate Kotlin struct from JSONC
./mm -gen -lang kt -in input.jsonc -out output.kt
# Generate Python struct from JSONC
./mm -gen -lang py -in input.jsonc -out output.py
# Generate JavaScript class from JSONC
./mm -gen -lang js -in input.jsonc -out output.js
# Generate C# class from JSONC
./mm -gen -lang cs -in input.jsonc -out output.cs
# Generate Rust struct from JSONC
./mm -gen -lang rs -in input.jsonc -out output.rs
# Generate Swift struct from JSONC
./mm -gen -lang swift -in input.jsonc -out output.swift
# Generate PHP class from JSONC
./mm -gen -lang php -in input.jsonc -out output.php