From 7730784e5848c214b5d7206d753888d2f55ddb97 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 6 Aug 2015 17:21:46 +0200 Subject: Move from int64 to int --- ber/int.go | 20 ++++++-------------- ber/marshal.go | 2 +- ber/marshal_test.go | 3 +-- 3 files changed, 8 insertions(+), 17 deletions(-) (limited to 'ber') diff --git a/ber/int.go b/ber/int.go index 437e0c6..87816d1 100644 --- a/ber/int.go +++ b/ber/int.go @@ -1,12 +1,12 @@ package ber -func unmarshalInt(b []byte) (i int64) { +func UnmarshalInt(b []byte) (i int) { neg := b[0]&0x80 != 0 for n, v := range b { if neg { v = ^v } - i += int64(v) << uint((len(b)-n-1)*8) + i += int(v) << uint((len(b)-n-1)*8) } if neg { i = ^i @@ -14,18 +14,14 @@ func unmarshalInt(b []byte) (i int64) { return } -func unmarshalUint(b []byte) (i uint64) { +func unmarshalUint(b []byte) (i uint) { for n, v := range b { - i += uint64(v) << uint(n*8) + i += uint(v) << uint(n*8) } return } -func UnmarshalInt(b []byte) int { - return int(unmarshalInt(b)) -} - -func intLen(i int64) (n int) { +func intLen(i int) (n int) { for i > 255 { n++ i >>= 8 @@ -37,7 +33,7 @@ func intLen(i int64) (n int) { return n + 1 } -func marshalInt(i int64) (b []byte) { +func MarshalInt(i int) (b []byte) { for n := intLen(i); n > 0; n-- { b = append(b, byte(i>>uint((n-1)*8))) } @@ -49,7 +45,3 @@ func marshalInt(i int64) (b []byte) { } return } - -func MarshalInt(i int) []byte { - return marshalInt(int64(i)) -} diff --git a/ber/marshal.go b/ber/marshal.go index 79c1879..25e0cb1 100644 --- a/ber/marshal.go +++ b/ber/marshal.go @@ -79,7 +79,7 @@ func (e *encodeState) error(err error) { } func intEncoder(e *encodeState, v reflect.Value) { - b := marshalInt(v.Int()) + b := MarshalInt(int(v.Int())) e.Write(b) } diff --git a/ber/marshal_test.go b/ber/marshal_test.go index da568ed..688c593 100644 --- a/ber/marshal_test.go +++ b/ber/marshal_test.go @@ -6,7 +6,6 @@ func TestMarschal(t *testing.T) { i := 42 b, err := Marshal(i) if err != nil { - t.Error(err) + t.Error(b, err) } - t.Log(b) } -- cgit v1.2.3