aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-08-06 17:21:46 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-08-06 17:21:46 +0200
commit7730784e5848c214b5d7206d753888d2f55ddb97 (patch)
treecc3099e795dca1a1ee0ec73bc25cfc53ab75d644 /ber
parentec6c8b5883eccdf304b932e25f847a2546ec46f5 (diff)
Move from int64 to int
Diffstat (limited to 'ber')
-rw-r--r--ber/int.go20
-rw-r--r--ber/marshal.go2
-rw-r--r--ber/marshal_test.go3
3 files changed, 8 insertions, 17 deletions
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)
}