GoWindGoWind
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
  • Introduction

    • GoWind Framework
    • Framework Architecture
  • go-wind Core

    • go-wind Core Framework
    • App Lifecycle Management
    • Context Propagation
    • Transport Abstraction
    • Log Facade Interface
  • go-wind-plugins

    • go-wind-plugins Plugin Overview
    • Plugin Configuration System
    • Plugin Registration Mechanism (SPI)
    • Logging Adapter Plugins
    • Transport Protocol Plugins
    • Message Middleware Plugins
    • Encoding Plugins
    • Security and Authentication Plugins
    • Distributed Tracing Plugins
    • Cache Plugins
    • Object Storage Plugins (OSS)
    • Rate Limiting Plugins
    • Metrics Plugins
    • AI Plugins
    • Workflow Plugins
    • Database and Cache Plugins
    • Bootstrap Integration and Gateway Plugins
    • Compression and Serialization Plugins
    • Template Rendering and Validation Plugins
  • go-wind-bootstrap

    • go-wind-bootstrap: The Declarative Bootstrap
    • The Bootstrap Configuration System
    • The Bootstrap SPI Mechanism
    • Declarative Middleware Orchestration
    • Bootstrap Command-Line Integration
    • Bootstrap Practical Examples
  • go-wind-flow Workflow Engine

    • GoWind Flow Process Engine
  • Tutorials

    • Quick Start Tutorial
    • Custom Plugin Development Tutorial
    • Multi-Protocol Listening Tutorial
    • Framework Migration Guide

Encoding Plugins

go-wind-plugins provides a unified codec interface for serializing/deserializing HTTP request bodies, gRPC messages, Broker messages, and more.

1. The Codec Interface

type Codec interface {
    Marshal(v interface{}) ([]byte, error)
    Unmarshal(data []byte, v interface{}) error
    Name() string
}

2. Built-in Encodings

There are 12 codec plugins in total:

EncodingImport PathEngine
JSONplugins/encoding/jsonencoding/json
Protobufplugins/encoding/protogoogle.golang.org/protobuf
YAMLplugins/encoding/yamlgopkg.in/yaml.v3
TOMLplugins/encoding/tomlpelletier/go-toml
XMLplugins/encoding/xmlencoding/xml
MessagePackplugins/encoding/msgpackvmihailenco/msgpack
Avroplugins/encoding/avrolinkedin/goavro
BSONplugins/encoding/bsongo.mongodb.org/mongo-driver
CBORplugins/encoding/cborfxamacker/cbor
FlatBuffersplugins/encoding/flatbuffersgoogle/flatbuffers
Gobplugins/encoding/gobencoding/gob
Thriftplugins/encoding/thriftApache Thrift

3. Registering Codecs

import (
    _ "github.com/tx7do/go-wind-plugins/encoding/json"
    _ "github.com/tx7do/go-wind-plugins/encoding/proto"
)

// init() registers them into the global codec registry automatically

4. Usage

4.1 Encoding and Decoding

import "github.com/tx7do/go-wind-plugins/encoding"

// Get a codec
jsonCodec := encoding.GetCodec("json")

// Encode
data, _ := jsonCodec.Marshal(user)

// Decode
var user User
jsonCodec.Unmarshal(data, &user)

4.2 HTTP Requests/Responses

// The transport layer picks the codec automatically based on Content-Type
// A client sending application/json → the JSON codec is used
// A client sending application/protobuf → the Protobuf codec is used

4.3 Broker Messages

msg := &broker.Message{
    Headers: map[string]string{
        "Content-Type": "application/json",
    },
    Body: jsonData,
}

5. Custom Codecs

package mycodec

import "github.com/tx7do/go-wind-plugins/encoding"

type Codec struct{}

func (c *Codec) Marshal(v interface{}) ([]byte, error) {
    // custom serialization logic
    return serialize(v)
}

func (c *Codec) Unmarshal(data []byte, v interface{}) error {
    // custom deserialization logic
    return deserialize(data, v)
}

func (c *Codec) Name() string { return "my-format" }

func init() {
    // the registry keys entries by Name() (case-insensitive)
    encoding.RegisterCodec(&Codec{})
}

Related Documents

  • Plugin Configuration System
  • Plugin Registration Mechanism
  • Message Middleware Plugins
Edit this page
Last Updated:: 11/3/26, 2:14 PM
Contributors: Bobo
Prev
Message Middleware Plugins
Next
Security and Authentication Plugins