apps/node 중심 구현 — TCP+JSON transport, Hexagonal Architecture, mock/cli adapter, fx DI, SQLite 실행 이력 저장. edge/control-plane/worker는 cobra placeholder. 유닛 테스트 및 통합 테스트 클라이언트 계획서 추가.
32 lines
820 B
Go
32 lines
820 B
Go
package transport
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"iop/packages/protocol"
|
|
)
|
|
|
|
// encodeEnvelope marshals env to JSON bytes (the frame payload).
|
|
func encodeEnvelope(env *protocol.Envelope) ([]byte, error) {
|
|
return json.Marshal(env)
|
|
}
|
|
|
|
// decodeEnvelope unmarshals frame payload bytes into an Envelope.
|
|
func decodeEnvelope(data []byte) (*protocol.Envelope, error) {
|
|
var env protocol.Envelope
|
|
if err := json.Unmarshal(data, &env); err != nil {
|
|
return nil, fmt.Errorf("decode envelope: %w", err)
|
|
}
|
|
return &env, nil
|
|
}
|
|
|
|
// encodePayload marshals an inner message to JSON bytes for Envelope.Payload.
|
|
func encodePayload(v any) ([]byte, error) {
|
|
return json.Marshal(v)
|
|
}
|
|
|
|
// decodePayload unmarshals Envelope.Payload into dst.
|
|
func decodePayload(payload []byte, dst any) error {
|
|
return json.Unmarshal(payload, dst)
|
|
}
|