MetaMessage 的簡單使用

举报
大漠孤煙 发表于 2026/05/07 21:22:52 2026/05/07
【摘要】 簡單寫下cli的使用先下載:MetaMessage 改個名,方便使用:mv mm_0.1.8_darwin_arm64 mm一個簡單的jsonc:cat input.jsonc { "a":2,}序列化:./mm -e -i input.jsonc -o output.mmEncoding Mode, Input: input.jsonc, Output: output.mm看下大小:...

簡單寫下cli的使用

先下載:


截屏2026-05-07 20.32.40.png


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  57 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
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。