Skip to content

Commit e9d31fc

Browse files
committed
refactor: update documentation for lambda formulas and Android support
- Removed redundant notes about the `fastproto-processor` module from README files. - Clarified that Android projects can directly use the `fastproto` dependency and need to enable annotation processing for lambda formulas. - Updated the Android guide to reflect changes in dependency management and compatibility with lambda expressions. - Enhanced the quick-start guide by removing outdated dependency instructions for core functionality.
1 parent 80f25c4 commit e9d31fc

5 files changed

Lines changed: 44 additions & 68 deletions

File tree

README-zh.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ public class Weather {
162162
}
163163
```
164164

165-
> **注意:** Lambda 公式需要 `fastproto-processor` 模块,请将其添加为 `provided` 作用域的依赖。详见 [Android 指南](docs/android.md)
166-
167-
168165
## *2. 注解*
169166

170167
### *2.1 基本数据类型注解*
@@ -263,17 +260,6 @@ public class Weather {
263260

264261
* *Lambda表达式*
265262

266-
Lambda 公式由 FastProto 注解处理器(`fastproto-processor`)在编译时处理,这确保了与 Android 和 Java 11+ JRE 环境的兼容性。只需添加处理器依赖:
267-
268-
```xml
269-
<dependency>
270-
<groupId>org.indunet</groupId>
271-
<artifactId>fastproto-processor</artifactId>
272-
<version>4.0.0</version>
273-
<scope>provided</scope>
274-
</dependency>
275-
```
276-
277263
```java
278264
import org.indunet.fastproto.annotation.DecodingFormula;
279265
import org.indunet.fastproto.annotation.EncodingFormula;

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ public class Weather {
163163
}
164164
```
165165

166-
> **Note:** Lambda formulas require the `fastproto-processor` module. Add it as a `provided` scope dependency. See [Android guide](docs/android.md) for details.
167-
168166

169167
## *2. Annotations*
170168

@@ -268,17 +266,6 @@ complex formula, it is recommended to customize formula classes by implementing
268266

269267
* *Lambda Expression*
270268

271-
Lambda formulas are processed at compile time by the FastProto annotation processor (`fastproto-processor`). This ensures compatibility with Android and Java 11+ JRE environments. Simply add the processor dependency:
272-
273-
```xml
274-
<dependency>
275-
<groupId>org.indunet</groupId>
276-
<artifactId>fastproto-processor</artifactId>
277-
<version>4.0.0</version>
278-
<scope>provided</scope>
279-
</dependency>
280-
```
281-
282269
```java
283270
import org.indunet.fastproto.annotation.DecodingFormula;
284271
import org.indunet.fastproto.annotation.EncodingFormula;

docs/android.md

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,28 @@ This page summarizes how to use FastProto on Android.
1111

1212
## Lambda Formulas on Android
1313

14-
FastProto provides a separate annotation processor module (`fastproto-processor`) that generates formula classes at compile time. This makes `@DecodingFormula(lambda = "...")` and `@EncodingFormula(lambda = "...")` fully compatible with Android.
14+
FastProto provides compile-time support for lambda formulas so `@DecodingFormula(lambda = "...")` and `@EncodingFormula(lambda = "...")` remain Android-friendly.
1515

1616
### Setup
1717

18-
Android projects need to configure the annotation processor separately (cannot use the `fastproto` bundle directly).
18+
Android projects can use the `fastproto` dependency directly. If you use lambda formulas, make sure annotation processing is enabled in your build.
1919

2020
**Gradle (Kotlin DSL)**:
2121
```kotlin
2222
dependencies {
23-
implementation("org.indunet:fastproto-core:4.1.0")
24-
annotationProcessor("org.indunet:fastproto-processor:4.1.0")
23+
implementation("org.indunet:fastproto:4.1.0")
2524
}
26-
27-
// For Kotlin projects, use kapt instead:
28-
// kapt("org.indunet:fastproto-processor:4.1.0")
2925
```
3026

3127
**Gradle (Groovy DSL)**:
3228
```groovy
3329
dependencies {
34-
implementation 'org.indunet:fastproto-core:4.1.0'
35-
annotationProcessor 'org.indunet:fastproto-processor:4.1.0'
30+
implementation 'org.indunet:fastproto:4.1.0'
3631
}
3732
```
3833

