func receiveProtobuf(conn *transport.Conn, inBuf []byte, t *testing.T) *proto.ServerToClient { response := new(proto.ServerToClient) conn.SetDeadline(time.Now().Add(time.Second)) num, err := conn.ReadFrame(inBuf) handleError(err, t) unpadMsg := proto.Unpad(inBuf[:num]) if err := response.Unmarshal(unpadMsg); err != nil { t.Error(err) } if response.Status == nil { t.Error("Server returned nil status.") } if *response.Status == proto.ServerToClient_PARSE_ERROR { t.Error("Server threw a parse error.") } return response }
func ReceiveProtobuf(conn *transport.Conn, inBuf []byte) (*proto.ServerToClient, error) { response := new(proto.ServerToClient) conn.SetDeadline(time.Now().Add(time.Hour)) num, err := conn.ReadFrame(inBuf) if err != nil { return nil, err } unpadMsg := proto.Unpad(inBuf[:num]) if err := response.Unmarshal(unpadMsg); err != nil { return nil, err } if response.Status == nil { return nil, errors.New("Server returned nil status.") } if *response.Status != proto.ServerToClient_OK { return nil, errors.New("Server did not return OK") } return response, nil }