// DecodeGCSObjectToBQJobReq decodes a GCSObjectToBQJobReq from r.
772128
func DecodeGCSObjectToBQJobReq(r io.Reader) (*GCSObjectToBQJobReq, error) {
	decoder := json.NewDecoder(r)
	var req *GCSObjectToBQJobReq
	err := decoder.Decode(&req)
	if err != nil {
		return nil, err
	}
	return req, nil
}
1235797
func decodeDBPointer(rd *bufio.Reader) (string, DBPointer, error) {
	// name
	name, err := readCstring(rd)
	if err != nil {
		return "", DBPointer{}, err
	}

	// value
	Name, err := readString(rd)
	if err != nil {
		return "", DBPointer{}, err
	}
	b := make([]byte, 12)
	_, err = io.ReadFull(rd, b)
	if err != nil {
		return "", DBPointer{}, err
	}
	return name, DBPointer{Name: Name, ObjectId: ObjectId(b)}, nil
}
533461
func (service *GCSService) DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error {
	names, err := service.FilterObjects(ctx, params)
	if err != nil {
		return err
	}

	var objectParams GCSObjectParams
	for _, name := range names {
		objectParams = GCSObjectParams{
			Bucket: params.Bucket,
			ID:     name,
		}

		err := service.DeleteObject(ctx, objectParams)
		if err != nil {
			return err
		}
	}

	return nil
}
1143854
func (service *GCSService) GetObjectAttrs(ctx context.Context, params GCSObjectParams) (*storage.ObjectAttrs, error) {
	obj := service.Client.Bucket(params.Bucket).Object(params.ID)

	attrs, err := obj.Attrs(ctx)
	if err != nil {
		return nil, err
	}

	return attrs, nil

}
916060
func (t *TextMatch) GetObjectType() string {
	if t == nil || t.ObjectType == nil {
		return ""
	}
	return *t.ObjectType
}
296682
func (service *GCSService) compose(ctx context.Context, bucket string, srcs []string, dst string) error {
	dstParams := GCSObjectParams{
		Bucket: bucket,
		ID:     dst,
	}
	objSrcs := make([]*storage.ObjectHandle, len(srcs))
	var crc uint32
	for i := 0; i < len(srcs); i++ {
		objSrcs[i] = service.Client.Bucket(bucket).Object(srcs[i])
		srcAttrs, err := service.GetObjectAttrs(ctx, GCSObjectParams{
			Bucket: bucket,
			ID:     srcs[i],
		})
		if err != nil {
			return err
		}

		if i == 0 {
			crc = srcAttrs.CRC32C
		} else {
			crc = crc32combine.CRC32Combine(crc32.Castagnoli, crc, srcAttrs.CRC32C, srcAttrs.Size)
		}
	}

	attrs, err := service.GetObjectAttrs(ctx, GCSObjectParams{
		Bucket: bucket,
		ID:     srcs[0],
	})
	if err != nil {
		return err
	}

	for i := 0; i < COMPOSE_RETRIES; i++ {
		dstCRC, err := service.ComposeFrom(ctx, objSrcs, dstParams, attrs.ContentType)
		if err != nil {
			return err
		}

		if dstCRC == crc {
			return nil
		}
	}

	err = service.DeleteObject(ctx, GCSObjectParams{
		Bucket: bucket,
		ID:     dst,
	})

	if err != nil {
		return err
	}

	err = errors.New("GCS compose failed: Mismatch of CRC32 checksums")
	return err
}
1005953
func (service *GCSService) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error) {
	attrs, err := service.GetObjectAttrs(ctx, params)
	if err != nil {
		return 0, err
	}

	return attrs.Size, nil
}
646238
func (b *bucket) CopyObject(
	ctx context.Context,
	req *gcs.CopyObjectRequest) (o *gcs.Object, err error) {
	b.mu.Lock()
	defer b.mu.Unlock()

	// Check that the destination name is legal.
	err = checkName(req.DstName)
	if err != nil {
		return
	}

	// Does the object exist?
	srcIndex := b.objects.find(req.SrcName)
	if srcIndex == len(b.objects) {
		err = &gcs.NotFoundError{
			Err: fmt.Errorf("Object %q not found", req.SrcName),
		}

		return
	}

	// Does it have the correct generation?
	if req.SrcGeneration != 0 &&
		b.objects[srcIndex].metadata.Generation != req.SrcGeneration {
		err = &gcs.NotFoundError{
			Err: fmt.Errorf(
				"Object %s generation %d not found", req.SrcName, req.SrcGeneration),
		}

		return
	}

	// Does it have the correct meta-generation?
	if req.SrcMetaGenerationPrecondition != nil {
		p := *req.SrcMetaGenerationPrecondition
		if b.objects[srcIndex].metadata.MetaGeneration != p {
			err = &gcs.PreconditionError{
				Err: fmt.Errorf(
					"Object %q has meta-generation %d",
					req.SrcName,
					b.objects[srcIndex].metadata.MetaGeneration),
			}

			return
		}
	}

	// Copy it and assign a new generation number, to ensure that the generation
	// number for the destination name is strictly increasing.
	dst := b.objects[srcIndex]
	dst.metadata.Name = req.DstName
	dst.metadata.MediaLink = "http://localhost/download/storage/fake/" + req.DstName

	b.prevGeneration++
	dst.metadata.Generation = b.prevGeneration

	// Insert into our array.
	existingIndex := b.objects.find(req.DstName)
	if existingIndex < len(b.objects) {
		b.objects[existingIndex] = dst
	} else {
		b.objects = append(b.objects, dst)
		sort.Sort(b.objects)
	}

	o = &dst.metadata
	return
}
185842
func (c CloudstackClient) QueryAsyncJobResult(jobid string) (QueryAsyncJobResultResponse, error) {
	var resp QueryAsyncJobResultResponse

	params := url.Values{}
	params.Set("jobid", jobid)
	response, err := NewRequest(c, "queryAsyncJobResult", params)

	if err != nil {
		return resp, err
	}

	resp = response.(QueryAsyncJobResultResponse)

	return resp, nil
}
1358842
func (j *JsonHelper) GobDecode(data []byte) error {
	var mv map[string]interface{}
	if err := json.Unmarshal(data, &mv); err != nil {
		return err
	}
	*j = JsonHelper(mv)
	return nil
}
1271775
func DecodeGCELabel(s string) (string, error) {
	uriForm := strings.Replace(s, "-", "%", -1)
	v, err := url.QueryUnescape(uriForm)
	if err != nil {
		return "", fmt.Errorf("Cannot decode GCE label: %q", s)
	}
	return v, nil
}
734745
func DecodeBytesDesc(b []byte, buf []byte) ([]byte, []byte, error) {
	return decodeBytes(b, buf, true)
}
1289955
func (l *gcsGateway) DeleteObject(ctx context.Context, bucket string, object string) error {
	err := l.client.Bucket(bucket).Object(object).Delete(ctx)
	if err != nil {
		logger.LogIf(ctx, err)
		return gcsToObjectError(err, bucket, object)
	}

	return nil
}
941557
func GetObject(gc *storage.Client, bucket, name string) (*bytes.Buffer, error) {

	rc, err := gc.Bucket(bucket).Object(name).NewReader(context.Background())
	if err != nil {
		if err == storage.ErrObjectNotExist {
			return nil, cloudstorage.ErrObjectNotFound
		}
		return nil, err
	}
	by, err := ioutil.ReadAll(rc)
	if err != nil {
		return nil, err
	}
	return bytes.NewBuffer(by), nil
}
387707
func (ctx *Context) DecodeGQL() (*GQLRequest, error) {
	r := &GQLRequest{}

	if string(ctx.Method()) == GET {
		query := ctx.GETParam("query")
		if len(query) == 0 {
			return nil, ErrInvalidGQLRequest
		}
		r.Query = query[0]

		if operationName := ctx.GETParam("operationName"); len(operationName) != 0 {
			r.OperationName = operationName[0]
		}

		if variables := ctx.GETParam("variables"); len(variables) != 0 {
			if _, err := ctx.UnJSONBytes([]byte(variables[0]), &r.Variables); err != nil {
				return nil, ErrInvalidGQLRequest
			}
		}

		return r, nil
	}

	ctSplitParams := strings.Split(ctx.ContentType(), delimiterCTParams)

	switch ctSplitParams[0] {
	case jsonCTshort:
		if err := ctx.UnJSON(&r); err != nil {
			return nil, err
		}
	case gqlCT:
		r.Query = string(ctx.PostBody())
	}

	return r, nil
}
151591
func (c *Client) GetGCS(i *GetGCSInput) (*GCS, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	if i.Name == "" {
		return nil, ErrMissingName
	}

	path := fmt.Sprintf("/service/%s/version/%d/logging/gcs/%s", i.Service, i.Version, i.Name)
	resp, err := c.Get(path, nil)
	if err != nil {
		return nil, err
	}

	var b *GCS
	if err := decodeJSON(&b, resp.Body); err != nil {
		return nil, err
	}
	return b, nil
}
779734
func (d *Decoder) decodeScalefactors3(gr, ch int) error {
	var err error
	s1 := slen1[d.scalefacCompress[gr][ch]]
	s2 := slen2[d.scalefacCompress[gr][ch]]

	if d.blockType[gr][ch] == 2 {
		shortLow := 0
		if d.mixedBlockFlag[gr][ch] == 1 {
			d.part2Length[gr][ch] = 17*s1 + 18*s2
			for sfb := 0; sfb < 8; sfb++ {
				d.scalefacL[gr][ch][sfb], err = d.reservoir.readBits(s1)
				if err != nil {
					return err
				}
			}
			shortLow = 3
		} else {
			d.part2Length[gr][ch] = 18*s1 + 18*s2
		}

		for sfb := shortLow; sfb < 12; sfb++ {
			s := s1
			if sfb >= 6 {
				s = s2
			}
			for w := 0; w < 3; w++ {
				d.scalefacS[gr][ch][sfb][w], err = d.reservoir.readBits(s)
				if err != nil {
					return err
				}
			}
		}
	} else {
		d.part2Length[gr][ch] = 11*s1 + 10*s2
		for scfsiBand := 0; scfsiBand < 4; scfsiBand++ {
			low, high := scfsiBands[scfsiBand], scfsiBands[scfsiBand+1]
			s := s1
			if scfsiBand >= 2 {
				s = s2
			}
			for sfb := low; sfb < high; sfb++ {
				if gr == 0 || d.scfsi3[ch][scfsiBand] == 0 {
					d.scalefacL[gr][ch][sfb], err = d.reservoir.readBits(s)
					if err != nil {
						return err
					}
				} else {
					d.scalefacL[1][ch][sfb] = d.scalefacL[0][ch][sfb]
					d.part2Length[gr][ch] -= s
				}
			}
		}
	}

	return nil
}