Skip to content

Commit

Permalink
seek peek
Browse files Browse the repository at this point in the history
  • Loading branch information
bbSnavy committed Jan 26, 2025
1 parent 977751d commit 163b368
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ t_ion_result_code ion_buffer_seek_write(t_ion_buffer *self, size_t curr) {
return vector_seek_write(self->body, curr);
}

t_ion_result_code ion_buffer_seek_peek(t_ion_buffer *self, size_t curr) {
if (self == NULL)
return RESULT_ERROR;

return vector_seek_peek(self->body, curr);
}

t_ion_result_code ion_buffer_write(t_ion_buffer *self, void *src, size_t len) {
if (self == NULL)
return RESULT_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/ion.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ t_ion_vector *vector_new(size_t unit);
t_ion_vector *vector_clone(t_ion_vector *self);
t_ion_result_code vector_seek_read(t_ion_vector *self, size_t index);
t_ion_result_code vector_seek_write(t_ion_vector *self, size_t index);
t_ion_result_code vector_seek_peek(t_ion_vector *self, size_t index);
t_ion_result_code vector_seek_relative_read(t_ion_vector *self, int64_t diff);
t_ion_result_code vector_seek_relative_write(t_ion_vector *self, int64_t diff);
t_ion_result_code vector_seek_relative_peek(t_ion_vector *self, int64_t diff);
t_ion_result_code vector_extend(t_ion_vector *self);
t_ion_result_code vector_write(t_ion_vector *self, void *src, size_t len);
t_ion_result_code vector_read(t_ion_vector *self, void *dst, size_t len);
Expand All @@ -87,6 +89,7 @@ void ion_buffer_free(t_ion_buffer *self);
t_ion_buffer *ion_buffer_clone(t_ion_buffer *self);
t_ion_result_code ion_buffer_seek_read(t_ion_buffer *self, size_t curr);
t_ion_result_code ion_buffer_seek_write(t_ion_buffer *self, size_t curr);
t_ion_result_code ion_buffer_seek_peek(t_ion_buffer *self, size_t curr);
t_ion_result_code ion_buffer_write(t_ion_buffer *self, void *src, size_t len);
t_ion_result_code ion_buffer_read(t_ion_buffer *self, void *dst, size_t len);
t_ion_result_code ion_buffer_peek(t_ion_buffer *self, void *dst, size_t len);
Expand Down
22 changes: 22 additions & 0 deletions src/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ t_ion_result_code vector_seek_write(t_ion_vector *self, size_t index) {
return RESULT_OK;
}

t_ion_result_code vector_seek_peek(t_ion_vector *self, size_t index) {
if (self == NULL)
return RESULT_ERROR;

if (index < 0)
return RESULT_ERROR;

if (index >= self->size)
return RESULT_ERROR;

self->curr_p = index;

return RESULT_OK;
}

t_ion_result_code vector_seek_relative_read(t_ion_vector *self, int64_t diff) {
if (self == NULL)
return RESULT_ERROR;
Expand All @@ -79,6 +94,13 @@ t_ion_result_code vector_seek_relative_write(t_ion_vector *self, int64_t diff) {
return vector_seek_write(self, (size_t)((int64_t)self->curr_r + diff));
}

t_ion_result_code vector_seek_relative_peek(t_ion_vector *self, int64_t diff) {
if (self == NULL)
return RESULT_ERROR;

return vector_seek_peek(self, (size_t)((int64_t)self->curr_r + diff));
}

t_ion_result_code vector_extend(t_ion_vector *self) {
void *body;
size_t size;
Expand Down

0 comments on commit 163b368

Please sign in to comment.