aboutsummaryrefslogtreecommitdiff
path: root/plugin/dnstap/msg/wrapper.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/dnstap/msg/wrapper.go')
-rw-r--r--plugin/dnstap/msg/wrapper.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/plugin/dnstap/msg/wrapper.go b/plugin/dnstap/msg/wrapper.go
new file mode 100644
index 000000000..a74c604d8
--- /dev/null
+++ b/plugin/dnstap/msg/wrapper.go
@@ -0,0 +1,26 @@
+package msg
+
+import (
+ "fmt"
+
+ lib "github.com/dnstap/golang-dnstap"
+ "github.com/golang/protobuf/proto"
+)
+
+func wrap(m *lib.Message) *lib.Dnstap {
+ t := lib.Dnstap_MESSAGE
+ return &lib.Dnstap{
+ Type: &t,
+ Message: m,
+ }
+}
+
+// Marshal encodes the message to a binary dnstap payload.
+func Marshal(m *lib.Message) (data []byte, err error) {
+ data, err = proto.Marshal(wrap(m))
+ if err != nil {
+ err = fmt.Errorf("proto: %s", err)
+ return
+ }
+ return
+}