Skip to content

Commit fc30efd

Browse files
author
a-ok123
committed
Added code and libraries
1 parent 3a0c04d commit fc30efd

File tree

13 files changed

+2040
-0
lines changed

13 files changed

+2040
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
27+
# IDEs
28+
.idea/

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# RaptorQ Go Bindings
2+
3+
This repository contains Go bindings for the RaptorQ erasure coding library. It is automatically synchronized from the [rq-library](https://github.com/LumeraProtocol/rq-library) repository.
4+
5+
## Repository Structure
6+
7+
```
8+
rq-go/
9+
├── README.md # This file
10+
├── go.mod # Root Go module file
11+
├── README.md # Documentation for Go bindings
12+
├── raptorq.go # Main Go binding code
13+
└── raptorq_test.go # Tests for the Go bindings
14+
└── lib/ # Platform-specific libraries
15+
├── README.md # Documentation for the libraries
16+
├── darwin/ # macOS libraries
17+
│ ├── amd64/ # Intel macOS
18+
│ │ └── librq_library.a
19+
│ └── arm64/ # Apple Silicon
20+
│ └── librq_library.a
21+
├── linux/ # Linux libraries
22+
│ ├── amd64/ # amd64
23+
│ │ └── librq_library.a
24+
│ └── arm64/ # ARM64
25+
│ └── librq_library.a
26+
└── windows/ # Windows libraries
27+
└── amd64/ # amd64
28+
└── librq_library.a
29+
```
30+
31+
## Platform Subfolders
32+
33+
The platform subfolder structure follows Go's standard naming convention:
34+
- `darwin/amd64` - macOS on Intel
35+
- `darwin/arm64` - macOS on Apple Silicon
36+
- `linux/amd64` - Linux on amd64
37+
- `linux/arm64` - Linux on ARM64 (including Raspberry Pi)
38+
- `windows/amd64` - Windows on amd64
39+
40+
## Linking
41+
42+
The Go module is configured to statically link with the RaptorQ library. This means the library code is included in the final binary, making it self-contained and avoiding runtime dependencies on shared libraries.
43+
44+
## Usage
45+
46+
To use this package in your Go project:
47+
48+
```bash
49+
go get github.com/LumeraProtocol/rq-go
50+
```
51+
52+
Then import it in your code:
53+
54+
```go
55+
import "github.com/LumeraProtocol/rq-go"
56+
```
57+
58+
## Example
59+
60+
```go
61+
package main
62+
63+
import (
64+
"fmt"
65+
"github.com/LumeraProtocol/rq-go"
66+
)
67+
68+
func main() {
69+
// Create a new RaptorQ processor with default settings
70+
processor, err := raptorq.NewDefaultRaptorQProcessor()
71+
if err != nil {
72+
panic(err)
73+
}
74+
defer processor.Free()
75+
76+
// Get library version
77+
version := raptorq.GetVersion()
78+
fmt.Printf("RaptorQ library version: %s\n", version)
79+
80+
// Use the processor to encode/decode files
81+
// See the test file for examples
82+
}
83+
```
84+
85+
## License
86+
87+
This project is licensed under MIT License. See the [LICENSE](LICENSE) file for details.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/LumeraProtocol/rq-go
2+
3+
go 1.21

include/rq-library.h

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/* RQ Library - C API
2+
* Generated with cbindgen
3+
*/
4+
5+
6+
#ifndef RQ_LIB_H
7+
#define RQ_LIB_H
8+
9+
/* Generated with cbindgen:0.28.0 */
10+
11+
#include <stdint.h>
12+
#include <stdbool.h>
13+
14+
#ifdef __cplusplus
15+
namespace RQLibrary {
16+
#endif // __cplusplus
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif // __cplusplus
21+
22+
/**
23+
* Initializes a RaptorQ session with the given configuration
24+
* Returns a session ID on success, or 0 on failure
25+
*/
26+
uintptr_t raptorq_init_session(uint16_t symbol_size,
27+
uint8_t redundancy_factor,
28+
uint64_t max_memory_mb,
29+
uint64_t concurrency_limit);
30+
31+
/**
32+
* Frees a RaptorQ session
33+
*/
34+
bool raptorq_free_session(uintptr_t session_id);
35+
36+
/**
37+
* Encodes a file using RaptorQ - streaming implementation
38+
*
39+
* Arguments:
40+
* * `session_id` - Session ID returned from raptorq_init_session
41+
* * `input_path` - Path to the input file
42+
* * `output_dir` - Directory where symbols will be written
43+
* * `block_size` - Size of blocks to process at once (0 = auto)
44+
* * `result_buffer` - Buffer to store the result (JSON metadata)
45+
* * `result_buffer_len` - Length of the result buffer
46+
*
47+
* Returns:
48+
* * 0 on success
49+
* * -1 on generic error
50+
* * -2 on invalid parameters
51+
* * -3 on invalid response
52+
* * -4 on bad return buffer size
53+
* * -4 on encoding failure
54+
* * -5 on invalid session
55+
* * -11 on IO error
56+
* * -12 on File not found
57+
* * -13 on Encoding failed
58+
* * -15 on Memory limit exceeded
59+
* * -16 on Concurrency limit reached
60+
*/
61+
int32_t raptorq_create_metadata(uintptr_t session_id,
62+
const char *input_path,
63+
const char *output_dir,
64+
uintptr_t block_size,
65+
bool return_layout,
66+
char *result_buffer,
67+
uintptr_t result_buffer_len);
68+
69+
/**
70+
* Encodes a file using RaptorQ - streaming implementation
71+
*
72+
* Arguments:
73+
* * `session_id` - Session ID returned from raptorq_init_session
74+
* * `input_path` - Path to the input file
75+
* * `output_dir` - Directory where symbols will be written
76+
* * `block_size` - Size of blocks to process at once (0 = auto)
77+
* * `result_buffer` - Buffer to store the result (JSON metadata)
78+
* * `result_buffer_len` - Length of the result buffer
79+
*
80+
* Returns:
81+
* * 0 on success
82+
* * -1 on generic error
83+
* * -2 on invalid parameters
84+
* * -3 on invalid response
85+
* * -4 on bad return buffer size
86+
* * -4 on encoding failure
87+
* * -5 on invalid session
88+
* * -11 on IO error
89+
* * -12 on File not found
90+
* * -13 on Encoding failed
91+
* * -15 on Memory limit exceeded
92+
* * -16 on Concurrency limit reached
93+
*/
94+
int32_t raptorq_encode_file(uintptr_t session_id,
95+
const char *input_path,
96+
const char *output_dir,
97+
uintptr_t block_size,
98+
char *result_buffer,
99+
uintptr_t result_buffer_len);
100+
101+
/**
102+
* Gets the last error message from the processor
103+
*
104+
* Arguments:
105+
* * `session_id` - Session ID returned from raptorq_init_session
106+
* * `error_buffer` - Buffer to store the error message
107+
* * `error_buffer_len` - Length of the error buffer
108+
*
109+
* Returns:
110+
* * 0 on success
111+
* * -1 on error
112+
*/
113+
int32_t raptorq_get_last_error(uintptr_t session_id,
114+
char *error_buffer,
115+
uintptr_t error_buffer_len);
116+
117+
/**
118+
* Decodes RaptorQ symbols back to the original file
119+
*
120+
* Arguments:
121+
* * `session_id` - Session ID returned from raptorq_init_session
122+
* * `symbols_dir` - Directory containing the symbols
123+
* * `output_path` - Path where the decoded file will be written
124+
* * `layout_path` - Path to the layout file (containing encoder parameters and block information)
125+
*
126+
* Returns:
127+
* * 0 on success
128+
* * -1 on generic error
129+
* * -2 on invalid parameters
130+
* * -3 on invalid response
131+
* * -4 on bad return buffer size
132+
* * -4 on encoding failure
133+
* * -5 on invalid session
134+
* * -11 on IO error
135+
* * -12 on File not found
136+
* * -14 on Decoding failed
137+
* * -15 on Memory limit exceeded
138+
* * -16 on Concurrency limit reached
139+
*/
140+
int32_t raptorq_decode_symbols(uintptr_t session_id,
141+
const char *symbols_dir,
142+
const char *output_path,
143+
const char *layout_path);
144+
145+
/**
146+
* Gets a recommended block size based on file size and available memory
147+
*
148+
* Arguments:
149+
* * `session_id` - Session ID returned from raptorq_init_session
150+
* * `file_size` - Size of the file to process
151+
*
152+
* Returns:
153+
* * Recommended block size in bytes
154+
* * 0 if it should not block or on error
155+
*/
156+
uintptr_t raptorq_get_recommended_block_size(uintptr_t session_id, uint64_t file_size);
157+
158+
/**
159+
* Version information
160+
*/
161+
int32_t raptorq_version(char *version_buffer, uintptr_t version_buffer_len);
162+
163+
#ifdef __cplusplus
164+
} // extern "C"
165+
#endif // __cplusplus
166+
167+
#ifdef __cplusplus
168+
} // namespace RQLibrary
169+
#endif // __cplusplus
170+
171+
#endif /* RQ_LIB_H */

