func (q *quasarDB) receive(conn *tsConn) (common.SmapNumbersResponse, error) { var sr = common.SmapNumbersResponse{} seg, err := capn.ReadFromStream(conn, nil) if err != nil { conn.Close() log.Errorf("Error receiving data from Quasar %v", err) return sr, err } resp := qsr.ReadRootResponse(seg) //log.Debug("qsr resp %v", resp.Which()) //log.Debug("status code %v", resp.StatusCode()) switch resp.Which() { case qsr.RESPONSE_VOID: if resp.StatusCode() != qsr.STATUSCODE_OK { return sr, fmt.Errorf("Received error status code when writing: %v", resp.StatusCode()) } case qsr.RESPONSE_RECORDS: if resp.StatusCode() != 0 { return sr, fmt.Errorf("Error when reading from Quasar: %v", resp.StatusCode().String()) } sr.Readings = []*common.SmapNumberReading{} for _, rec := range resp.Records().Values().ToArray() { sr.Readings = append(sr.Readings, &common.SmapNumberReading{Time: uint64(rec.Time()), Value: rec.Value()}) } return sr, nil default: return sr, fmt.Errorf("Got unexpected Quasar Error code (%v)", resp.StatusCode().String()) } return sr, nil }
func (bdb *btrIface) numberResponseFromChan(c chan btrdb.StandardValue) common.SmapNumbersResponse { var sr = common.SmapNumbersResponse{ Readings: []*common.SmapNumberReading{}, } for val := range c { sr.Readings = append(sr.Readings, &common.SmapNumberReading{Time: uint64(val.Time), Value: val.Value, UoT: common.UOT_NS}) } return sr }