From 6b6c369b624b9ddccd9a23eed78e0340db99ad85 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 27 Jun 2015 01:34:48 +0200 Subject: Add Marshal --- ber/int.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ber/int.go') diff --git a/ber/int.go b/ber/int.go index 32cc9af..97fd7b8 100644 --- a/ber/int.go +++ b/ber/int.go @@ -1,6 +1,8 @@ package ber -func intLen(i int) int { +import "reflect" + +func intLen(i int64) int { n := 1 for i > 255 { n++ @@ -13,7 +15,7 @@ func intLen(i int) int { return n } -func unmarshalInt(b []byte) (i int) { +func unmarshalInt(b []byte) (i int64) { nn := len(b) neg := b[0]&0x80 != 0 if b[0] == 0xFF { @@ -24,7 +26,7 @@ func unmarshalInt(b []byte) (i int) { if neg { v = ^v } - i += int(v) << uint((nn-n-1)*8) + i += int64(v) << uint((nn-n-1)*8) } if neg { i = -i - 1 @@ -32,7 +34,7 @@ func unmarshalInt(b []byte) (i int) { return } -func marshalInt(i int) (b []byte) { +func marshalInt(i int64) (b []byte) { for n := intLen(i); n > 0; n-- { b = append(b, byte(i>>uint((n-1)*8))) } @@ -44,3 +46,8 @@ func marshalInt(i int) (b []byte) { } return } + +func intEncoder(e *encodeState, v reflect.Value) { + b := marshalInt(v.Int()) + e.Write(b) +} -- cgit v1.2.3