move function around

This commit is contained in:
Nam Tran
2020-11-24 18:43:59 -06:00
parent 57443a5c26
commit 78fc7cb184

112
client.cc
View File

@@ -38,61 +38,6 @@ size_t process_block(char const * ptr, size_t len);
size_t process_block(char const * ptr, size_t len){ size_t process_block(char const * ptr, size_t len){
return len; return len;
} }
size_t process_channel(char const * ptr, size_t len){
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
spdlog::debug("channel length must be between {} and {}.",
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
return len;
}
size_t bytes_left = len;
bool valid_channel = false;
uint32_t * wordData = (uint32_t *)ptr;
while ((bytes_left > 0) && !valid_channel) {
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
spdlog::debug("bad_data, expecting {0:x}, received {0:x}",
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
bytes_left -= 4;
} else {
valid_channel = true;
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
spdlog::debug("Invalid channel size: {}", channel_size);
}
uint32_t version = wordData[0] && 0xFF;
spdlog::debug("channel size {}, version {}", channel_size, version);
int32_t integral[3];
for (int i = 0; i < 3; i++)
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
spdlog::debug("integrals: {}, {}, {}", integral[0], integral[1], integral[2]);
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
spdlog::debug("crossing_count {}, block_count {}, channel {}, spill_id {}",
crossing_count, block_count, channel, spill_id);
for (uint32_t i = 0; i < block_count; i++) {
process_block(ptr, channel_size); // not correct yet!
}
// the number of bytes consumed by this function, regardless of block
// processing
bytes_left -= channel_size;
Channel c(ptr, channel_size);
c.Print();
}
}
// return number of bytes cosumed of the channel
spdlog::debug("processed {} bytes out of {}", (len - bytes_left), len);
return len - bytes_left;
}
int main(int argc, char * argv[]) int main(int argc, char * argv[])
@@ -217,3 +162,60 @@ void setup_logger(){
exit(-1); exit(-1);
} }
} }
size_t process_channel(char const * ptr, size_t len){
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
spdlog::debug("channel length must be between {} and {}.",
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
return len;
}
size_t bytes_left = len;
bool valid_channel = false;
uint32_t * wordData = (uint32_t *)ptr;
while ((bytes_left > 0) && !valid_channel) {
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
spdlog::debug("bad_data, expecting {0:x}, received {0:x}",
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
bytes_left -= 4;
} else {
valid_channel = true;
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
spdlog::debug("Invalid channel size: {}", channel_size);
}
uint32_t version = wordData[0] && 0xFF;
spdlog::debug("channel size {}, version {}", channel_size, version);
int32_t integral[3];
for (int i = 0; i < 3; i++)
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
spdlog::debug("integrals: {}, {}, {}", integral[0], integral[1], integral[2]);
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
spdlog::debug("crossing_count {}, block_count {}, channel {}, spill_id {}",
crossing_count, block_count, channel, spill_id);
for (uint32_t i = 0; i < block_count; i++) {
process_block(ptr, channel_size); // not correct yet!
}
// the number of bytes consumed by this function, regardless of block
// processing
bytes_left -= channel_size;
Channel c(ptr, channel_size);
c.Print();
}
}
// return number of bytes cosumed of the channel
spdlog::debug("processed {} bytes out of {}", (len - bytes_left), len);
return len - bytes_left;
}