aboutsummaryrefslogtreecommitdiff
path: root/ber/int.go
diff options
context:
space:
mode:
Diffstat (limited to 'ber/int.go')
-rw-r--r--ber/int.go15
1 files changed, 11 insertions, 4 deletions
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)
+}