Thanks a lot! This works as expected, I think functions for BigEndian and 
LittleEndian should be documented or at least referenced in the binary 
documentation.

import (
"encoding/binary"
"fmt"
"time"
)

func main() {
t := time.Now()
b1 := make([]byte, 8)
b2 := make([]byte, 8)
binary.BigEndian.PutUint64(b1, uint64(t.Unix()))
binary.BigEndian.PutUint64(b2, uint64(t.UnixNano()))
i1 := binary.BigEndian.Uint64(b1)
i2 := binary.BigEndian.Uint64(b2)
fmt.Println("Unix:", t.Unix(), b1, "->", i1)
fmt.Println("UnixNano:", t.UnixNano(), b2, "->", i2)
}


On Monday, February 27, 2017 at 12:44:56 PM UTC-6, Guillermo Estrada wrote:
>
> On Monday, February 27, 2017 at 12:41:43 PM UTC-6, zeebo wrote:
>>
>> You're using the variable width encoding. The number of bytes of a 
>> variable width encoded int64 will depend on the magnitude of the value. If 
>> you use binary.BigEndian or binary.LittleEndian you can use the 
>> *PutUint64* method which will always be 8 bytes.
>>
>
> Thank you! I can see I can find them here if I go into the code:
>
> https://golang.org/src/encoding/binary/binary.go
>
> Although those functions are NOT documented here:
>
> https://golang.org/pkg/encoding/binary/
>
> Shouldn't they be?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to