Skip to content

Commit 814e58a

Browse files
committed
Second
1 parent 621931c commit 814e58a

33 files changed

Lines changed: 844 additions & 2065 deletions

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: erlef/setup-beam@v1
1616
with:
1717
otp-version: "28"
18-
gleam-version: "1.12.0-nightly-20250818"
18+
gleam-version: "1.12.0"
1919
rebar3-version: "3"
2020
# elixir-version: "1"
2121
- run: gleam deps download

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ erl_crash.dump
55

66
# Test-generated files - kept in test/ dir to avoid cluttering src/
77
test/*_pb.gleam
8-
test/.generated/
8+
test/generated_outputs/
99
build/test_gen/
1010
dev/

Makefile

Lines changed: 0 additions & 56 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,6 @@
1-
# gloto
1+
# Protozoa
22

33
A Protocol Buffers library for Gleam, providing encoding and decoding of protobuf messages.
44

5-
[![Package Version](https://img.shields.io/hexpm/v/gloto)](https://hex.pm/packages/gloto)
6-
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gloto/)
7-
8-
## Installation
9-
10-
```sh
11-
gleam add gloto@1
12-
```
13-
14-
## Usage
15-
16-
### Encoding Messages
17-
18-
```gleam
19-
import gloto
20-
import gleam/int
21-
import gleam/io
22-
23-
pub fn encode_example() {
24-
// Create a protobuf message with multiple fields
25-
let message = gloto.build_message([
26-
gloto.encode_int32(1, 42), // Field 1: int32
27-
gloto.encode_string(2, "Hello"), // Field 2: string
28-
gloto.encode_bool(3, True), // Field 3: bool
29-
])
30-
31-
// message is now a BitArray containing the encoded protobuf
32-
message
33-
}
34-
```
35-
36-
### Decoding Messages
37-
38-
```gleam
39-
import gloto
40-
import gleam/int
41-
import gleam/io
42-
43-
pub fn decode_example(data: BitArray) {
44-
case gloto.decode(data) {
45-
Ok(fields) -> {
46-
// Find specific fields by number
47-
case gloto.find_field(fields, 1) {
48-
Ok(field) -> {
49-
case gloto.decode_varint_value(field) {
50-
Ok(value) -> io.println("Field 1: " <> int.to_string(value))
51-
Error(_) -> io.println("Failed to decode field 1")
52-
}
53-
}
54-
Error(_) -> io.println("Field 1 not found")
55-
}
56-
}
57-
Error(_) -> io.println("Failed to decode message")
58-
}
59-
}
60-
```
61-
62-
### Nested Messages
63-
64-
```gleam
65-
import gloto
66-
67-
pub fn nested_message_example() {
68-
// Create an inner message
69-
let inner = gloto.build_message([
70-
gloto.encode_string(1, "inner value"),
71-
gloto.encode_int32(2, 100),
72-
])
73-
74-
// Embed it in an outer message
75-
let outer = gloto.build_message([
76-
gloto.encode_int32(1, 999),
77-
gloto.encode_message_field(2, inner), // Nested message in field 2
78-
])
79-
80-
outer
81-
}
82-
```
83-
84-
### Repeated Fields
85-
86-
Protocol Buffers supports repeated fields. Simply encode multiple values with the same field number:
87-
88-
```gleam
89-
import gloto
90-
91-
pub fn repeated_fields_example() {
92-
let message = gloto.build_message([
93-
gloto.encode_int32(1, 10),
94-
gloto.encode_int32(1, 20), // Same field number
95-
gloto.encode_int32(1, 30), // Creates a repeated field
96-
gloto.encode_string(2, "other field"),
97-
])
98-
99-
// When decoding, use find_all_fields to get all values
100-
case gloto.decode(message) {
101-
Ok(fields) -> {
102-
let repeated = gloto.find_all_fields(fields, 1)
103-
// repeated will contain all three int32 values
104-
repeated
105-
}
106-
Error(_) -> panic
107-
}
108-
}
109-
```
110-
111-
## Supported Types
112-
113-
- **Varint**: int32, int64, bool
114-
- **Fixed32**: 32-bit values with fixed size
115-
- **Fixed64**: 64-bit values with fixed size
116-
- **Length-delimited**: strings, bytes, nested messages
117-
118-
## Architecture
119-
120-
The library is structured into three main modules:
121-
122-
- `gloto/wire` - Wire format types and tag encoding/decoding
123-
- `gloto/encoder` - Functions for encoding various protobuf types
124-
- `gloto/decoder` - Functions for decoding protobuf messages
125-
- `gloto` - High-level API for working with protobuf messages
126-
127-
## Future Plans
128-
129-
- Code generation from .proto files
130-
- gRPC support
131-
- Schema validation
132-
- More comprehensive type support
133-
134-
## Development
135-
136-
```sh
137-
gleam run # Run the project
138-
gleam test # Run the tests
139-
```
140-
141-
Further documentation can be found at <https://hexdocs.pm/gloto>.
5+
[![Package Version](https://img.shields.io/hexpm/v/protozoa)](https://hex.pm/packages/protozoa)
6+
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/protozoa/)

birdie_snapshots/generate_all_field_types.accepted

Lines changed: 0 additions & 52 deletions
This file was deleted.

birdie_snapshots/generate_all_scalar_types.accepted

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)