Saturday, 28 September 2013

In golang how do you convert a slice into an array

In golang how do you convert a slice into an array

I am new to go and trying to write an application that reads RPM files.
The start of each block has a Magic char of [4]byte.
Here is my struct
type Lead struct {
Magic [4]byte
Major, Minor byte
Type uint16
Arch uint16
Name string
OS uint16
SigType uint16
}
I am trying to do the following:
lead := Lead{}
lead.Magic = buffer[0:4]
I am searching online and not sure how to go from a slice to an array
(without copying). I can always make the Magic []byte (or even uint64),
but I was more curious on how would I go from type []byte to [4]byte if
needed to?

No comments:

Post a Comment