diff options
Diffstat (limited to 'ber/len.go')
-rw-r--r-- | ber/len.go | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -1,12 +1,30 @@ package ber -func UnmarshalLen(b []byte) (i, n int) { +import ( + "io" +) + +func UnmarshalLen(r io.ByteReader) int { + b, _ := r.ReadByte() + if b&0x80 == 0 { + return int(b) + } + n := int(b & 0x7f) + var i int + for k := 0; k <= n; k++ { + b, _ := r.ReadByte() + i |= int(b) << uint(k*8) + } + return i +} + +func unmarshalLen(b []byte) (i, n int) { if b[0]&0x80 == 0 { return int(b[0]), 1 } n = int(b[0] & 0x7f) - for k := n; k > 0; k-- { - i += int(b[k]) << uint((k-1)*8) + for k := 0; k <= n; k++ { + i |= int(b[k]) << uint((k-1)*8) } return i, n + 1 } |