From 1dc2ea374c4595cfcb550e3519278dab57b54be2 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 26 Jun 2015 20:29:11 +0200 Subject: Add String marshaler/unmarshaler --- ber/string.go | 9 +++++++++ ber/string_test.go | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 ber/string.go create mode 100644 ber/string_test.go (limited to 'ber') 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}) +} -- cgit v1.2.3