Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEmptyMessage = errors.New("message is nil")
ErrEmptyMessage when message is nil
Functions ¶
func GetMessageName ¶
GetMessageName returns the message name from the wrapped proto message
Example ¶
package main import ( "fmt" "github.com/vimeda/pletter/pb" ) func main() { // Create your proto message ac := pb.Example{ ID: "1231231312", } // call the PackAndMarshal function to wrap your message and already proto.Marshal it raw, err := any.PackAndMarshal(&ac) if err != nil { fmt.Printf("an error occurred while packing and marshalling the message: %s", err) } // call the Unpack function that will unwrap your message from the envelop name, err := any.GetMessageName(raw) if err != nil { fmt.Printf("an error occurred while getting the message name: %s", err) } fmt.Printf("message name: %s", name) // should print pb.Example }
Output:
func Pack ¶
Pack packs a proto message into an envelope message
Example ¶
package main import ( "fmt" "github.com/vimeda/pletter/pb" ) func main() { // Create your proto message ac := pb.Example{ ID: "1231231312", } // call the Pack function to wrap your message. This returns an envelop type _, err := any.Pack(&ac) if err != nil { fmt.Printf("an error occurred while packing the message: %s", err) } }
Output:
func PackAndMarshal ¶
PackAndMarshal packs a proto message into an envelope message and marshal it
Example ¶
package main import ( "fmt" "github.com/vimeda/pletter/pb" ) func main() { // Create your proto message ac := pb.Example{ ID: "1231231312", } // call the PackAndMarshal function to wrap your message and already proto.Marshal it _, err := any.PackAndMarshal(&ac) if err != nil { fmt.Printf("an error occurred while packing and marshalling the message: %s", err) } }
Output:
func Unpack ¶
Unpack unpacks a slice of bytes into a proto message. The slice of bytes should represent an enveloped proto message
Example ¶
package main import ( "fmt" "github.com/vimeda/pletter/pb" ) func main() { // Create your proto message ac := pb.Example{ ID: "1231231312", } // call the PackAndMarshal function to wrap your message and already proto.Marshal it raw, err := any.PackAndMarshal(&ac) if err != nil { fmt.Printf("an error occurred while packing and marshalling the message: %s", err) } // declare your expected type var expectedExample pb.Example // call the Unpack function that will unwrap your message from the envelop if err := any.Unpack(raw, &expectedExample); err != nil { fmt.Printf("an error occurred while unpacking the message: %s", err) } }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.