// GetFrameLogForDevice subscribes to the uplink and downlink frame logs
// for the given device and sends this to the given channel.
352985
func GetFrameLogForDevice(ctx context.Context, p *redis.Pool, devEUI lorawan.EUI64, frameLogChan chan FrameLog) error {
	uplinkKey := fmt.Sprintf(deviceFrameLogUplinkPubSubKeyTempl, devEUI)
	downlinkKey := fmt.Sprintf(deviceFrameLogDownlinkPubSubKeyTempl, devEUI)
	return getFrameLogs(ctx, p, uplinkKey, downlinkKey, frameLogChan)
}
1154318
func (w *Webcam) GetSupportedFrameSizes(f PixelFormat) []FrameSize {
	result := make([]FrameSize, 0)

	var index uint32
	var err error

	for index = 0; err == nil; index++ {
		s, err := getFrameSize(w.fd, index, uint32(f))

		if err != nil {
			break
		}

		result = append(result, s)
	}

	return result
}
955383
func frameFromBytes(buff []byte) (f linkFrame) {
  if buff[0] == 0x00 {
    pkts := buff[1]
    idx := 0
    for pkts > 0 {
      plen := binary.BigEndian.Uint16(buff[:2+idx])
      if 2 + int(plen) + idx < len(buff) {
        pkt := make([]byte, int(plen))
        copy(pkt, buff[idx+2:2+len(pkt)+idx])
        f = append(f, ipPacket(pkt))
        pkts--
        idx += len(pkt) + 2
      } else {
        return nil
      }
    }
  }
  return
}
413558
func (s *storageImpl) getLogEntriesIter(c context.Context, st *getStrategy, cb storage.GetCallback) error {
	// Get our maximum byte limit. If we are externally constrained via MaxBytes,
	// apply that limit too.
	// Get an archive reader.
	var (
		offset = st.startOffset
		length = st.length()
	)

	log.Fields{
		"offset": offset,
		"length": length,
		"path":   s.Stream,
	}.Debugf(c, "Creating stream reader for range.")
	storageReader, err := s.Client.NewReader(s.Stream, int64(offset), length)
	if err != nil {
		log.WithError(err).Errorf(c, "Failed to create stream Reader.")
		return errors.Annotate(err, "failed to create stream Reader").Err()
	}
	defer func() {
		if tmpErr := storageReader.Close(); tmpErr != nil {
			// (Non-fatal)
			log.WithError(tmpErr).Warningf(c, "Error closing stream Reader.")
		}
	}()

	// Count how many bytes we've read.
	cr := iotools.CountingReader{Reader: storageReader}

	// Iteratively update our strategy's start offset each time we read a complete
	// frame.
	var (
		rio       = recordio.NewReader(&cr, maxStreamRecordSize)
		buf       bytes.Buffer
		remaining = st.count
	)
	for {
		// Reset the count so we know how much we read for this frame.
		cr.Count = 0

		sz, r, err := rio.ReadFrame()
		if err != nil {
			return errors.Annotate(err, "failed to read frame").Err()
		}

		buf.Reset()
		buf.Grow(int(sz))

		switch amt, err := buf.ReadFrom(r); {
		case err != nil:
			log.Fields{
				log.ErrorKey:  err,
				"frameOffset": offset,
				"frameSize":   sz,
			}.Errorf(c, "Failed to read frame data.")
			return errors.Annotate(err, "failed to read frame data").Err()

		case amt != sz:
			// If we didn't buffer the complete frame, we hit a premature EOF.
			return errors.Annotate(io.EOF, "incomplete frame read").Err()
		}

		// If we read from offset 0, the first frame will be the log stream's
		// descriptor, which we can discard.
		discardFrame := (offset == 0)
		offset += uint64(cr.Count)
		if discardFrame {
			continue
		}

		// Punt this log entry to our callback, if appropriate.
		entry := storage.MakeEntry(buf.Bytes(), -1)
		switch idx, err := entry.GetStreamIndex(); {
		case err != nil:
			log.Fields{
				log.ErrorKey:  err,
				"frameOffset": offset,
				"frameSize":   sz,
			}.Errorf(c, "Failed to get log entry index.")
			return errors.Annotate(err, "failed to get log entry index").Err()

		case idx < st.startIndex:
			// Skip this entry, as it's before the first requested entry.
			continue
		}

		// We want to punt this entry, but we also want to re-use our Buffer. Clone
		// its data so it is independent.
		entry.D = make([]byte, len(entry.D))
		copy(entry.D, buf.Bytes())
		if !cb(entry) {
			return nil
		}

		// Enforce our limit, if one is supplied.
		if remaining > 0 {
			remaining--
			if remaining == 0 {
				return nil
			}
		}
	}
}
998483
func (c *Context) GetShaderInfoLog(shader *js.Object) string {
	return c.Call("getShaderInfoLog", shader).String()
}
191631
func LogUplinkFrameForGateways(p *redis.Pool, uplinkFrameSet gw.UplinkFrameSet) error {
	c := p.Get()
	defer c.Close()

	c.Send("MULTI")
	for _, rx := range uplinkFrameSet.RxInfo {
		var id lorawan.EUI64
		copy(id[:], rx.GatewayId)

		frameLog := gw.UplinkFrameSet{
			PhyPayload: uplinkFrameSet.PhyPayload,
			TxInfo:     uplinkFrameSet.TxInfo,
			RxInfo:     []*gw.UplinkRXInfo{rx},
		}

		b, err := proto.Marshal(&frameLog)
		if err != nil {
			return errors.Wrap(err, "marshal uplink frame-set error")
		}

		key := fmt.Sprintf(gatewayFrameLogUplinkPubSubKeyTempl, id)
		c.Send("PUBLISH", key, b)
	}
	_, err := c.Do("EXEC")
	if err != nil {
		return errors.Wrap(err, "publish frame to gateway channel error")
	}

	return nil
}
1127688
func (_m *DBClient) GetDevicesByServiceId(sid string) ([]models.Device, error) {
	ret := _m.Called(sid)

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

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

	return r0, r1
}
1313473
func SendFramedResponse(w io.Writer, frameType int32, data []byte) (int, error) {
	beBuf := make([]byte, 4)
	size := uint32(len(data)) + 4

	binary.BigEndian.PutUint32(beBuf, size)
	n, err := w.Write(beBuf)
	if err != nil {
		return n, err
	}

	binary.BigEndian.PutUint32(beBuf, uint32(frameType))
	n, err = w.Write(beBuf)
	if err != nil {
		return n + 4, err
	}

	n, err = w.Write(data)
	return n + 8, err
}
276175
func getLogrusLogger(ctx context.Context, keys ...interface{}) *logrus.Entry {
	var logger *logrus.Entry

	// Get a logger, if it is present.
	loggerInterface := ctx.Value(loggerKey{})
	if loggerInterface != nil {
		if lgr, ok := loggerInterface.(*logrus.Entry); ok {
			logger = lgr
		}
	}

	if logger == nil {
		fields := logrus.Fields{}

		// Fill in the instance id, if we have it.
		instanceID := ctx.Value("instance.id")
		if instanceID != nil {
			fields["instance.id"] = instanceID
		}

		fields["go.version"] = runtime.Version()
		// If no logger is found, just return the standard logger.
		logger = logrus.StandardLogger().WithFields(fields)
	}

	fields := logrus.Fields{}
	for _, key := range keys {
		v := ctx.Value(key)
		if v != nil {
			fields[fmt.Sprint(key)] = v
		}
	}

	return logger.WithFields(fields)
}
367837
func GetCapturedLogger() *log.Logger {
	r, w := io.Pipe()
	l := log.New(w, prefix, flags)
	go redirect(r)
	return l
}
433718
func TypeForDevice(device fs.BlockDevice) FATType {
	sizeInMB := device.Len() / (1024 * 1024)
	switch {
	case sizeInMB < 4:
		return FAT12
	case sizeInMB < 512:
		return FAT16
	default:
		return FAT32
	}
}
443149
func (d *domainClient) GetManifestForFrame(ctx context.Context, args *GetManifestForFrameArgs) (reply *GetManifestForFrameReply, err error) {
	reply = new(GetManifestForFrameReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "ApplicationCache.getManifestForFrame", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "ApplicationCache.getManifestForFrame", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "ApplicationCache", Op: "GetManifestForFrame", Err: err}
	}
	return
}
52831
func getEventByDeviceHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	vars := mux.Vars(r)
	limit := vars["limit"]
	ctx := r.Context()
	deviceId, err := url.QueryUnescape(vars["deviceId"])

	// Problems unescaping URL
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error unescaping URL: " + err.Error())
		return
	}

	// Convert limit to int
	limitNum, err := strconv.Atoi(limit)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error converting to integer: " + err.Error())
		return
	}

	// Check device
	if err := checkDevice(deviceId, ctx); err != nil {
		LoggingClient.Error(fmt.Sprintf("error checking device %s %v", deviceId, err))
		switch err := err.(type) {
		case *types.ErrServiceClient:
			http.Error(w, err.Error(), err.StatusCode)
			return
		default: //return an error on everything else.
			http.Error(w, err.Error(), http.StatusServiceUnavailable)
			return
		}
	}

	switch r.Method {
	case http.MethodGet:
		err := checkMaxLimit(limitNum)
		if err != nil {
			http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
			return
		}

		eventList, err := getEventsByDeviceIdLimit(limitNum, deviceId)

		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		encode(eventList, w)
	}
}
1099076
func (_class VIFMetricsClass) GetRecord(sessionID SessionRef, self VIFMetricsRef) (_retval VIFMetricsRecord, _err error) {
	_method := "VIF_metrics.get_record"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVIFMetricsRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVIFMetricsRecordToGo(_method + " -> ", _result.Value)
	return
}
608821
func (reader *PluginConfigReader) GetSubLogger(subScope string) logrus.FieldLogger {
	return reader.WithError.GetSubLogger(subScope)
}
1353312
func LogRecordNotifyToVerbose(n *LogRecordNotify) LogRecordNotifyVerbose {
	return LogRecordNotifyVerbose{
		Type:             "logRecord",
		ObservationPoint: n.ObservationPoint,
		FlowType:         n.Type,
		L7Proto:          n.l7Proto(),
		SrcEpID:          n.SourceEndpoint.ID,
		SrcEpLabels:      n.SourceEndpoint.Labels,
		SrcIdentity:      n.SourceEndpoint.Identity,
		DstEpID:          n.DestinationEndpoint.ID,
		DstEpLabels:      n.DestinationEndpoint.Labels,
		DstIdentity:      n.DestinationEndpoint.Identity,
		Verdict:          n.Verdict,
		HTTP:             n.HTTP,
		Kafka:            n.Kafka,
		DNS:              n.DNS,
		L7:               n.L7,
	}
}
368984
func (r Network_Subnet_IpAddress) GetSyslogEventsOneDay() (resp []datatypes.Network_Logging_Syslog, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Subnet_IpAddress", "getSyslogEventsOneDay", nil, &r.Options, &resp)
	return
}