lib/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Static RaptorQ Library
2+
3+
This directory contains the static version of the RaptorQ library (`librq_library.a`) for different platforms and architectures.
4+
5+
## Directory Structure
6+
7+
The library files are organized in platform-specific subdirectories following Go's standard naming convention:
8+
9+
```
10+
lib/
11+
├── README.md # This file
12+
├── darwin/ # macOS libraries
13+
│ ├── amd64/ # Intel macOS
14+
│ │ ├── librq_library.a
15+
│ └── arm64/ # Apple Silicon
16+
│ └── librq_library.a
17+
├── linux/ # Linux libraries
18+
│ ├── amd64/ # amd64
19+
│ │ └── librq_library.a
20+
│ └── arm64/ # ARM64
21+
│ └── librq_library.a
22+
└── windows/ # Windows libraries
23+
└── amd64/ # amd64
24+
└── librq_library.a
25+
```

lib/darwin/amd64/librq_library.a

20.7 MB
Binary file not shown.

lib/darwin/amd64/librq_library.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/alexey/Work/lumera/rq-library/target/release/librq_library.rlib: /Users/alexey/Work/lumera/rq-library/build.rs /Users/alexey/Work/lumera/rq-library/src/lib.rs /Users/alexey/Work/lumera/rq-library/src/platform.rs /Users/alexey/Work/lumera/rq-library/src/processor.rs
514 KB
Binary file not shown.

0 commit comments

Comments
 (0)