|
1 |
| -# liftbridge-grpc |
| 1 | +# Liftbridge API |
2 | 2 |
|
3 |
| -Protobuf definitions for the [Liftbridge](https://github.com/liftbridge-io/liftbridge) gRPC API. |
| 3 | +This repository contains the public API definitions for |
| 4 | +[Liftbridge](https://github.com/liftbridge-io/liftbridge). It is primarily |
| 5 | +intended for Liftbridge client developers. |
| 6 | + |
| 7 | +## gRPC API |
| 8 | + |
| 9 | +The client-facing gRPC API is defined in [api.proto](api.proto). |
| 10 | + |
| 11 | +## Direct NATS API |
| 12 | + |
| 13 | +It is also possible for a client to publish messages to Liftbridge via NATS |
| 14 | +directly. Liftbridge accepts plain NATS messages, allowing it to make existing |
| 15 | +subjects durable without any publisher changes. However, these messages will |
| 16 | +not have some features such as acks. |
| 17 | + |
| 18 | +In order to opt into Liftbridge-specific features, the message must be prefixed |
| 19 | +with the following header and be encoded as a `Message` (defined in |
| 20 | +[api.proto](api.proto)). |
| 21 | + |
| 22 | +### Liftbridge Envelope Header |
| 23 | + |
| 24 | +``` |
| 25 | +0 8 16 24 32 |
| 26 | +├───────────────┴───────────────┴───────────────┴───────────────┤ |
| 27 | +│ Magic Number │ |
| 28 | +├───────────────┬───────────────┬───────────────┬───────────────┤ |
| 29 | +│ Version │ HeaderLen │ Flags │ Reserved │ |
| 30 | +├───────────────┴───────────────┴───────────────┴───────────────┤ |
| 31 | +│ CRC-32C (optional) │ |
| 32 | +└───────────────────────────────────────────────────────────────┘ |
| 33 | +``` |
| 34 | + |
| 35 | +#### Magic number [4 bytes] |
| 36 | + |
| 37 | +The Liftbridge magic number is `B9 0E 43 B4`. This was chosen by random but |
| 38 | +deliberately restricted to invalid UTF-8 to reduce the chance of a collision. |
| 39 | +This was also verified to not match known file signatures. |
| 40 | + |
| 41 | +#### Version [1 byte] |
| 42 | + |
| 43 | +The version byte allows for future protocol upgrades. This should only be |
| 44 | +bumped if the envelope format changes or if the message encoding changes in a |
| 45 | +non-backwards-compatible way. Adding fields to the messages should not require |
| 46 | +a version bump. |
| 47 | + |
| 48 | +#### HeaderLen [1 byte] |
| 49 | + |
| 50 | +The header length is the offset of the payload. This is included primarily for |
| 51 | +safety. |
| 52 | + |
| 53 | +#### Flags [1 byte] |
| 54 | + |
| 55 | +The flag bits are defined as follows: |
| 56 | + |
| 57 | +| Bit | Description | |
| 58 | +| --- | --------------- | |
| 59 | +| 0 | CRC-32C enabled | |
| 60 | + |
| 61 | +#### CRC-32C [4 bytes, optional] |
| 62 | + |
| 63 | +The CRC-32C (Castagnoli) is the checksum of the payload (i.e. from HeaderLen to |
| 64 | +the end). This is optional but should significantly reduce the chance that a |
| 65 | +random NATS message is interpreted as a Liftbridge message. |
0 commit comments