cloner

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cloner

type Cloner interface {
	Copy(out, in interface{}) error
	Clone(interface{}) (interface{}, error)
}

Cloner knows how to make copies of messages. It can be asked to copy one value into another, and it can also be asked to simply synthesize a new value that is a copy of some input value.

This is used to copy messages between in-process client and server. Copying will usually be more efficient than marshalling to bytes and back (though that is a valid strategy that a custom Cloner implementation could take). Copies are made to avoid sharing values across client and server goroutines.

func CloneFunc

func CloneFunc(fn func(interface{}) (interface{}, error)) Cloner

CloneFunc adapts a single clone function to the Cloner interface. The given function implements the Clone method. To implement the Copy method, the given function is invoked and then reflection is used to shallow copy the clone to the output.

func CodecCloner

func CodecCloner(codec encoding.Codec) Cloner

CodecCloner uses the given codec to implement the Cloner interface. The Copy method is implemented by using the code to marshal the input to bytes and then unmarshal from bytes into the output value. The Clone method then uses reflection to create a new value of the same type and uses this strategy to then copy the input to the newly created value.

func CopyFunc

func CopyFunc(fn func(out, in interface{}) error) Cloner

CopyFunc adapts a single copy function to the Cloner interface. The given function implements the Copy method. To implement the Clone method, a new value of the same type is created using reflection and then the given function is used to copy the input to the newly created value.

Jump to

Keyboard shortcuts

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