3934
**Maven (Android)**:
4035
```xml
41-
<dependencies>
42-
<dependency>
43-
<groupId>org.indunet</groupId>
44-
<artifactId>fastproto-core</artifactId>
45-
<version>4.1.0</version>
46-
</dependency>
47-
<dependency>
48-
<groupId>org.indunet</groupId>
49-
<artifactId>fastproto-processor</artifactId>
50-
<version>4.1.0</version>
51-
<scope>provided</scope>
52-
</dependency>
53-
</dependencies>
54-
```
55-
56-
**Note:** For standard Maven/Gradle projects (non-Android), simply use the `fastproto` bundle which includes everything:
57-
```xml
5836
<dependency>
5937
<groupId>org.indunet</groupId>
6038
<artifactId>fastproto</artifactId>
@@ -128,7 +106,6 @@ public class SensorData {
128106

129107
## FAQ
130108

131-
- **Can I use lambda formulas on Android?** Yes! The `fastproto-processor` module generates formula classes at compile time, making lambda formulas fully compatible with Android.
132-
- **Why can't I use the `fastproto` bundle on Android?** Android's build system requires explicit annotation processor configuration. The bundle works for standard Maven/Gradle projects but Android needs separate `fastproto-core` + `fastproto-processor` dependencies.
109+
- **Can I use lambda formulas on Android?** Yes. Lambda formulas are generated at compile time, so they are compatible with Android as long as annotation processing is enabled.
133110
- **Do I need the annotation processor?** If you use `@DecodingFormula(lambda = "...")` or `@EncodingFormula(lambda = "...")`, yes. If you only use class-based formulas like `@DecodingFormula(MyFormula.class)`, the annotation processor is optional.
134111
- **Do I need ProGuard rules?** If you rely on reflection/annotations, keep them as shown above. The generated formula classes should also be kept.

docs/help.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<meta name="description" content="FastProto documentation: annotation mapping, byte/bit order, checksum/CRC, formulas, arrays & strings, APIs without annotations, FAQ.">
88
<link rel="icon" href="../logo.png">
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css" data-hljs-theme>
910
<style>
1011
:root{
1112
--bg:#f7f9fc; --card:#ffffff; --text:#111; --muted:#4a5568; --brand:#2563eb; --accent:#059669;
@@ -60,6 +61,7 @@
6061
body{margin:0}
6162
</style>
6263
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
64+
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/highlight.min.js"></script>
6365
<script>
6466
// Fallback loader for marked.js if primary CDN blocked
6567
(function(){
@@ -69,12 +71,45 @@
6971
s.src=src; s.onload=resolve; s.onerror=reject; document.head.appendChild(s);
7072
});
7173
}
74+
function loadCss(href){
75+
return new Promise(function(resolve,reject){
76+
var l=document.createElement('link');
77+
l.rel='stylesheet'; l.href=href; l.onload=resolve; l.onerror=reject;
78+
document.head.appendChild(l);
79+
});
80+
}
81+
function ensureHljsTheme(){
82+
if(document.querySelector('link[data-hljs-theme]')) return;
83+
var themeLink=document.createElement('link');
84+
themeLink.rel='stylesheet';
85+
themeLink.href='https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css';
86+
themeLink.setAttribute('data-hljs-theme','');
87+
document.head.appendChild(themeLink);
88+
}
7289
window.ensureMarked = async function(){
7390
if(window.marked) return;
7491
try{ await loadScript('https://unpkg.com/marked/marked.min.js'); }catch(e){}
7592
if(window.marked) return;
7693
try{ await loadScript('https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.2/marked.min.js'); }catch(e){}
7794
};
95+
window.ensureHljs = async function(){
96+
if(window.hljs) return;
97+
ensureHljsTheme();
98+
try{
99+
await loadScript('https://unpkg.com/highlight.js@11.9.0/lib/highlight.min.js');
100+
return;
101+
}catch(e){}
102+
try{
103+
await loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js');
104+
return;
105+
}catch(e){}
106+
try{
107+
await loadCss('https://unpkg.com/highlight.js@11.9.0/styles/github.min.css');
108+
}catch(e){}
109+
try{
110+
await loadCss('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css');
111+
}catch(e){}
112+
};
78113
})();
79114
</script>
80115
</head>
@@ -174,6 +209,10 @@ <h3>Guides</h3>
174209
if(!window.marked){ await window.ensureMarked(); }
175210
if(window.marked){
176211
docEl.innerHTML = marked.parse(md, { breaks: true });
212+
if(!window.hljs){ await window.ensureHljs(); }
213+
if(window.hljs){
214+
docEl.querySelectorAll('pre code').forEach(block => window.hljs.highlightElement(block));
215+
}
177216
}else{
178217
docEl.innerHTML = '<pre>'+ escapeHtml(md) +'</pre>';
179218
}

docs/quick-start.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ Add the dependency via Maven:
1414
</dependency>
1515
```
1616

17-
This bundle includes both core library and annotation processor for lambda formula support.
18-
19-
For Android projects or if you only need core functionality:
20-
21-
```xml
22-
<!-- Core only (no lambda formula support) -->
23-
<dependency>
24-
<groupId>org.indunet</groupId>
25-
<artifactId>fastproto-core</artifactId>
26-
<version>4.1.0</version>
27-
</dependency>
28-
```
29-
3017
## Define Your Protocol Model
3118

3219
Suppose you receive a 20-byte packet from a weather device.

0 commit comments

Comments
 (0)