xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / api / sse.h

808 bytes
1// Internal SSE line splitter shared by the streaming API adapters.
2//
3// Every adapter consumes server-sent events where each event carries a single
4// `data:` line of JSON. This splits a byte stream into those payloads.
5
6#ifndef TINY_API_SSE_H
7#define TINY_API_SSE_H
8
9#include <stddef.h>
10
11// Called once per `data:` payload, with the prefix and trailing newline removed.
12// `[DONE]` sentinels and empty payloads are not delivered. The pointer is valid
13// only for the call.
14typedef void (*tiny_sse_fn)(const char *data, size_t len, void *user);
15
16typedef struct {
17    char *pending;
18    size_t pending_len;
19    size_t pending_cap;
20} tiny_sse;
21
22void tiny_sse_init(tiny_sse *s);
23void tiny_sse_free(tiny_sse *s);
24void tiny_sse_feed(tiny_sse *s, const char *data, size_t n, tiny_sse_fn fn, void *user);
25
26#endif