update date, destination, integer

This commit is contained in:
Hayden Parker
2016-02-14 22:40:29 -08:00
parent e19d6fa0ab
commit f9706700a1
4 changed files with 37 additions and 18 deletions

View File

@ -4,20 +4,22 @@ import (
"encoding/binary"
)
const (
INTEGER_SIZE = 8
)
//
// Interpret a slice of bytes from length 1
// to length 8 as a big-endian integer and
// return an int representation.
// Interpret a slice of bytes from length 0 to length 8 as a big-endian
// integer and return an int representation.
//
func Integer(number []byte) int {
func Integer(number []byte) (value int) {
num_len := len(number)
if num_len < 8 {
if num_len < INTEGER_SIZE {
number = append(
make([]byte, 8-num_len),
make([]byte, INTEGER_SIZE-num_len),
number...,
)
}
return int(
binary.BigEndian.Uint64(number),
)
value = int(binary.BigEndian.Uint64(number))
return
}