serialize

package
v0.0.0-...-abdb4f7 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package serialize provides a Serializer interface with implementations that encode and decode message data in various ways.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MsgpackRegisterExtension

func MsgpackRegisterExtension(t reflect.Type, ext byte, encode func(reflect.Value) ([]byte, error), decode func(reflect.Value, []byte) error)

MsgpackRegisterExtension registers a custom type for special serialization.

Types

type BinaryData

type BinaryData []byte

Binary data follows a convention for conversion to JSON strings.

A byte array is converted to a JSON string as follows:

1. convert the byte array to a Base64 encoded (host language) string 2. prepend the string with a \0 character 3. serialize the string to a JSON string

func (BinaryData) MarshalJSON

func (b BinaryData) MarshalJSON() ([]byte, error)

func (*BinaryData) UnmarshalJSON

func (b *BinaryData) UnmarshalJSON(v []byte) error

type CBORSerializer

type CBORSerializer struct{}

CBORSerializer is an implementation of Serializer that handles serializing and deserializing cbor encoded payloads.

func (*CBORSerializer) Deserialize

func (s *CBORSerializer) Deserialize(data []byte) (wamp.Message, error)

Deserialize decodes a cbor payload into a Message.

func (*CBORSerializer) Serialize

func (s *CBORSerializer) Serialize(msg wamp.Message) ([]byte, error)

Serialize encodes a Message into a cbor payload.

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer is an implementation of Serializer that handles serializing and deserializing json encoded payloads.

func (*JSONSerializer) Deserialize

func (s *JSONSerializer) Deserialize(data []byte) (wamp.Message, error)

Deserialize decodes a json payload into a Message.

func (*JSONSerializer) Serialize

func (s *JSONSerializer) Serialize(msg wamp.Message) ([]byte, error)

Serialize encodes a Message into a json payload.

type MessagePackSerializer

type MessagePackSerializer struct{}

MessagePackSerializer is an implementation of Serializer that handles serializing and deserializing msgpack encoded payloads.

func (*MessagePackSerializer) Deserialize

func (s *MessagePackSerializer) Deserialize(data []byte) (wamp.Message, error)

Deserialize decodes a msgpack payload into a Message.

func (*MessagePackSerializer) Serialize

func (s *MessagePackSerializer) Serialize(msg wamp.Message) ([]byte, error)

Serialize encodes a Message into a msgpack payload.

type Serialization

type Serialization int

Serialization indicates the data serialization format used in a WAMP session

const (
	// Use JSON-encoded strings as a payload.
	JSON Serialization = iota
	// Use msgpack-encoded strings as a payload.
	MSGPACK
	// Use CBOR encoding as a payload
	CBOR
)

type Serializer

type Serializer interface {
	Serialize(wamp.Message) ([]byte, error)
	Deserialize([]byte) (wamp.Message, error)
}

Serializer is the interface implemented by an object that can serialize and deserialize WAMP messages

Jump to

Keyboard shortcuts

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