aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-06-26 20:29:11 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-06-26 20:29:11 +0200
commit1dc2ea374c4595cfcb550e3519278dab57b54be2 (patch)
tree9241be49feadb39d2bb219efa8b7e4864c9a000d /ber
parent7750e4b583a0962f18c3844e74b6ee87206d84e6 (diff)
Add String marshaler/unmarshaler
Diffstat (limited to 'ber')
-rw-r--r--ber/string.go9
-rw-r--r--ber/string_test.go22
2 files changed, 31 insertions, 0 deletions
diff --git a/ber/string.go b/ber/string.go
new file mode 100644
index 0000000..77d0ea4
--- /dev/null
+++ b/ber/string.go
@@ -0,0 +1,9 @@
+package ber
+
+func marshalString(s string) []byte {
+ return []byte(s)
+}
+
+func unmarshalString(b []byte) string {
+ return string(b)
+}
diff --git a/ber/string_test.go b/ber/string_test.go
new file mode 100644
index 0000000..72c3a2a
--- /dev/null
+++ b/ber/string_test.go
@@ -0,0 +1,22 @@
+package ber
+
+import (
+ "bytes"
+ "testing"
+)
+
+func testString(t *testing.T, s string, e []byte) {
+ a := marshalString(s)
+ if !bytes.Equal(a, e) {
+ t.Error("String", s, "expexted", e, "got", a)
+ }
+
+ b := unmarshalString(e)
+ if b != s {
+ t.Error("DeString", e, "expexted", s, "got", b)
+ }
+}
+
+func TestString(t *testing.T) {
+ testString(t, "111", []byte{0x31, 0x31, 0x31})
+}