feat: プラグインFFIとTypeBox/TLVテストの拡張

- plugin_ffi_common: デバッグ情報とコメント追加
- typebox_tlv_diff: 差分テストの詳細化

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-09-04 20:16:34 +09:00
parent c7a7ac61b7
commit 9a1db62238
2 changed files with 30 additions and 0 deletions

View File

@ -1,6 +1,8 @@
//! Common FFI helpers for Plugin system
//! Minimal TLV utilities extracted for unified facade usage.
use crate::box_trait::NyashBox;
/// Encode empty TLV arguments: version=1, argc=0
pub fn encode_empty_args() -> Vec<u8> { vec![1u8, 0, 0, 0] }
@ -12,6 +14,22 @@ pub fn encode_tlv_header(argc: u16) -> Vec<u8> {
buf
}
/// Encode a slice of NyashBox arguments into TLV buffer (v1)
/// Policy: prefer i64 numeric when coercible; otherwise UTF-8 string; otherwise to_string_box()
pub fn encode_args(args: &[Box<dyn NyashBox>]) -> Vec<u8> {
let mut buf = encode_tlv_header(args.len() as u16);
for a in args {
if let Some(i) = crate::runtime::semantics::coerce_to_i64(a.as_ref()) {
encode::i64(&mut buf, i);
} else if let Some(s) = crate::runtime::semantics::coerce_to_string(a.as_ref()) {
encode::string(&mut buf, &s);
} else {
encode::string(&mut buf, &a.to_string_box().value);
}
}
buf
}
/// Simple helpers for common primitive returns
pub mod decode {
/// Try to parse a u32 instance id from an output buffer (little-endian).