msgpackrpc

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

MsgPack RPC Codec

Usage

Import the codec and set within the client/server

package main

import (
    "github.com/micro/go-plugins/codec/msgpackrpc"
    "github.com/micro/go-micro"
    "github.com/micro/go-micro/client"
    "github.com/micro/go-micro/server"
)

func main() {
    client := client.NewClient(
        client.Codec("application/msgpack", msgpackrpc.NewCodec),
        client.ContentType("application/msgpack"),
    )

    server := server.NewServer(
        server.Codec("application/msgpack", msgpackrpc.NewCodec),
    )

    service := micro.NewService(
        micro.Client(client),
        micro.Server(server),
    )

    // ...
}

Generating Request/Response types

The msgpack codec is much like protobuf. It expects the request/response types to conform to a specific interface. Usually this means defining some IDL and generating the required types.

Learn how to do that at github.com/tinylib/msgp

Documentation

Overview

Package msgpackrpc provides a msgpack-rpc codec

Index

Constants

View Source
const (
	RequestType      = 0
	ResponseType     = 1
	NotificationType = 2

	RequestPackSize      = 4
	ResponsePackSize     = 4
	NotificationPackSize = 3
)

The msgpack-rpc specification: https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md

Variables

View Source
var (
	ErrBadPackSize      = errors.New("Bad pack size")
	ErrBadMessageType   = errors.New("Bad message type")
	ErrBadErrorType     = errors.New("Bad error type")
	ErrUnexpectedParams = errors.New("Unexpected params")
	ErrNotEncodable     = errors.New("Not encodable")
	ErrNotDecodable     = errors.New("Not decodable")
)

Functions

func NewCodec

func NewCodec(rwc io.ReadWriteCloser) codec.Codec

Types

type Notification

type Notification struct {
	Method string
	Body   interface{}
	// contains filtered or unexported fields
}

func (*Notification) DecodeMsg

func (n *Notification) DecodeMsg(mr *msgp.Reader) error

func (*Notification) EncodeMsg

func (n *Notification) EncodeMsg(w *msgp.Writer) error

EncodeMsg encodes the notification to writer. The body is expected to be an encodable type.

type Request

type Request struct {
	ID     uint32
	Method string
	Body   interface{}
	// contains filtered or unexported fields
}

Request is what the client can construct to be sent to the server. The params represents the body of the request.

func (*Request) DecodeMsg

func (r *Request) DecodeMsg(mr *msgp.Reader) error

func (*Request) EncodeMsg

func (r *Request) EncodeMsg(w *msgp.Writer) error

EncodeMsg encodes the request to writer. The body is expected to be an encodable type.

type Response

type Response struct {
	ID    uint32
	Error string
	Body  interface{}
	// contains filtered or unexported fields
}

func (*Response) DecodeMsg

func (r *Response) DecodeMsg(mr *msgp.Reader) error

func (*Response) EncodeMsg

func (r *Response) EncodeMsg(w *msgp.Writer) error

Jump to

Keyboard shortcuts

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