@dxos/codec-protobuf 2.33.9-dev.e605934d → 2.33.9-dev.eb69ac10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +39 -0
  2. package/dist/{index.js → browser.js} +3983 -197
  3. package/dist/src/buffer-patch.d.ts +1 -0
  4. package/dist/src/buffer-patch.d.ts.map +1 -1
  5. package/dist/src/buffer-patch.js +15 -0
  6. package/dist/src/buffer-patch.js.map +1 -0
  7. package/dist/src/codec.js +53 -0
  8. package/dist/src/codec.js.map +1 -0
  9. package/dist/src/common.js +6 -0
  10. package/dist/src/common.js.map +1 -0
  11. package/dist/src/encoding.js +35 -0
  12. package/dist/src/encoding.js.map +1 -0
  13. package/dist/src/index.d.ts +2 -0
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/index.js +31 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/interface.js +14 -0
  18. package/dist/src/interface.js.map +1 -0
  19. package/dist/src/mapping.d.ts +3 -0
  20. package/dist/src/mapping.d.ts.map +1 -1
  21. package/dist/src/mapping.js +72 -0
  22. package/dist/src/mapping.js.map +1 -0
  23. package/dist/src/precompiled-mapping/codegen.js +86 -0
  24. package/dist/src/precompiled-mapping/codegen.js.map +1 -0
  25. package/dist/src/precompiled-mapping/create-message-mapper.js +132 -0
  26. package/dist/src/precompiled-mapping/create-message-mapper.js.map +1 -0
  27. package/dist/src/sanitizer.js +53 -0
  28. package/dist/src/sanitizer.js.map +1 -0
  29. package/dist/src/schema.js +86 -0
  30. package/dist/src/schema.js.map +1 -0
  31. package/dist/src/service.d.ts +2 -2
  32. package/dist/src/service.d.ts.map +1 -1
  33. package/dist/src/service.js +113 -0
  34. package/dist/src/service.js.map +1 -0
  35. package/dist/src/stream.d.ts +31 -0
  36. package/dist/src/stream.d.ts.map +1 -1
  37. package/dist/src/stream.js +186 -0
  38. package/dist/src/stream.js.map +1 -0
  39. package/dist/src/stream.test.js +66 -0
  40. package/dist/src/stream.test.js.map +1 -0
  41. package/dist/src/substitutions/any.js +30 -0
  42. package/dist/src/substitutions/any.js.map +1 -0
  43. package/dist/src/substitutions/index.js +22 -0
  44. package/dist/src/substitutions/index.js.map +1 -0
  45. package/dist/src/substitutions/timestamp.js +19 -0
  46. package/dist/src/substitutions/timestamp.js.map +1 -0
  47. package/dist/test/codec.test.js +67 -0
  48. package/dist/test/codec.test.js.map +1 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +10 -7
  51. package/src/encoding.ts +9 -0
  52. package/src/index.ts +2 -0
  53. package/src/mapping.ts +60 -0
  54. package/src/precompiled-mapping/create-message-mapper.ts +41 -3
  55. package/src/service.ts +11 -18
  56. package/src/stream.test.ts +3 -1
  57. package/src/stream.ts +72 -1
package/README.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # codec-protobuf
2
2
 
3
+ There's an associated @dxos/protobuf-compiler package that does codegen based on protobuf schema.
4
+
5
+ ## Handling of scalar fields with default values
6
+
7
+ Based on:
8
+ - https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
9
+ - https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md
10
+
11
+
12
+ In protobuf scalar fields (numbers, booleans, strings, bytes, enums) may have an implicit default value:
13
+
14
+ - 0 for number types
15
+ - false for booleans
16
+ - '' (empty string) for strings
17
+ - [] for bytes
18
+ - First enum value for enums
19
+
20
+ ### Non-optional fields
21
+
22
+ Example:
23
+
24
+ ```protobuf
25
+ int32 number = 1;
26
+ ```
27
+
28
+ If the field is set to it's default value (0 in this example) it MAY be missing in the wire encoding (Go implementation) or present with the value set to 0 (JS implementation).
29
+
30
+ When decoding, the missing fields MUST be treated as having the default implicit value (0 in this case).
31
+
32
+ ### Optional fields
33
+
34
+ ```protobuf
35
+ optional int32 number = 1;
36
+ ```
37
+
38
+ If the field is set to it's default value (0 in this example) it MUST be present in the wire encoding with the value set to 0.
39
+
40
+ When decoding, the missing fields it MUST be set as undefined. If the field is present in the wire format, it must be set to its numeric value.
41
+
3
42
  ## Toolchain
4
43
 
5
44
  This package must NOT use `toolchain` to avoid cyclic dependencies.