base packet encoding/decoding stuff