// Post a new reading
// Check if valuedescriptor exists in the database
512130
func (c *Client) AddReading(r contract.Reading) (id string, err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	if r.Id != "" {
		_, err = uuid.Parse(r.Id)
		if err != nil {
			return "", db.ErrInvalidObjectId
		}
	}
	return addReading(conn, true, r)
}
911625
func (_m *DBClient) ValueDescriptorsByLabel(label string) ([]models.ValueDescriptor, error) {
	ret := _m.Called(label)

	var r0 []models.ValueDescriptor
	if rf, ok := ret.Get(0).(func(string) []models.ValueDescriptor); ok {
		r0 = rf(label)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.ValueDescriptor)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(label)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1055938
func (zip GobMeddler) PostRead(fieldAddr, scanTarget interface{}) error {
	ptr := scanTarget.(*[]byte)
	if ptr == nil {
		return fmt.Errorf("GobMeddler.PostRead: nil pointer")
	}
	raw := *ptr

	if zip {
		// un-gzip and decode gob
		gzipReader, err := gzip.NewReader(bytes.NewReader(raw))
		if err != nil {
			return fmt.Errorf("Error creating gzip Reader: %v", err)
		}
		defer gzipReader.Close()
		gobDecoder := gob.NewDecoder(gzipReader)
		if err := gobDecoder.Decode(fieldAddr); err != nil {
			return fmt.Errorf("Gob decoder/gzip error: %v", err)
		}
		if err := gzipReader.Close(); err != nil {
			return fmt.Errorf("Closing gzip reader: %v", err)
		}

		return nil
	}

	// decode gob
	gobDecoder := gob.NewDecoder(bytes.NewReader(raw))
	if err := gobDecoder.Decode(fieldAddr); err != nil {
		return fmt.Errorf("Gob decode error: %v", err)
	}

	return nil
}
1151246
func readDataSet(endpoint, query string, args ...interface{}) ([]map[string]string, error) {
	var inst *Instance
	var exists bool
	if inst, exists = connectionPool[endpoint]; !exists {
		return nil, errNotRegistered
	}
	var err error
	var result *sql.Rows
	var columnName []string
	if result, err = inst.connection.Query(query, args...); err != nil {
		return nil, err
	}
	defer result.Close()
	if columnName, err = result.Columns(); err != nil {
		return nil, err
	}
	columnCount := len(columnName)
	columnValue := make([]interface{}, columnCount)
	var dataset []map[string]string
	for result.Next() {
		for i := 0; i < columnCount; i++ {
			columnValue[i] = new([]byte)
		}
		if err = result.Scan(columnValue...); err != nil {
			return nil, err
		}
		row := make(map[string]string)
		for i := 0; i < columnCount; i++ {
			row[columnName[i]] = string(*columnValue[i].(*[]byte))
		}
		dataset = append(dataset, row)
	}
	return dataset, nil
}
690875
func Post(url string, r io.Reader) error {
	status, _, rc, err := DefaultClient.Post(url, nil, r)
	if err != nil {
		return err
	}
	defer rc.Close()
	if !status.IsSuccess() {
		return &StatusError{status}
	}
	return nil
}
1191127
func (p *MemPostings) Get(name, value string) Postings {
	var lp []uint64
	p.mtx.RLock()
	l := p.m[name]
	if l != nil {
		lp = l[value]
	}
	p.mtx.RUnlock()

	if lp == nil {
		return EmptyPostings()
	}
	return newListPostings(lp...)
}
866491
func (_m *DBClient) ValueDescriptorsByUomLabel(uomLabel string) ([]models.ValueDescriptor, error) {
	ret := _m.Called(uomLabel)

	var r0 []models.ValueDescriptor
	if rf, ok := ret.Get(0).(func(string) []models.ValueDescriptor); ok {
		r0 = rf(uomLabel)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.ValueDescriptor)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(uomLabel)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
248995
func (mc MongoClient) ReadingsByValueDescriptorNames(names []string, limit int) ([]contract.Reading, error) {
	return mapReadings(mc.getReadingsLimit(bson.M{"name": bson.M{"$in": names}}, limit))
}
1325395
func (_m *DBClient) AddValueDescriptor(v models.ValueDescriptor) (string, error) {
	ret := _m.Called(v)

	var r0 string
	if rf, ok := ret.Get(0).(func(models.ValueDescriptor) string); ok {
		r0 = rf(v)
	} else {
		r0 = ret.Get(0).(string)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(models.ValueDescriptor) error); ok {
		r1 = rf(v)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
245534
func NewPostRef(client ClientInterface, post *MiniPost) *PostRef {
	return &PostRef{
		client:   client,
		MiniPost: *post,
	}
}
1350805
func (mc MongoClient) ValueDescriptorsByType(t string) ([]contract.ValueDescriptor, error) {
	return mapValueDescriptors(mc.getValueDescriptors(bson.M{"type": t}))
}
442788
func (elt TimeMeddler) PostRead(fieldAddr, scanTarget interface{}) error {
	switch tgt := fieldAddr.(type) {
	case *time.Time:
		if elt.ZeroIsNull {
			src := scanTarget.(**time.Time)
			if *src == nil {
				*tgt = time.Time{}
			} else if elt.Local {
				*tgt = (*src).Local()
			} else {
				*tgt = (*src).UTC()
			}
			return nil
		}

		src := scanTarget.(*time.Time)
		if elt.Local {
			*tgt = src.Local()
		} else {
			*tgt = src.UTC()
		}

		return nil

	case **time.Time:
		if elt.ZeroIsNull {
			return fmt.Errorf("meddler TimeMeddler cannot be used on a *time.Time field, only time.Time")
		}
		src := scanTarget.(**time.Time)
		if *src == nil {
			*tgt = nil
		} else if elt.Local {
			**src = (*src).Local()
			*tgt = *src
		} else {
			**src = (*src).UTC()
			*tgt = *src
		}

		return nil

	default:
		return fmt.Errorf("meddler.TimeMeddler.PostRead: unknown struct field type: %T", fieldAddr)
	}
}
322766
func (sem *Sem) Post() error {
	ret := int(C.SDL_SemPost(sem.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
958654
func Post(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error) {
	request, err := PostRequest(baseURL, object)
	if err != nil {
		return nil, nil, err
	}

	return Do(request, jsh.ObjectMode)
}
353416
func (r *Reader) PostingsRanges() (map[labels.Label]Range, error) {
	m := map[labels.Label]Range{}

	for k, e := range r.postings {
		for v, start := range e {
			d := encoding.NewDecbufAt(r.b, int(start), castagnoliTable)
			if d.Err() != nil {
				return nil, d.Err()
			}
			m[labels.Label{Name: k, Value: v}] = Range{
				Start: int64(start) + 4,
				End:   int64(start) + 4 + int64(d.Len()),
			}
		}
	}
	return m, nil
}
596888
func (mc MongoClient) ValueDescriptors() ([]contract.ValueDescriptor, error) {
	return mapValueDescriptors(mc.getValueDescriptors(nil))
}
744759
func (c *Client) Post(ctx context.Context, url string, bodyType string, body io.Reader) error {
	resp, err := c.post(ctx, url, bodyType, body)
	if err != nil {
		return err
	}
	return resp.Body.Close()
}