I'm writing a program that should parse and reply to network packets but I'm a bit annoyed because I can't do simple C style return (int)buffer[at];
with an array of bytes. Is there any better way to retrieve 4 bytes from byte[] as int32 than the following?
func (packet *Packet) GetInt32(at int) int32 {
return int32(packet.buffer[at]) << 24 +
int32(packet.buffer[at+1]) << 16 +
int32(packet.buffer[at+2]) << 8 +
int32(packet.buffer[at+3])
}
It works correctly but I was thinking if there was a better way to do this.