-
Notifications
You must be signed in to change notification settings - Fork 87
/
libyrs.h
2752 lines (2450 loc) · 106 KB
/
libyrs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* The MIT License (MIT)
*
* Copyright (c) 2020
* - Bartosz Sypytkowski <[email protected]>
* - Kevin Jahns <[email protected]>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef YRS_FFI_H
#define YRS_FFI_H
/**
* A Yrs document type. Documents are most important units of collaborative resources management.
* All shared collections live within a scope of their corresponding documents. All updates are
* generated on per document basis (rather than individual shared type). All operations on shared
* collections happen via `YTransaction`, which lifetime is also bound to a document.
*
* Document manages so called root types, which are top-level shared types definitions (as opposed
* to recursively nested types).
*/
typedef struct YDoc {} YDoc;
/**
* A common shared data type. All Yrs instances can be refered to using this data type (use
* `ytype_kind` function if a specific type needs to be determined). Branch pointers are passed
* over type-specific functions like `ytext_insert`, `yarray_insert` or `ymap_insert` to perform
* a specific shared type operations.
*
* Using write methods of different shared types (eg. `ytext_insert` and `yarray_insert`) over
* the same branch may result in undefined behavior.
*/
typedef struct Branch {} Branch;
typedef struct Transaction {} Transaction;
typedef struct TransactionMut {} TransactionMut;
/**
* Iterator structure used by weak link unquote.
*/
typedef struct YWeakIter {} YWeakIter;
/**
* Iterator structure used by shared array data type.
*/
typedef struct YArrayIter {} YArrayIter;
/**
* Iterator structure used by shared map data type. Map iterators are unordered - there's no
* specific order in which map entries will be returned during consecutive iterator calls.
*/
typedef struct YMapIter {} YMapIter;
/**
* Iterator structure used by XML nodes (elements and text) to iterate over node's attributes.
* Attribute iterators are unordered - there's no specific order in which map entries will be
* returned during consecutive iterator calls.
*/
typedef struct YXmlAttrIter {} YXmlAttrIter;
/**
* Iterator used to traverse over the complex nested tree structure of a XML node. XML node
* iterator walks only over `YXmlElement` and `YXmlText` nodes. It does so in ordered manner (using
* the order in which children are ordered within their parent nodes) and using **depth-first**
* traverse.
*/
typedef struct YXmlTreeWalker {} YXmlTreeWalker;
typedef struct YUndoManager {} YUndoManager;
typedef struct LinkSource {} LinkSource;
typedef struct Unquote {} Unquote;
typedef struct StickyIndex {} StickyIndex;
typedef struct YSubscription {} YSubscription;
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
/**
* Flag used by `YInput` to pass JSON string for an object that should be deserialized and
* stored internally as fully fledged scalar type.
*/
#define Y_JSON -9
/**
* Flag used by `YInput` and `YOutput` to tag boolean values.
*/
#define Y_JSON_BOOL -8
/**
* Flag used by `YInput` and `YOutput` to tag floating point numbers.
*/
#define Y_JSON_NUM -7
/**
* Flag used by `YInput` and `YOutput` to tag 64-bit integer numbers.
*/
#define Y_JSON_INT -6
/**
* Flag used by `YInput` and `YOutput` to tag strings.
*/
#define Y_JSON_STR -5
/**
* Flag used by `YInput` and `YOutput` to tag binary content.
*/
#define Y_JSON_BUF -4
/**
* Flag used by `YInput` and `YOutput` to tag embedded JSON-like arrays of values,
* which themselves are `YInput` and `YOutput` instances respectively.
*/
#define Y_JSON_ARR -3
/**
* Flag used by `YInput` and `YOutput` to tag embedded JSON-like maps of key-value pairs,
* where keys are strings and v
*/
#define Y_JSON_MAP -2
/**
* Flag used by `YInput` and `YOutput` to tag JSON-like null values.
*/
#define Y_JSON_NULL -1
/**
* Flag used by `YInput` and `YOutput` to tag JSON-like undefined values.
*/
#define Y_JSON_UNDEF 0
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YArray` shared type.
*/
#define Y_ARRAY 1
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YMap` shared type.
*/
#define Y_MAP 2
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YText` shared type.
*/
#define Y_TEXT 3
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YXmlElement` shared type.
*/
#define Y_XML_ELEM 4
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YXmlText` shared type.
*/
#define Y_XML_TEXT 5
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YXmlFragment` shared type.
*/
#define Y_XML_FRAG 6
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YDoc` shared type.
*/
#define Y_DOC 7
/**
* Flag used by `YInput` and `YOutput` to tag content, which is an `YWeakLink` shared type.
*/
#define Y_WEAK_LINK 8
/**
* Flag used by `YOutput` to tag content, which is an undefined shared type. This usually happens
* when it's referencing a root type that has not been initalized localy.
*/
#define Y_UNDEFINED 9
/**
* Flag used to mark a truthy boolean numbers.
*/
#define Y_TRUE 1
/**
* Flag used to mark a falsy boolean numbers.
*/
#define Y_FALSE 0
/**
* Flag used by `YOptions` to determine, that text operations offsets and length will be counted by
* the byte number of UTF8-encoded string.
*/
#define Y_OFFSET_BYTES 0
/**
* Flag used by `YOptions` to determine, that text operations offsets and length will be counted by
* UTF-16 chars of encoded string.
*/
#define Y_OFFSET_UTF16 1
/**
* Error code: couldn't read data from input stream.
*/
#define ERR_CODE_IO 1
/**
* Error code: decoded variable integer outside of the expected integer size bounds.
*/
#define ERR_CODE_VAR_INT 2
/**
* Error code: end of stream found when more data was expected.
*/
#define ERR_CODE_EOS 3
/**
* Error code: decoded enum tag value was not among known cases.
*/
#define ERR_CODE_UNEXPECTED_VALUE 4
/**
* Error code: failure when trying to decode JSON content.
*/
#define ERR_CODE_INVALID_JSON 5
/**
* Error code: other error type than the one specified.
*/
#define ERR_CODE_OTHER 6
/**
* Error code: not enough memory to perform an operation.
*/
#define ERR_NOT_ENOUGH_MEMORY 7
/**
* Error code: conversion attempt to specific Rust type was not possible.
*/
#define ERR_TYPE_MISMATCH 8
/**
* Error code: miscellaneous error coming from serde, not covered by other error codes.
*/
#define ERR_CUSTOM 9
/**
* Error code: update block assigned to parent that is not a valid shared ref of deleted block.
*/
#define ERR_INVALID_PARENT 9
#define YCHANGE_ADD 1
#define YCHANGE_RETAIN 0
#define YCHANGE_REMOVE -1
#define Y_KIND_UNDO 0
#define Y_KIND_REDO 1
/**
* Tag used to identify `YPathSegment` storing a *char parameter.
*/
#define Y_EVENT_PATH_KEY 1
/**
* Tag used to identify `YPathSegment` storing an int parameter.
*/
#define Y_EVENT_PATH_INDEX 2
/**
* Tag used to identify `YEventChange` (see: `yevent_delta` function) case, when a new element
* has been added to an observed collection.
*/
#define Y_EVENT_CHANGE_ADD 1
/**
* Tag used to identify `YEventChange` (see: `yevent_delta` function) case, when an existing
* element has been removed from an observed collection.
*/
#define Y_EVENT_CHANGE_DELETE 2
/**
* Tag used to identify `YEventChange` (see: `yevent_delta` function) case, when no changes have
* been detected for a particular range of observed collection.
*/
#define Y_EVENT_CHANGE_RETAIN 3
/**
* Tag used to identify `YEventKeyChange` (see: `yevent_keys` function) case, when a new entry has
* been inserted into a map component of shared collection.
*/
#define Y_EVENT_KEY_CHANGE_ADD 4
/**
* Tag used to identify `YEventKeyChange` (see: `yevent_keys` function) case, when an existing
* entry has been removed from a map component of shared collection.
*/
#define Y_EVENT_KEY_CHANGE_DELETE 5
/**
* Tag used to identify `YEventKeyChange` (see: `yevent_keys` function) case, when an existing
* entry has been overridden with a new value within a map component of shared collection.
*/
#define Y_EVENT_KEY_CHANGE_UPDATE 6
typedef struct TransactionInner TransactionInner;
/**
* Configuration object used by `YDoc`.
*/
typedef struct YOptions {
/**
* Globally unique 53-bit integer assigned to corresponding document replica as its identifier.
*
* If two clients share the same `id` and will perform any updates, it will result in
* unrecoverable document state corruption. The same thing may happen if the client restored
* document state from snapshot, that didn't contain all of that clients updates that were sent
* to other peers.
*/
uint64_t id;
/**
* A NULL-able globally unique Uuid v4 compatible null-terminated string identifier
* of this document. If passed as NULL, a random Uuid will be generated instead.
*/
const char *guid;
/**
* A NULL-able, UTF-8 encoded, null-terminated string of a collection that this document
* belongs to. It's used only by providers.
*/
const char *collection_id;
/**
* Encoding used by text editing operations on this document. It's used to compute
* `YText`/`YXmlText` insertion offsets and text lengths. Either:
*
* - `Y_OFFSET_BYTES`
* - `Y_OFFSET_UTF16`
*/
uint8_t encoding;
/**
* Boolean flag used to determine if deleted blocks should be garbage collected or not
* during the transaction commits. Setting this value to 0 means GC will be performed.
*/
uint8_t skip_gc;
/**
* Boolean flag used to determine if subdocument should be loaded automatically.
* If this is a subdocument, remote peers will load the document as well automatically.
*/
uint8_t auto_load;
/**
* Boolean flag used to determine whether the document should be synced by the provider now.
*/
uint8_t should_load;
} YOptions;
/**
* A Yrs document type. Documents are the most important units of collaborative resources management.
* All shared collections live within a scope of their corresponding documents. All updates are
* generated on per-document basis (rather than individual shared type). All operations on shared
* collections happen via `YTransaction`, which lifetime is also bound to a document.
*
* Document manages so-called root types, which are top-level shared types definitions (as opposed
* to recursively nested types).
*/
typedef YDoc YDoc;
/**
* A common shared data type. All Yrs instances can be refered to using this data type (use
* `ytype_kind` function if a specific type needs to be determined). Branch pointers are passed
* over type-specific functions like `ytext_insert`, `yarray_insert` or `ymap_insert` to perform
* a specific shared type operations.
*
* Using write methods of different shared types (eg. `ytext_insert` and `yarray_insert`) over
* the same branch may result in undefined behavior.
*/
typedef Branch Branch;
typedef union YOutputContent {
uint8_t flag;
double num;
int64_t integer;
char *str;
const char *buf;
struct YOutput *array;
struct YMapEntry *map;
Branch *y_type;
YDoc *y_doc;
} YOutputContent;
/**
* An output value cell returned from yrs API methods. It describes a various types of data
* supported by yrs shared data types.
*
* Since `YOutput` instances are always created by calling the corresponding yrs API functions,
* they eventually should be deallocated using [youtput_destroy] function.
*/
typedef struct YOutput {
/**
* Tag describing, which `value` type is being stored by this input cell. Can be one of:
*
* - [Y_JSON_BOOL] for boolean flags.
* - [Y_JSON_NUM] for 64-bit floating point numbers.
* - [Y_JSON_INT] for 64-bit signed integers.
* - [Y_JSON_STR] for null-terminated UTF-8 encoded strings.
* - [Y_JSON_BUF] for embedded binary data.
* - [Y_JSON_ARR] for arrays of JSON-like values.
* - [Y_JSON_MAP] for JSON-like objects build from key-value pairs.
* - [Y_JSON_NULL] for JSON-like null values.
* - [Y_JSON_UNDEF] for JSON-like undefined values.
* - [Y_TEXT] for pointers to `YText` data types.
* - [Y_ARRAY] for pointers to `YArray` data types.
* - [Y_MAP] for pointers to `YMap` data types.
* - [Y_XML_ELEM] for pointers to `YXmlElement` data types.
* - [Y_XML_TEXT] for pointers to `YXmlText` data types.
* - [Y_DOC] for pointers to nested `YDocRef` data types.
*/
int8_t tag;
/**
* Length of the contents stored by a current `YOutput` cell.
*
* For [Y_JSON_NULL] and [Y_JSON_UNDEF] its equal to `0`.
*
* For [Y_JSON_ARR], [Y_JSON_MAP] it describes a number of passed elements.
*
* For other types it's always equal to `1`.
*/
uint32_t len;
/**
* Union struct which contains a content corresponding to a provided `tag` field.
*/
union YOutputContent value;
} YOutput;
/**
* A structure representing single key-value entry of a map output (used by either
* embedded JSON-like maps or YMaps).
*/
typedef struct YMapEntry {
/**
* Null-terminated string representing an entry's key component. Encoded as UTF-8.
*/
const char *key;
/**
* A `YOutput` value representing containing variadic content that can be stored withing map's
* entry.
*/
const struct YOutput *value;
} YMapEntry;
/**
* A structure representing single attribute of an either `YXmlElement` or `YXmlText` instance.
* It consists of attribute name and string, both of which are null-terminated UTF-8 strings.
*/
typedef struct YXmlAttr {
const char *name;
const char *value;
} YXmlAttr;
/**
* Subscription to any kind of observable events, like `ymap_observe`, `ydoc_observe_updates_v1` etc.
* This subscription can be destroyed by calling `yunobserve` function, which will cause to unsubscribe
* correlated callback.
*/
typedef YSubscription YSubscription;
/**
* Struct representing a state of a document. It contains the last seen clocks for blocks submitted
* per any of the clients collaborating on document updates.
*/
typedef struct YStateVector {
/**
* Number of clients. It describes a length of both `client_ids` and `clocks` arrays.
*/
uint32_t entries_count;
/**
* Array of unique client identifiers (length is given in `entries_count` field). Each client
* ID has corresponding clock attached, which can be found in `clocks` field under the same
* index.
*/
uint64_t *client_ids;
/**
* Array of clocks (length is given in `entries_count` field) known for each client. Each clock
* has a corresponding client identifier attached, which can be found in `client_ids` field
* under the same index.
*/
uint32_t *clocks;
} YStateVector;
typedef struct YIdRange {
uint32_t start;
uint32_t end;
} YIdRange;
/**
* Fixed-length sequence of ID ranges. Each range is a pair of [start, end) values, describing the
* range of items identified by clock values, that this range refers to.
*/
typedef struct YIdRangeSeq {
/**
* Number of ranges stored in this sequence.
*/
uint32_t len;
/**
* Array (length is stored in `len` field) or ranges. Each range is a pair of [start, end)
* values, describing continuous collection of items produced by the same client, identified
* by clock values, that this range refers to.
*/
struct YIdRange *seq;
} YIdRangeSeq;
/**
* Delete set is a map of `(ClientID, Range[])` entries. Length of a map is stored in
* `entries_count` field. ClientIDs reside under `client_ids` and their corresponding range
* sequences can be found under the same index of `ranges` field.
*/
typedef struct YDeleteSet {
/**
* Number of client identifier entries.
*/
uint32_t entries_count;
/**
* Array of unique client identifiers (length is given in `entries_count` field). Each client
* ID has corresponding sequence of ranges attached, which can be found in `ranges` field under
* the same index.
*/
uint64_t *client_ids;
/**
* Array of range sequences (length is given in `entries_count` field). Each sequence has
* a corresponding client ID attached, which can be found in `client_ids` field under
* the same index.
*/
struct YIdRangeSeq *ranges;
} YDeleteSet;
/**
* Event generated for callbacks subscribed using `ydoc_observe_after_transaction`. It contains
* snapshot of changes made within any committed transaction.
*/
typedef struct YAfterTransactionEvent {
/**
* Descriptor of a document state at the moment of creating the transaction.
*/
struct YStateVector before_state;
/**
* Descriptor of a document state at the moment of committing the transaction.
*/
struct YStateVector after_state;
/**
* Information about all items deleted within the scope of a transaction.
*/
struct YDeleteSet delete_set;
} YAfterTransactionEvent;
typedef struct YSubdocsEvent {
uint32_t added_len;
uint32_t removed_len;
uint32_t loaded_len;
YDoc **added;
YDoc **removed;
YDoc **loaded;
} YSubdocsEvent;
/**
* Transaction is one of the core types in Yrs. All operations that need to touch or
* modify a document's contents (a.k.a. block store), need to be executed in scope of a
* transaction.
*/
typedef struct TransactionInner YTransaction;
/**
* Structure containing unapplied update data.
* Created via `ytransaction_pending_update`.
* Released via `ypending_update_destroy`.
*/
typedef struct YPendingUpdate {
/**
* A state vector that informs about minimal client clock values that need to be satisfied
* in order to successfully apply current update.
*/
struct YStateVector missing;
/**
* Update data stored in lib0 v1 format.
*/
char *update_v1;
/**
* Length of `update_v1` payload.
*/
uint32_t update_len;
} YPendingUpdate;
typedef struct YMapInputData {
char **keys;
struct YInput *values;
} YMapInputData;
typedef LinkSource Weak;
typedef union YInputContent {
uint8_t flag;
double num;
int64_t integer;
char *str;
char *buf;
struct YInput *values;
struct YMapInputData map;
YDoc *doc;
const Weak *weak;
} YInputContent;
/**
* A data structure that is used to pass input values of various types supported by Yrs into a
* shared document store.
*
* `YInput` constructor function don't allocate any resources on their own, neither they take
* ownership by pointers to memory blocks allocated by user - for this reason once an input cell
* has been used, its content should be freed by the caller.
*/
typedef struct YInput {
/**
* Tag describing, which `value` type is being stored by this input cell. Can be one of:
*
* - [Y_JSON] for a UTF-8 encoded, NULL-terminated JSON string.
* - [Y_JSON_BOOL] for boolean flags.
* - [Y_JSON_NUM] for 64-bit floating point numbers.
* - [Y_JSON_INT] for 64-bit signed integers.
* - [Y_JSON_STR] for null-terminated UTF-8 encoded strings.
* - [Y_JSON_BUF] for embedded binary data.
* - [Y_JSON_ARR] for arrays of JSON-like values.
* - [Y_JSON_MAP] for JSON-like objects build from key-value pairs.
* - [Y_JSON_NULL] for JSON-like null values.
* - [Y_JSON_UNDEF] for JSON-like undefined values.
* - [Y_ARRAY] for cells which contents should be used to initialize a `YArray` shared type.
* - [Y_MAP] for cells which contents should be used to initialize a `YMap` shared type.
* - [Y_DOC] for cells which contents should be used to nest a `YDoc` sub-document.
* - [Y_WEAK_LINK] for cells which contents should be used to nest a `YWeakLink` sub-document.
*/
int8_t tag;
/**
* Length of the contents stored by current `YInput` cell.
*
* For [Y_JSON_NULL] and [Y_JSON_UNDEF] its equal to `0`.
*
* For [Y_JSON_ARR], [Y_JSON_MAP], [Y_ARRAY] and [Y_MAP] it describes a number of passed
* elements.
*
* For other types it's always equal to `1`.
*/
uint32_t len;
/**
* Union struct which contains a content corresponding to a provided `tag` field.
*/
union YInputContent value;
} YInput;
/**
* A data type representing a single change to be performed in sequence of changes defined
* as parameter to a `ytext_insert_delta` function. A type of change can be detected using
* a `tag` field:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new characters added to a collection. In this case `insert`
* field contains a pointer to a list of newly inserted values, while `len` field informs about
* their count. Additionally `attributes_len` nad `attributes` carry information about optional
* formatting attributes applied to edited blocks.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this case
* `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of characters that have not been changed, counted from
* the previous element. `len` field informs about number of retained elements. Additionally
* `attributes_len` nad `attributes` carry information about optional formatting attributes applied
* to edited blocks.
*/
typedef struct YDeltaIn {
/**
* Tag field used to identify particular type of change made:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new elements added to a collection. In this case `values`
* field contains a pointer to a list of newly inserted values, while `len` field informs about
* their count.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this
* case `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of elements that have not been changed, counted
* from the previous element. `len` field informs about number of retained elements.
*/
uint8_t tag;
/**
* Number of element affected by current type of change. It can refer to a number of
* inserted `values`, number of deleted element or a number of retained (unchanged) values.
*/
uint32_t len;
/**
* A nullable pointer to a list of formatting attributes assigned to an edited area represented
* by this delta.
*/
const struct YInput *attributes;
/**
* Used in case when current change is of `Y_EVENT_CHANGE_ADD` type. Contains a list (of
* length stored in `len` field) of newly inserted values.
*/
const struct YInput *insert;
} YDeltaIn;
/**
* A chunk of text contents formatted with the same set of attributes.
*/
typedef struct YChunk {
/**
* Piece of YText formatted using the same `fmt` rules. It can be a string, embedded object
* or another y-type.
*/
struct YOutput data;
/**
* Number of formatting attributes attached to current chunk of text.
*/
uint32_t fmt_len;
/**
* The formatting attributes attached to the current chunk of text.
*/
struct YMapEntry *fmt;
} YChunk;
/**
* Event pushed into callbacks registered with `ytext_observe` function. It contains delta of all
* text changes made within a scope of corresponding transaction (see: `ytext_event_delta`) as
* well as navigation data used to identify a `YText` instance which triggered this event.
*/
typedef struct YTextEvent {
const void *inner;
const TransactionMut *txn;
} YTextEvent;
/**
* Event pushed into callbacks registered with `ymap_observe` function. It contains all
* key-value changes made within a scope of corresponding transaction (see: `ymap_event_keys`) as
* well as navigation data used to identify a `YMap` instance which triggered this event.
*/
typedef struct YMapEvent {
const void *inner;
const TransactionMut *txn;
} YMapEvent;
/**
* Event pushed into callbacks registered with `yarray_observe` function. It contains delta of all
* content changes made within a scope of corresponding transaction (see: `yarray_event_delta`) as
* well as navigation data used to identify a `YArray` instance which triggered this event.
*/
typedef struct YArrayEvent {
const void *inner;
const TransactionMut *txn;
} YArrayEvent;
/**
* Event pushed into callbacks registered with `yxmlelem_observe` function. It contains
* all attribute changes made within a scope of corresponding transaction
* (see: `yxmlelem_event_keys`) as well as child XML nodes changes (see: `yxmlelem_event_delta`)
* and navigation data used to identify a `YXmlElement` instance which triggered this event.
*/
typedef struct YXmlEvent {
const void *inner;
const TransactionMut *txn;
} YXmlEvent;
/**
* Event pushed into callbacks registered with `yxmltext_observe` function. It contains
* all attribute changes made within a scope of corresponding transaction
* (see: `yxmltext_event_keys`) as well as text edits (see: `yxmltext_event_delta`)
* and navigation data used to identify a `YXmlText` instance which triggered this event.
*/
typedef struct YXmlTextEvent {
const void *inner;
const TransactionMut *txn;
} YXmlTextEvent;
/**
* Event pushed into callbacks registered with `yweak_observe` function. It contains
* all an event changes of the underlying transaction.
*/
typedef struct YWeakLinkEvent {
const void *inner;
const TransactionMut *txn;
} YWeakLinkEvent;
typedef union YEventContent {
struct YTextEvent text;
struct YMapEvent map;
struct YArrayEvent array;
struct YXmlEvent xml_elem;
struct YXmlTextEvent xml_text;
struct YWeakLinkEvent weak;
} YEventContent;
typedef struct YEvent {
/**
* Tag describing, which shared type emitted this event.
*
* - [Y_TEXT] for pointers to `YText` data types.
* - [Y_ARRAY] for pointers to `YArray` data types.
* - [Y_MAP] for pointers to `YMap` data types.
* - [Y_XML_ELEM] for pointers to `YXmlElement` data types.
* - [Y_XML_TEXT] for pointers to `YXmlText` data types.
*/
int8_t tag;
/**
* A nested event type, specific for a shared data type that triggered it. Type of an
* event can be verified using `tag` field.
*/
union YEventContent content;
} YEvent;
typedef union YPathSegmentCase {
const char *key;
uint32_t index;
} YPathSegmentCase;
/**
* A single segment of a path returned from `yevent_path` function. It can be one of two cases,
* recognized by it's `tag` field:
*
* 1. `Y_EVENT_PATH_KEY` means that segment value can be accessed by `segment.value.key` and is
* referring to a string key used by map component (eg. `YMap` entry).
* 2. `Y_EVENT_PATH_INDEX` means that segment value can be accessed by `segment.value.index` and is
* referring to an int index used by sequence component (eg. `YArray` item or `YXmlElement` child).
*/
typedef struct YPathSegment {
/**
* Tag used to identify which case current segment is referring to:
*
* 1. `Y_EVENT_PATH_KEY` means that segment value can be accessed by `segment.value.key` and is
* referring to a string key used by map component (eg. `YMap` entry).
* 2. `Y_EVENT_PATH_INDEX` means that segment value can be accessed by `segment.value.index`
* and is referring to an int index used by sequence component (eg. `YArray` item or
* `YXmlElement` child).
*/
char tag;
/**
* Union field containing either `key` or `index`. A particular case can be recognized by using
* segment's `tag` field.
*/
union YPathSegmentCase value;
} YPathSegment;
/**
* A single instance of formatting attribute stored as part of `YDelta` instance.
*/
typedef struct YDeltaAttr {
/**
* A null-terminated UTF-8 encoded string containing a unique formatting attribute name.
*/
const char *key;
/**
* A value assigned to a formatting attribute.
*/
struct YOutput value;
} YDeltaAttr;
/**
* A data type representing a single change detected over an observed `YText`/`YXmlText`. A type
* of change can be detected using a `tag` field:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new characters added to a collection. In this case `insert`
* field contains a pointer to a list of newly inserted values, while `len` field informs about
* their count. Additionally `attributes_len` nad `attributes` carry information about optional
* formatting attributes applied to edited blocks.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this case
* `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of characters that have not been changed, counted from
* the previous element. `len` field informs about number of retained elements. Additionally
* `attributes_len` nad `attributes` carry information about optional formatting attributes applied
* to edited blocks.
*
* A list of changes returned by `ytext_event_delta`/`yxmltext_event_delta` enables to locate
* a position of all changes within an observed collection by using a combination of added/deleted
* change structs separated by retained changes (marking eg. number of elements that can be safely
* skipped, since they remained unchanged).
*/
typedef struct YDeltaOut {
/**
* Tag field used to identify particular type of change made:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new elements added to a collection. In this case `values`
* field contains a pointer to a list of newly inserted values, while `len` field informs about
* their count.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this
* case `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of elements that have not been changed, counted
* from the previous element. `len` field informs about number of retained elements.
*/
uint8_t tag;
/**
* Number of element affected by current type of change. It can refer to a number of
* inserted `values`, number of deleted element or a number of retained (unchanged) values.
*/
uint32_t len;
/**
* A number of formatting attributes assigned to an edited area represented by this delta.
*/
uint32_t attributes_len;
/**
* A nullable pointer to a list of formatting attributes assigned to an edited area represented
* by this delta.
*/
struct YDeltaAttr *attributes;
/**
* Used in case when current change is of `Y_EVENT_CHANGE_ADD` type. Contains a list (of
* length stored in `len` field) of newly inserted values.
*/
struct YOutput *insert;
} YDeltaOut;
/**
* A data type representing a single change detected over an observed shared collection. A type
* of change can be detected using a `tag` field:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new elements added to a collection. In this case `values` field
* contains a pointer to a list of newly inserted values, while `len` field informs about their
* count.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this case
* `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of elements that have not been changed, counted from
* the previous element. `len` field informs about number of retained elements.
*
* A list of changes returned by `yarray_event_delta`/`yxml_event_delta` enables to locate a
* position of all changes within an observed collection by using a combination of added/deleted
* change structs separated by retained changes (marking eg. number of elements that can be safely
* skipped, since they remained unchanged).
*/
typedef struct YEventChange {
/**
* Tag field used to identify particular type of change made:
*
* 1. `Y_EVENT_CHANGE_ADD` marks a new elements added to a collection. In this case `values`
* field contains a pointer to a list of newly inserted values, while `len` field informs about
* their count.
* 2. `Y_EVENT_CHANGE_DELETE` marks an existing elements removed from the collection. In this
* case `len` field informs about number of removed elements.
* 3. `Y_EVENT_CHANGE_RETAIN` marks a number of elements that have not been changed, counted
* from the previous element. `len` field informs about number of retained elements.
*/
uint8_t tag;
/**
* Number of element affected by current type of a change. It can refer to a number of
* inserted `values`, number of deleted element or a number of retained (unchanged) values.
*/
uint32_t len;
/**
* Used in case when current change is of `Y_EVENT_CHANGE_ADD` type. Contains a list (of
* length stored in `len` field) of newly inserted values.
*/
const struct YOutput *values;
} YEventChange;
/**
* A data type representing a single change made over a map component of shared collection types,
* such as `YMap` entries or `YXmlText`/`YXmlElement` attributes. A `key` field provides a
* corresponding unique key string of a changed entry, while `tag` field informs about specific
* type of change being done:
*
* 1. `Y_EVENT_KEY_CHANGE_ADD` used to identify a newly added entry. In this case an `old_value`
* field is NULL, while `new_value` field contains an inserted value.
* 1. `Y_EVENT_KEY_CHANGE_DELETE` used to identify an existing entry being removed. In this case
* an `old_value` field contains the removed value.
* 1. `Y_EVENT_KEY_CHANGE_UPDATE` used to identify an existing entry, which value has been changed.
* In this case `old_value` field contains replaced value, while `new_value` contains a newly
* inserted one.
*/
typedef struct YEventKeyChange {
/**
* A UTF8-encoded null-terminated string containing a key of a changed entry.
*/
const char *key;
/**
* Tag field informing about type of change current struct refers to:
*
* 1. `Y_EVENT_KEY_CHANGE_ADD` used to identify a newly added entry. In this case an
* `old_value` field is NULL, while `new_value` field contains an inserted value.
* 1. `Y_EVENT_KEY_CHANGE_DELETE` used to identify an existing entry being removed. In this
* case an `old_value` field contains the removed value.
* 1. `Y_EVENT_KEY_CHANGE_UPDATE` used to identify an existing entry, which value has been
* changed. In this case `old_value` field contains replaced value, while `new_value` contains
* a newly inserted one.
*/
char tag;
/**
* Contains a removed entry's value or replaced value of an updated entry.