-
Notifications
You must be signed in to change notification settings - Fork 7
/
automerge.h
3357 lines (3167 loc) · 114 KB
/
automerge.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
#ifndef AUTOMERGE_C_H
#define AUTOMERGE_C_H
/**
* \file
* \brief All constants, functions and types in the core Automerge C API.
*
* \warning This file is auto-generated by cbindgen.
*/
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
/**
* \defgroup enumerations Public Enumerations
* Symbolic names for integer constants.
*/
/**
* \memberof AMdoc
* \def AM_ROOT
* \brief The root object of a document.
*/
#define AM_ROOT NULL
/**
* \memberof AMdoc
* \def AM_CHANGE_HASH_SIZE
* \brief The count of bytes in a change hash.
*/
#define AM_CHANGE_HASH_SIZE 32
/**
* \ingroup enumerations
* \enum AMidxType
* \installed_headerfile
* \brief The type of an item's index.
*/
enum AMidxType {
/**
* The default tag, not a type signifier.
*/
AM_IDX_TYPE_DEFAULT = 0,
/**
* A UTF-8 string view key.
*/
AM_IDX_TYPE_KEY,
/**
* A 64-bit unsigned integer position.
*/
AM_IDX_TYPE_POS,
};
typedef uint8_t AMidxType;
/**
* \ingroup enumerations
* \enum AMmarkExpand
* \installed_headerfile
* \brief A mark's expansion mode for when bordering text is inserted.
*/
enum AMmarkExpand {
/**
* Include text inserted at the end offset.
*/
AM_MARK_EXPAND_AFTER = 3,
/**
* Include text inserted at the start offset.
*/
AM_MARK_EXPAND_BEFORE = 2,
/**
* Include text inserted at either offset.
*/
AM_MARK_EXPAND_BOTH = 4,
/**
* The default tag, not a mark expansion mode signifier.
*/
AM_MARK_EXPAND_DEFAULT = 0,
/**
* Exclude text inserted at either offset.
*/
AM_MARK_EXPAND_NONE = 1,
};
typedef uint8_t AMmarkExpand;
/**
* \ingroup enumerations
* \enum AMobjType
* \installed_headerfile
* \brief The type of an object.
*/
enum AMobjType {
/**
* The default tag, not a type signifier.
*/
AM_OBJ_TYPE_DEFAULT = 0,
/**
* A list.
*/
AM_OBJ_TYPE_LIST = 1,
/**
* A key-value map.
*/
AM_OBJ_TYPE_MAP,
/**
* A list of Unicode graphemes.
*/
AM_OBJ_TYPE_TEXT,
};
typedef uint8_t AMobjType;
/**
* \ingroup enumerations
* \enum AMstatus
* \installed_headerfile
* \brief The status of an API call.
*/
enum AMstatus {
/**
* Success.
* \note This tag is unalphabetized so that `0` indicates success.
*/
AM_STATUS_OK,
/**
* Failure due to an error.
*/
AM_STATUS_ERROR,
/**
* Failure due to an invalid result.
*/
AM_STATUS_INVALID_RESULT,
};
typedef uint8_t AMstatus;
/**
* \ingroup enumerations
* \enum AMvalType
* \installed_headerfile
* \brief The type of an item's value.
*/
enum AMvalType {
/**
* An actor identifier value.
*/
AM_VAL_TYPE_ACTOR_ID = (1 << 1),
/**
* A boolean value.
*/
AM_VAL_TYPE_BOOL = (1 << 2),
/**
* A view onto an array of bytes value.
*/
AM_VAL_TYPE_BYTES = (1 << 3),
/**
* A change value.
*/
AM_VAL_TYPE_CHANGE = (1 << 4),
/**
* A change hash value.
*/
AM_VAL_TYPE_CHANGE_HASH = (1 << 5),
/**
* A CRDT counter value.
*/
AM_VAL_TYPE_COUNTER = (1 << 6),
/**
* The default tag, not a type signifier.
*/
AM_VAL_TYPE_DEFAULT = 0,
/**
* A document value.
*/
AM_VAL_TYPE_DOC = (1 << 7),
/**
* A 64-bit float value.
*/
AM_VAL_TYPE_F64 = (1 << 8),
/**
* A 64-bit signed integer value.
*/
AM_VAL_TYPE_INT = (1 << 9),
/**
* A mark.
*/
AM_VAL_TYPE_MARK = (1 << 10),
/**
* A null value.
*/
AM_VAL_TYPE_NULL = (1 << 11),
/**
* An object type value.
*/
AM_VAL_TYPE_OBJ_TYPE = (1 << 12),
/**
* A UTF-8 string view value.
*/
AM_VAL_TYPE_STR = (1 << 13),
/**
* A synchronization have value.
*/
AM_VAL_TYPE_SYNC_HAVE = (1 << 14),
/**
* A synchronization message value.
*/
AM_VAL_TYPE_SYNC_MESSAGE = (1 << 15),
/**
* A synchronization state value.
*/
AM_VAL_TYPE_SYNC_STATE = (1 << 16),
/**
* A *nix timestamp (milliseconds) value.
*/
AM_VAL_TYPE_TIMESTAMP = (1 << 17),
/**
* A 64-bit unsigned integer value.
*/
AM_VAL_TYPE_UINT = (1 << 18),
/**
* An unknown type of value.
*/
AM_VAL_TYPE_UNKNOWN = (1 << 19),
/**
* A void.
*/
AM_VAL_TYPE_VOID = (1 << 0),
};
typedef uint32_t AMvalType;
/**
* \struct AMactorId
* \installed_headerfile
* \brief An actor's unique identifier.
*/
typedef struct AMactorId AMactorId;
/**
* \struct AMchange
* \installed_headerfile
* \brief A group of operations performed by an actor.
*/
typedef struct AMchange AMchange;
/**
* \struct AMdoc
* \installed_headerfile
* \brief A JSON-like CRDT.
*/
typedef struct AMdoc AMdoc;
/**
* \struct AMitem
* \installed_headerfile
* \brief An item within a result.
*/
typedef struct AMitem AMitem;
typedef struct AMmark AMmark;
/**
* \struct AMobjId
* \installed_headerfile
* \brief An object's unique identifier.
*/
typedef struct AMobjId AMobjId;
/**
* \struct AMresult
* \installed_headerfile
* \brief A discriminated union of result variants.
*/
typedef struct AMresult AMresult;
/**
* \struct AMsyncHave
* \installed_headerfile
* \brief A summary of the changes that the sender of a synchronization
* message already has.
*/
typedef struct AMsyncHave AMsyncHave;
/**
* \struct AMsyncMessage
* \installed_headerfile
* \brief A synchronization message for a peer.
*/
typedef struct AMsyncMessage AMsyncMessage;
/**
* \struct AMsyncState
* \installed_headerfile
* \brief The state of synchronization with a peer.
*/
typedef struct AMsyncState AMsyncState;
/**
* \struct AMbyteSpan
* \installed_headerfile
* \brief A view onto an array of bytes.
*/
typedef struct AMbyteSpan {
/**
* A pointer to the first byte of an array of bytes.
* \warning \p src is only valid until the array of bytes to which it
* points is freed.
* \note If the `AMbyteSpan` came from within an `AMitem` struct then
* \p src will be freed when the pointer to the `AMresult` struct
* containing the `AMitem` struct is passed to `AMresultFree()`.
*/
const uint8_t *src;
/**
* The count of bytes in the array.
*/
size_t count;
} AMbyteSpan;
/**
* \struct AMitems
* \installed_headerfile
* \brief A random-access iterator over a sequence of `AMitem` structs.
*/
typedef struct AMitems {
/**
* An implementation detail that is intentionally opaque.
* \warning Modifying \p detail will cause undefined behavior.
* \note The actual size of \p detail will vary by platform, this is just
* the one for the platform this documentation was built on.
*/
uint8_t detail[+8+8+8];
} AMitems;
/**
* \struct AMunknownValue
* \installed_headerfile
* \brief A value (typically for a `set` operation) whose type is unknown.
*/
typedef struct AMunknownValue {
/**
* The value's raw bytes.
*/
struct AMbyteSpan bytes;
/**
* The value's encoded type identifier.
*/
uint8_t type_code;
} AMunknownValue;
/**
* \memberof AMactorId
* \brief Gets the value of an actor identifier as an array of bytes.
*
* \param[in] actor_id A pointer to an `AMactorId` struct.
* \return An `AMbyteSpan` struct for an array of bytes.
* \pre \p actor_id `!= NULL`
* \internal
*
* # Safety
* actor_id must be a valid pointer to an AMactorId
*/
struct AMbyteSpan AMactorIdBytes(const struct AMactorId *actor_id);
/**
* \memberof AMactorId
* \brief Compares two actor identifiers.
*
* \param[in] actor_id1 A pointer to an `AMactorId` struct.
* \param[in] actor_id2 A pointer to an `AMactorId` struct.
* \return `-1` if \p actor_id1 `<` \p actor_id2, `0` if
* \p actor_id1 `==` \p actor_id2 and `1` if
* \p actor_id1 `>` \p actor_id2.
* \pre \p actor_id1 `!= NULL`
* \pre \p actor_id2 `!= NULL`
* \internal
*
* #Safety
* actor_id1 must be a valid pointer to an AMactorId
* actor_id2 must be a valid pointer to an AMactorId
*/
int AMactorIdCmp(const struct AMactorId *actor_id1, const struct AMactorId *actor_id2);
/**
* \memberof AMactorId
* \brief Allocates a new actor identifier and initializes it from a random
* UUID value.
*
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_ACTOR_ID` item.
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
*/
struct AMresult *AMactorIdInit(void);
/**
* \memberof AMactorId
* \brief Allocates a new actor identifier and initializes it from an array of
* bytes value.
*
* \param[in] src A pointer to an array of bytes.
* \param[in] count The count of bytes to copy from the array pointed to by
* \p src.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_ACTOR_ID` item.
* \pre \p src `!= NULL`
* \pre `sizeof(`\p src `) > 0`
* \pre \p count `<= sizeof(`\p src `)`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* src must be a byte array of length `>= count`
*/
struct AMresult *AMactorIdFromBytes(const uint8_t *src, size_t count);
/**
* \memberof AMactorId
* \brief Allocates a new actor identifier and initializes it from a
* hexadecimal UTF-8 string view value.
*
* \param[in] value A UTF-8 string view as an `AMbyteSpan` struct.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_ACTOR_ID` item.
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* value.src must be a byte array of length >= value.count
*/
struct AMresult *AMactorIdFromStr(struct AMbyteSpan value);
/**
* \memberof AMactorId
* \brief Gets the value of an actor identifier as a UTF-8 hexadecimal string
* view.
*
* \param[in] actor_id A pointer to an `AMactorId` struct.
* \return A UTF-8 string view as an `AMbyteSpan` struct.
* \pre \p actor_id `!= NULL`
* \internal
*
* # Safety
* actor_id must be a valid pointer to an AMactorId
*/
struct AMbyteSpan AMactorIdStr(const struct AMactorId *actor_id);
/**
* \memberof AMbyteSpan
* \brief Creates a view onto an array of bytes.
*
* \param[in] src A pointer to an array of bytes or `NULL`.
* \param[in] count The count of bytes to view from the array pointed to by
* \p src.
* \return An `AMbyteSpan` struct.
* \pre \p count `<= sizeof(`\p src `)`
* \post `(`\p src `== NULL) -> (AMbyteSpan){NULL, 0}`
* \internal
*
* #Safety
* src must be a byte array of length `>= count` or `std::ptr::null()`
*/
struct AMbyteSpan AMbytes(const uint8_t *src, size_t count);
/**
* \memberof AMbyteSpan
* \brief Creates a view onto a C string.
*
* \param[in] c_str A null-terminated byte string or `NULL`.
* \return An `AMbyteSpan` struct.
* \pre Each byte in \p c_str encodes one UTF-8 character.
* \internal
*
* #Safety
* c_str must be a null-terminated array of `std::os::raw::c_char` or `std::ptr::null()`.
*/
struct AMbyteSpan AMstr(const char *c_str);
/**
* \memberof AMbyteSpan
* \brief Compares two UTF-8 string views lexicographically.
*
* \param[in] lhs A UTF-8 string view as an `AMbyteSpan` struct.
* \param[in] rhs A UTF-8 string view as an `AMbyteSpan` struct.
* \return Negative value if \p lhs appears before \p rhs in lexicographical order.
* Zero if \p lhs and \p rhs compare equal.
* Positive value if \p lhs appears after \p rhs in lexicographical order.
* \pre \p lhs.src `!= NULL`
* \pre \p lhs.count `<= sizeof(`\p lhs.src `)`
* \pre \p rhs.src `!= NULL`
* \pre \p rhs.count `<= sizeof(`\p rhs.src `)`
* \internal
*
* #Safety
* lhs.src must be a byte array of length >= lhs.count
* rhs.src must be a a byte array of length >= rhs.count
*/
int AMstrCmp(struct AMbyteSpan lhs, struct AMbyteSpan rhs);
/**
* \memberof AMchange
* \brief Gets the first referenced actor identifier in a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_ACTOR_ID` item.
* \pre \p change `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMresult *AMchangeActorId(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Compresses the raw bytes of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
void AMchangeCompress(struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the dependencies of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE_HASH` items.
* \pre \p change `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMresult *AMchangeDeps(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the extra bytes of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return An `AMbyteSpan` struct.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMbyteSpan AMchangeExtraBytes(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Allocates a new change and initializes it from an array of bytes value.
*
* \param[in] src A pointer to an array of bytes.
* \param[in] count The count of bytes to load from the array pointed to by
* \p src.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_CHANGE` item.
* \pre \p src `!= NULL`
* \pre `sizeof(`\p src `) > 0`
* \pre \p count `<= sizeof(`\p src `)`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* src must be a byte array of length `>= count`
*/
struct AMresult *AMchangeFromBytes(const uint8_t *src, size_t count);
/**
* \memberof AMchange
* \brief Gets the hash of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return An `AMbyteSpan` struct for a change hash.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMbyteSpan AMchangeHash(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Tests the emptiness of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return `true` if \p change is empty, `false` otherwise.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
bool AMchangeIsEmpty(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Loads a document into a sequence of changes.
*
* \param[in] src A pointer to an array of bytes.
* \param[in] count The count of bytes to load from the array pointed to by
* \p src.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE` items.
* \pre \p src `!= NULL`
* \pre `sizeof(`\p src `) > 0`
* \pre \p count `<= sizeof(`\p src `)`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* src must be a byte array of length `>= count`
*/
struct AMresult *AMchangeLoadDocument(const uint8_t *src, size_t count);
/**
* \memberof AMchange
* \brief Gets the maximum operation index of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A 64-bit unsigned integer.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
uint64_t AMchangeMaxOp(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the message of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A UTF-8 string view as an `AMbyteSpan` struct.
* \pre \p change `!= NULL`
* \post `(`\p change `== NULL) -> (AMbyteSpan){NULL, 0}`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMbyteSpan AMchangeMessage(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the index of a change in the changes from an actor.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A 64-bit unsigned integer.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
uint64_t AMchangeSeq(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the size of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A 64-bit unsigned integer.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
size_t AMchangeSize(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the start operation index of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A 64-bit unsigned integer.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
uint64_t AMchangeStartOp(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the commit time of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return A 64-bit signed integer.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
int64_t AMchangeTime(const struct AMchange *change);
/**
* \memberof AMchange
* \brief Gets the raw bytes of a change.
*
* \param[in] change A pointer to an `AMchange` struct.
* \return An `AMbyteSpan` struct for an array of bytes.
* \pre \p change `!= NULL`
* \internal
*
* # Safety
* change must be a valid pointer to an AMchange
*/
struct AMbyteSpan AMchangeRawBytes(const struct AMchange *change);
/**
* \memberof AMdoc
* \brief Applies a sequence of changes to a document.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] items A pointer to an `AMitems` struct with `AM_VAL_TYPE_CHANGE`
* items.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_VOID` item.
* \pre \p doc `!= NULL`
* \pre \p items `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
* items must be a valid pointer to an AMitems.
*/
struct AMresult *AMapplyChanges(struct AMdoc *doc, const struct AMitems *items);
/**
* \memberof AMdoc
* \brief Allocates storage for a document and initializes it by duplicating
* the given document.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_DOC` item.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMclone(const struct AMdoc *doc);
/**
* \memberof AMdoc
* \brief Allocates a new document and initializes it with defaults.
*
* \param[in] actor_id A pointer to an `AMactorId` struct or `NULL` for a
* random one.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_DOC` item.
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* actor_id must be a valid pointer to an AMactorId or std::ptr::null()
*/
struct AMresult *AMcreate(const struct AMactorId *actor_id);
/**
* \memberof AMdoc
* \brief Commits the current operations on a document with an optional
* message and/or *nix timestamp (milliseconds).
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] message A UTF-8 string view as an `AMbyteSpan` struct.
* \param[in] timestamp A pointer to a 64-bit integer or `NULL`.
* \return A pointer to an `AMresult` struct with one `AM_VAL_TYPE_CHANGE_HASH`
* item if there were operations to commit or an `AM_VAL_TYPE_VOID` item
* if there were no operations to commit.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMcommit(struct AMdoc *doc, struct AMbyteSpan message, const int64_t *timestamp);
/**
* \memberof AMdoc
* \brief Creates an empty change with an optional message and/or *nix
* timestamp (milliseconds).
*
* \details This is useful if you wish to create a "merge commit" which has as
* its dependents the current heads of the document but you don't have
* any operations to add to the document.
*
* \note If there are outstanding uncommitted changes to the document
* then two changes will be created: one for creating the outstanding
* changes and one for the empty change. The empty change will always be
* the latest change in the document after this call and the returned
* hash will be the hash of that empty change.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] message A UTF-8 string view as an `AMbyteSpan` struct.
* \param[in] timestamp A pointer to a 64-bit integer or `NULL`.
* \return A pointer to an `AMresult` struct with one `AM_VAL_TYPE_CHANGE_HASH`
* item.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMemptyChange(struct AMdoc *doc, struct AMbyteSpan message, const int64_t *timestamp);
/**
* \memberof AMdoc
* \brief Tests the equality of two documents after closing their respective
* transactions.
*
* \param[in] doc1 A pointer to an `AMdoc` struct.
* \param[in] doc2 A pointer to an `AMdoc` struct.
* \return `true` if \p doc1 `==` \p doc2 and `false` otherwise.
* \pre \p doc1 `!= NULL`
* \pre \p doc2 `!= NULL`
* \internal
*
* #Safety
* doc1 must be a valid pointer to an AMdoc
* doc2 must be a valid pointer to an AMdoc
*/
bool AMequal(struct AMdoc *doc1, struct AMdoc *doc2);
/**
* \memberof AMdoc
* \brief Forks this document at its current or a historical point for use by
* a different actor.
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] heads A pointer to an `AMitems` struct with `AM_VAL_TYPE_CHANGE_HASH`
* items to select a historical point or `NULL` to select its
* current point.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_VOID` item.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
* heads must be a valid pointer to an AMitems or std::ptr::null()
*/
struct AMresult *AMfork(struct AMdoc *doc, const struct AMitems *heads);
/**
* \memberof AMdoc
* \brief Generates a synchronization message for a peer based upon the given
* synchronization state.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] sync_state A pointer to an `AMsyncState` struct.
* \return A pointer to an `AMresult` struct with either an
* `AM_VAL_TYPE_SYNC_MESSAGE` or `AM_VAL_TYPE_VOID` item.
* \pre \p doc `!= NULL`
* \pre \p sync_state `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
* sync_state must be a valid pointer to an AMsyncState
*/
struct AMresult *AMgenerateSyncMessage(struct AMdoc *doc, struct AMsyncState *sync_state);
/**
* \memberof AMdoc
* \brief Gets a document's actor identifier.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_ACTOR_ID` item.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMgetActorId(const struct AMdoc *doc);
/**
* \memberof AMdoc
* \brief Gets the change added to a document by its respective hash.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] src A pointer to an array of bytes.
* \param[in] count The count of bytes to copy from the array pointed to by
* \p src.
* \return A pointer to an `AMresult` struct with an `AM_VAL_TYPE_CHANGE` item.
* \pre \p doc `!= NULL`
* \pre \p src `!= NULL`
* \pre `sizeof(`\p src') >= AM_CHANGE_HASH_SIZE`
* \pre \p count `<= sizeof(`\p src `)`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
* src must be a byte array of length `>= automerge::types::HASH_SIZE`
*/
struct AMresult *AMgetChangeByHash(struct AMdoc *doc, const uint8_t *src, size_t count);
/**
* \memberof AMdoc
* \brief Gets the changes added to a document by their respective hashes.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] have_deps A pointer to an `AMitems` struct with
* `AM_VAL_TYPE_CHANGE_HASH` items or `NULL`.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE` items.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMgetChanges(struct AMdoc *doc, const struct AMitems *have_deps);
/**
* \memberof AMdoc
* \brief Gets the changes added to a second document that weren't added to
* a first document.
*
* \param[in] doc1 A pointer to an `AMdoc` struct.
* \param[in] doc2 A pointer to an `AMdoc` struct.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE` items.
* \pre \p doc1 `!= NULL`
* \pre \p doc2 `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc1 must be a valid pointer to an AMdoc
* doc2 must be a valid pointer to an AMdoc
*/
struct AMresult *AMgetChangesAdded(struct AMdoc *doc1, struct AMdoc *doc2);
/**
* \memberof AMdoc
* \brief Gets the current heads of a document.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE_HASH` items.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
*/
struct AMresult *AMgetHeads(struct AMdoc *doc);
/**
* \memberof AMdoc
* \brief Gets the hashes of the changes in a document that aren't transitive
* dependencies of the given hashes of changes.
*
* \param[in] doc A pointer to an `AMdoc` struct.
* \param[in] heads A pointer to an `AMitems` struct with `AM_VAL_TYPE_CHANGE_HASH`
* items or `NULL`.
* \return A pointer to an `AMresult` struct with `AM_VAL_TYPE_CHANGE_HASH` items.
* \pre \p doc `!= NULL`
* \warning The returned `AMresult` struct pointer must be passed to
* `AMresultFree()` in order to avoid a memory leak.
* \internal
*
* # Safety
* doc must be a valid pointer to an AMdoc
* heads must be a valid pointer to an AMitems or std::ptr::null()
*/