Giter Site home page Giter Site logo

protoc-gen-go-hessian2's Introduction

protoc-gen-go-hessian2

Prerequisites

Before using protoc-gen-go-hessian2, make sure you have the following prerequisites installed on your system:

  • Go (version 1.17 or higher)
  • Protocol Buffers (version 3.0 or higher)

Installation

To install protoc-gen-go-hessian2, you can use go install:

go install github.com/dubbogo/protoc-gen-go-hessian2

Or you can clone this repository and build it manually:

git clone github.com/dubbogo/protoc-gen-go-hessian2
cd protoc-gen-go-hessian2
go build

Usage

To generate Hessian2 code using protoc-gen-go-hessian2, you can use the following command:

protoc -I ./ \
  --go-hessian2_out=./ --go-hessian2_opt=paths=source_relative \
  ./greet.proto

The --go-hessian2_out option specifies the output directory for the generated code, and --go-hessian2_opt=paths=source_relative sets the output path to be relative to the source file.

Example

To generate Hessian2 code for a simple message, you can create a .proto file with the following content:

syntax = "proto3";

package greet;

option go_package = "some_path/greet;greet";

import "unified_idl_extend/unified_idl_extend.proto";

message GreetRequest {
  string name = 1;

  option (unified_idl_extend.message_extend) = {
    java_class_name: "org.apache.greet.GreetRequest";
  };
}

message GreetResponse {
  string greeting = 1;

  option (unified_idl_extend.message_extend) = {
    java_class_name: "org.apache.greet.GreetResponse";
  };
}

Note that you need to import the unified_idl_extend package and extend the message with the message_extend option and set java_class_name to the corresponding Java class name.

Then, you can run the following command to generate the Hessian2 code:

protoc -I ./ \
  --go-hessian2_out=./ --go-hessian2_opt=paths=source_relative \
  ./greet.proto

This will generate the greet.hessian2.go file in the same directory as your greet.proto file:

.
├── greet.hessian2.go
├── greet.proto
└── unified_idl_extend
    ├── unified_idl_extend.pb.go
    └── unified_idl_extend.proto

The content of the greet.hessian2.go file will be:

// Code generated by protoc-gen-go-dubbo. DO NOT EDIT.

// Source: greet.proto
// Package: greet

package greet

import (
	dubbo_go_hessian2 "github.com/apache/dubbo-go-hessian2"
)

type GreetRequest struct {
	Name string
}

func (x *GreetRequest) JavaClassName() string {
	return "org.apache.greet.GreetRequest"
}

func (x *GreetRequest) String() string {
	e := dubbo_go_hessian2.NewEncoder()
	err := e.Encode(x)
	if err != nil {
		return ""
	}
	return string(e.Buffer())
}

func (x *GreetRequest) GetName() string {
	if x != nil {
		return x.Name
	}
	return ""
}

type GreetResponse struct {
	Greeting string
}

func (x *GreetResponse) JavaClassName() string {
	return "org.apache.greet.GreetResponse"
}

func (x *GreetResponse) String() string {
	e := dubbo_go_hessian2.NewEncoder()
	err := e.Encode(x)
	if err != nil {
		return ""
	}
	return string(e.Buffer())
}

func (x *GreetResponse) GetGreeting() string {
	if x != nil {
		return x.Greeting
	}
	return ""
}

func init() {
	dubbo_go_hessian2.RegisterPOJO(new(GreetRequest))
	dubbo_go_hessian2.RegisterPOJO(new(GreetResponse))
}

protoc-gen-go-hessian2's People

Contributors

yuukirn avatar chickenlj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.