protoc-gen-golang-jsonshim

command
v1.15.0-bzc-beta.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

protoc-gen-jsonshim

protoc-gen-jsonshim is a plugin for protoc which generates MarshalJSON() and UnmarshalJSON() functions for .pb.go types. The implementations simply redirect to MarshalJSONPB() and UnmarshalJSONPB() respectively. This allows the types to be used with native Go JSON serialization.

Usage

Add the executable to your system's PATH, for example:

$ go install istio.io/tools/cmd/protoc-gen-golang-jsonshim

Add the golang-jsonshim_out option to your protoc command line, for example:

$ protoc --golang-jsonshim_out=:output/path ...

Examples Of Generated Code

// Code generated by protoc-gen-jsonshim. DO NOT EDIT.
package generated

import (
    bytes "bytes"
    jsonpb "github.com/golang/protobuf/jsonpb"
)

// MarshalJSON is a custom marshaler for Simple
func (this *Simple) MarshalJSON() ([]byte, error) {
    str, err := TypesMarshaler.MarshalToString(this)
    return []byte(str), err
}

// UnmarshalJSON is a custom unmarshaler for Simple
func (this *Simple) UnmarshalJSON(b []byte) error {
    return TypesUnmarshaler.Unmarshal(bytes.NewReader(b), this)
}

var (
    TypesMarshaler   = &jsonpb.Marshaler{}
    TypesUnmarshaler = &jsonpb.Unmarshaler{AllowUnknownFields: true}
)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
test
generated
Code generated by protoc-gen-jsonshim.
Code generated by protoc-gen-jsonshim.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL