I am writing a program that should analyze and respond to network packets, but it annoys me a bit, because I cannot make a simple style C return (int)buffer[at]; with an array of bytes. Is there a better way to get 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 wondered if there is a better way to do this.
source share