You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Automatically manages lengths of variable-sized fields
73
+
- Eliminates manual size calculation and tracking
74
+
- Reduces potential errors in binary protocol implementations
75
+
76
+
### 3. Performance Optimizations
77
+
78
+
- Reflection caching for repeated operations
79
+
- Efficient memory allocation
80
+
- Optimized encoding/decoding paths
81
+
82
+
### 4. Smart Field Tags
71
83
72
84
```go
73
85
typeExamplestruct {
@@ -78,7 +90,7 @@ type Example struct {
78
90
}
79
91
```
80
92
81
-
### 3. Struct Tag Reference
93
+
### 5. Struct Tag Reference
82
94
83
95
The `struc` tag supports various formats and options for precise binary data control:
84
96
@@ -152,10 +164,12 @@ type ByteOrderTypes struct {
152
164
typeSpecialTypesstruct {
153
165
// Skip this field during packing/unpacking
154
166
Ignoredint`struc:"skip"`
167
+
// Completely ignore this field (won't be included in binary)
168
+
Privatestring`struc:"-"`
155
169
// Size reference from another field
156
170
Data []byte`struc:"sizefrom=Size"`
157
171
// Custom type implementation
158
-
CustomCustom
172
+
YourCustomTypeCustomBinaryer
159
173
}
160
174
```
161
175
@@ -165,42 +179,110 @@ Tag Format: `struc:"type,option1,option2"`
165
179
-`big`/`little`: Byte order specification
166
180
-`sizeof=Field`: Specify this field tracks another field's size
167
181
-`sizefrom=Field`: Specify this field's size is tracked by another field
168
-
-`skip`: Skip this field during packing/unpacking
182
+
-`skip`: Skip this field during packing/unpacking (space is reserved in binary)
183
+
-`-`: Completely ignore this field (not included in binary)
169
184
-`[N]type`: Fixed-size array of type with length N
170
185
-`[]type`: Dynamic-size array/slice of type
171
186
172
-
###4. Automatic Size Tracking
187
+
#### Why `omitempty` is not supported?
173
188
174
-
- Automatically manages lengths of variable-sized fields
175
-
- Eliminates manual size calculation and tracking
176
-
- Reduces potential errors in binary protocol implementations
189
+
Unlike JSON serialization where fields can be optionally omitted, binary serialization requires a strict and fixed byte layout. Here's why `omitempty` is not supported:
0 commit comments