Esempio n. 1
0
/*
   W is width of image in PIXELS.
   SRC is in packed pixel format.
   DEST is filled with 1 BYTE per PIXEL.
*/
unsigned char *
decode_line (unsigned char *dest, unsigned char *src, int w)
{
  unsigned int w8;
  unsigned int bpp;
  unsigned char b[4];
  int i;
  unsigned char *p;

  p = src;
  w8 = up8( w );

  /* 4 planes, bpp BYTES per plane */
  /* Planes are MSB -> LSB */
  bpp = w8 >> 3;

  while( w > 0 )
	{
	  for( i=0; i<4; ++i )
		b[i] = p[i*bpp];

	  if ( w > 8 )
		dest = decode_byte( dest, b, 8 );
	  else
		dest = decode_byte( dest, b, w );

	  w -= 8;
	  ++p;
	}

  return (src + bpp * 4);
}
Esempio n. 2
0
MINDY_INLINE static int decode_int4(struct thread *thread)
{
    int byte1 = decode_byte(thread);
    int byte2 = decode_byte(thread);
    int byte3 = decode_byte(thread);
    int byte4 = decode_byte(thread);

    return byte1 | (byte2 << 8) | (byte3 << 16) | (byte4 << 24);
}
Esempio n. 3
0
bool ErrorResponse::decode(int version, char* buffer, size_t size) {
  char* pos = decode_int32(buffer, code_);
  pos = decode_string(pos, &message_);

  switch (code_) {
    case CQL_ERROR_UNAVAILABLE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, required_);
      decode_int32(pos, received_);
      break;
    case CQL_ERROR_READ_TIMEOUT:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      decode_byte(pos, data_present_);
      break;
    case CQL_ERROR_WRITE_TIMEOUT:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      decode_write_type(pos);
      break;
    case CQL_ERROR_READ_FAILURE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      pos = decode_int32(pos, num_failures_);
      decode_byte(pos, data_present_);
      break;
    case CQL_ERROR_FUNCTION_FAILURE:
      pos = decode_string(pos, &keyspace_);
      pos = decode_string(pos, &function_);
      decode_stringlist(pos, arg_types_);
      break;
    case CQL_ERROR_WRITE_FAILURE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      pos = decode_int32(pos, num_failures_);
      decode_write_type(pos);
      break;
    case CQL_ERROR_UNPREPARED:
      decode_string(pos, &prepared_id_);
      break;
    case CQL_ERROR_ALREADY_EXISTS:
      pos = decode_string(pos, &keyspace_);
      pos = decode_string(pos, &table_);
      break;
  }
  return true;
}
Esempio n. 4
0
void interpret_next_byte(struct thread *thread)
{
    int timer = OPS_PER_TIME_SLICE;

    while (timer-- > 0)
        interpret_byte(decode_byte(thread), thread);
}
Esempio n. 5
0
bool CInputTeen::ProcessMain(LPDESC lpDesc, const void * c_pvOrig, size_t uiBytes, int & r_iBytesProceed)
{
	const char	*c_pData = (const char*) c_pvOrig;
	const size_t header_size = sizeof(BYTE) + sizeof(WORD);

	if (uiBytes < header_size)
		return false;

	for (m_iBufferLeft = uiBytes; m_iBufferLeft > 0;)
	{
		BYTE header		= decode_byte(c_pData);
		WORD desc_num	= decode_2bytes(c_pData+sizeof(BYTE));
		char *body		= (char*) c_pData + header_size;

		int packet_len	= __packet_len(header);

		if (m_iBufferLeft < packet_len)
			return true;

		c_pData			+= packet_len;
		m_iBufferLeft	-= packet_len;
		r_iBytesProceed	+= packet_len;

		__input_teen(header, desc_num, body);
	}	

	return true;
}
Esempio n. 6
0
void print_string(unsigned char data[]) {
    int r = 0, tr = 0, ind = 2;
    int len = data[0] - 2;
    const char *str = NULL;

    while (len > 0) {
        if (ind == 8) {
            r = hid_read(dev, data, 8);
            if (r < 0) {
                fatal("error reading data (%ls)", hid_error(dev));
            }
            if (tr != 8) {
                fatal("expected 8 bytes, received: %d", tr);
            }
            ind = 0;
        }
        str = decode_byte(data[ind]);
        if (strlen(str) > 1) {
            printf("<%s>", str);
        } else {
            printf("%s", str);
        }
        len--;
        ind++;
    }
}
Esempio n. 7
0
void print_key(unsigned char data[]) {
    char combo[128] = {0};
    if ((data[2] & CTRL) != 0) {
        strcat(combo, "ctrl+");
    }
    if ((data[2] & SHIFT) != 0) {
        strcat(combo, "shift+");
    }
    if ((data[2] & ALT) != 0) {
        strcat(combo, "alt+");
    }
    if ((data[2] & WIN) != 0) {
        strcat(combo, "win+");
    }
    if (data[3] != 0) {
        const char *key = decode_byte(data[3]);
        strcat(combo, key);
    } else {
        size_t len = strlen(combo);
        if (len > 0) {
            combo[len - 1] = 0; // remove the last +
        }
    }
    printf("%s", combo);
}
Esempio n. 8
0
MINDY_INLINE static int decode_arg(struct thread *thread)
{
    int arg = decode_byte(thread);

    if (arg == 0xff)
        return decode_int4(thread);
    else
        return arg;
}
Esempio n. 9
0
bool Nunchuk::update() {
  delay(1);
  Wire.requestFrom(NUNCHUK_DEVICE_ID, NUNCHUK_BUFFER_SIZE);
  int byte_counter = 0;
  while (Wire.available() && byte_counter < NUNCHUK_BUFFER_SIZE)
    _buffer[byte_counter++] = decode_byte(Wire.read());
  request_data();
  return byte_counter == NUNCHUK_BUFFER_SIZE;
}
Esempio n. 10
0
static char*
decode_string_value (guint8 *buf, guint8 **endbuf, guint8 *limit)
{
	int type;
    gint32 length;
	guint8 *p = buf;
	char *s;

	type = decode_byte (p, &p, limit);
	if (type == PRIM_TYPE_NULL) {
		*endbuf = p;
		return NULL;
	}
	g_assert (type == PRIM_TYPE_STRING);

	length = 0;
	while (TRUE) {
		guint8 b = decode_byte (p, &p, limit);
		
		length <<= 8;
		length += b;
		if (b <= 0x7f)
			break;
	}

	g_assert (length < (1 << 16));

	s = (char *)g_malloc (length + 1);

	g_assert (p + length <= limit);
	memcpy (s, p, length);
	s [length] = '\0';
	p += length;

	*endbuf = p;

	return s;
}
Esempio n. 11
0
MemberKey decode_member_key(PC& pc, Either<const Unit*, const UnitEmitter*> u) {
  auto const mcode = static_cast<MemberCode>(decode_byte(pc));

  switch (mcode) {
    case MEC: case MEL: case MPC: case MPL:
      return MemberKey{mcode, decode_iva(pc)};

    case MEI:
      return MemberKey{mcode, decode_raw<int64_t>(pc)};

    case MET: case MPT: case MQT: {
      auto const id = decode_raw<Id>(pc);
      auto const str = u.match(
        [id](const Unit* u) { return u->lookupLitstrId(id); },
        [id](const UnitEmitter* ue) { return ue->lookupLitstr(id); }
      );
      return MemberKey{mcode, str};
    }

    case MW:
      return MemberKey{};
  }
  not_reached();
}
Esempio n. 12
0
bool Value::as_bool() const {
  assert(!is_null() && value_type() == CASS_VALUE_TYPE_BOOLEAN);
  uint8_t value;
  decode_byte(data_, value);
  return value != 0;
}
Esempio n. 13
0
static void op_push_byte(int byte, struct thread *thread)
{
    signed char value = decode_byte(thread);
    *thread->sp++ = make_fixnum(value);
}
Esempio n. 14
0
void BlinkerMac::recv(const uint8_t c)
{
    digitalWrite(13, blink());

    // if you haven't gotten a byte in a while, then what you have
    // is probably garbage.
    if (packet_in_progress && stalled()) {
        debug("aborting rcv");
        IRFrame::hexdump(buf);
        reset();
        return;
    }
    if (!packet_in_progress) {
        packet_in_progress = prefix_hit(c);
        last_rx_time = millis();
        return; //the next byte should be the first byte of a packet
    }

    debugstart("%d", buf_pos);
    debugcont(" ");
    //geting a packet
    uint8_t input;
    if (decode_byte(c, input)) {
        buf->blob()[buf_pos] = input;
        buf_pos++;
    } else {
        return; // was a stuffed byte
    }

    if (buf_pos >= sizeof(IRFrame)) {
        //whole packet recieved!
        buf_pos = 0;
        packet_in_progress = false;

        if (buf->valid()) {
            buf->ntoh();

            if (buf->source == address) {
                // don't relay our own packets
                debugend();
                reset();
                return;
            }

            if (buf->destination != address) {
                if (buf->hops < MAX_HOPS) {
                    auto newbuf = FrameFactory.alloc();
                    IRFrame::copy(newbuf, buf);
                    eventManager.queueEvent(PacketNeedsRelayEvent, (int)newbuf);
                    debugend();
                    reset();
                    return;
                } else {
                    debugcont("too many hops.. eating");
                    debugend();
                    reset();
                    return;
                }
            }

            auto newbuf = FrameFactory.alloc();
            IRFrame::copy(newbuf, buf);
            eventManager.queueEvent(ValidFrameRecievedEvent, (int)newbuf);
            debugend();
            reset();
            return;
        } else {
            auto newbuf = FrameFactory.alloc();
            IRFrame::copy(newbuf, buf);
            eventManager.queueEvent(InvalidFrameRecievedEvent, (int)newbuf);
            debugend();
            reset();
        }
    }
    return;
}