shapito: implement so_bewrite_data_row()

This commit is contained in:
Dmitry Simonenko 2017-06-24 17:00:46 +03:00
parent 348351f7ae
commit b7285d13ed
2 changed files with 44 additions and 0 deletions

View File

@ -129,6 +129,10 @@ so_bewrite_no_data()
/* RowDescription */
so_bewrite_row_description()
so_bewrite_row_description_add()
/* DataRow */
so_bewrite_data_row()
so_bewrite_data_row_add()
```
**Read messages from Frontend**

View File

@ -198,6 +198,46 @@ so_bewrite_row_description_add(so_stream_t *buf, int start,
return 0;
}
static inline int
so_bewrite_data_row(so_stream_t *buf)
{
int rc = so_stream_ensure(buf, sizeof(so_header_t) + sizeof(uint16_t));
if (so_unlikely(rc == -1))
return -1;
int position = so_stream_used(buf);
so_stream_write8(buf, 'D');
so_stream_write32(buf, sizeof(uint32_t) + sizeof(uint16_t));
so_stream_write16(buf, 0);
return position;
}
static inline int
so_bewrite_data_row_add(so_stream_t *buf, int start, char *data, int32_t len)
{
int is_null = len == -1;
int size = sizeof(uint32_t) + (is_null) ? 0 : len;
int rc = so_stream_ensure(buf, size);
if (so_unlikely(rc == -1))
return -1;
so_stream_write32(buf, len);
if (! is_null)
so_stream_write(buf, (uint8_t*)data, len);
so_header_t *header;
header = (so_header_t*)(buf->s + start);
uint32_t pos_size = sizeof(uint32_t) + sizeof(uint16_t);
uint8_t *pos = (uint8_t*)&header->len;
uint32_t total_size;
uint16_t count;
so_stream_read32(&total_size, &pos, &pos_size);
so_stream_read16(&count, &pos, &pos_size);
total_size += size;
count++;
so_stream_write32to((uint8_t*)&header->len, total_size);
so_stream_write16to((uint8_t*)&header->len + sizeof(uint32_t), count);
return 0;
}
static inline int
so_bewrite_complete(so_stream_t *buf, char *message, int len)
{