aboutsummaryrefslogtreecommitdiffstats
path: root/utils/binary/write.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-10-31 14:56:38 +0000
committerGitHub <noreply@github.com>2016-10-31 14:56:38 +0000
commit659386309f36c482ddc0bb9e854ebda3da216491 (patch)
treeeb156bfbfad599f3dd88e184a7f690f67c64337d /utils/binary/write.go
parent5944d8a185ff1f91e0e108dab1d756fd88692c3b (diff)
downloadgo-git-659386309f36c482ddc0bb9e854ebda3da216491.tar.gz
utils: binary, new package that collect all the spare helper functions about binary operations (#102)
Diffstat (limited to 'utils/binary/write.go')
-rw-r--r--utils/binary/write.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/binary/write.go b/utils/binary/write.go
new file mode 100644
index 0000000..3ea1d91
--- /dev/null
+++ b/utils/binary/write.go
@@ -0,0 +1,30 @@
+package binary
+
+import (
+ "encoding/binary"
+ "io"
+)
+
+// Write writes the binary representation of data into w, using BigEndian order
+// https://golang.org/pkg/encoding/binary/#Write
+func Write(w io.Writer, data ...interface{}) error {
+ for _, v := range data {
+ if err := binary.Write(w, binary.BigEndian, v); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+// WriteUint32 writes the binary representation of a uint32 into w, in BigEndian
+// order
+func WriteUint32(w io.Writer, value uint32) error {
+ return binary.Write(w, binary.BigEndian, value)
+}
+
+// WriteUint16 writes the binary representation of a uint16 into w, in BigEndian
+// order
+func WriteUint16(w io.Writer, value uint16) error {
+ return binary.Write(w, binary.BigEndian, value)
+}