This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new a6fdcfb9e chore(rust): refine varint read/write method name (#3590)
a6fdcfb9e is described below
commit a6fdcfb9eb58545a5e9964901968ef5f8fa9c57b
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Apr 20 18:45:05 2026 +0800
chore(rust): refine varint read/write method name (#3590)
## Why?
## What does this PR do?
## Related issues
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
benchmarks/rust/benches/buffer_read_bench.rs | 68 +++++++++++-----------
benchmarks/rust/benches/buffer_write_bench.rs | 48 +++++++--------
cpp/fory/serialization/basic_serializer.h | 12 ++--
cpp/fory/serialization/context.h | 8 +--
cpp/fory/serialization/skip.cc | 4 +-
cpp/fory/serialization/struct_serializer.h | 24 ++++----
cpp/fory/serialization/union_serializer.h | 8 +--
docs/guide/cpp/custom-serializers.md | 8 +--
docs/guide/rust/custom-serializers.md | 8 +--
rust/README.md | 4 +-
rust/fory-core/src/buffer.rs | 59 ++++++++++---------
rust/fory-core/src/meta/meta_string.rs | 2 +-
rust/fory-core/src/meta/type_meta.rs | 36 ++++++------
rust/fory-core/src/resolver/context.rs | 4 +-
rust/fory-core/src/resolver/meta_resolver.rs | 6 +-
.../fory-core/src/resolver/meta_string_resolver.rs | 6 +-
rust/fory-core/src/resolver/ref_resolver.rs | 6 +-
rust/fory-core/src/serializer/array.rs | 4 +-
rust/fory-core/src/serializer/collection.rs | 6 +-
rust/fory-core/src/serializer/datetime.rs | 14 ++---
rust/fory-core/src/serializer/enum_.rs | 6 +-
rust/fory-core/src/serializer/map.rs | 6 +-
rust/fory-core/src/serializer/number.rs | 12 ++--
rust/fory-core/src/serializer/primitive_list.rs | 4 +-
rust/fory-core/src/serializer/skip.rs | 22 +++----
rust/fory-core/src/serializer/string.rs | 4 +-
rust/fory-core/src/serializer/struct_.rs | 2 +-
rust/fory-core/src/serializer/tuple.rs | 8 +--
rust/fory-core/src/serializer/unsigned_number.rs | 12 ++--
rust/fory-derive/src/object/derive_enum.rs | 34 +++++------
rust/fory-derive/src/object/read.rs | 8 +--
rust/fory-derive/src/object/util.rs | 28 ++++-----
rust/fory/src/lib.rs | 4 +-
rust/tests/tests/compatible/test_struct.rs | 4 +-
rust/tests/tests/test_buffer.rs | 18 +++---
rust/tests/tests/test_cross_language.rs | 52 ++++++++---------
36 files changed, 280 insertions(+), 279 deletions(-)
diff --git a/benchmarks/rust/benches/buffer_read_bench.rs
b/benchmarks/rust/benches/buffer_read_bench.rs
index 58c623d58..8e49e1720 100644
--- a/benchmarks/rust/benches/buffer_read_bench.rs
+++ b/benchmarks/rust/benches/buffer_read_bench.rs
@@ -54,20 +54,20 @@ fn prepare_f64_buffer() -> Vec<u8> {
buf
}
-fn prepare_varint32_buffer(multiplier: i32) -> Vec<u8> {
+fn prepare_var_i32_buffer(multiplier: i32) -> Vec<u8> {
let mut buf = Vec::new();
let mut writer = Writer::from_buffer(&mut buf);
for i in 0..1000 {
- writer.write_varint32((i % 1000) * multiplier);
+ writer.write_var_i32((i % 1000) * multiplier);
}
buf
}
-fn prepare_varint64_buffer(multiplier: i64) -> Vec<u8> {
+fn prepare_var_i64_buffer(multiplier: i64) -> Vec<u8> {
let mut buf = Vec::new();
let mut writer = Writer::from_buffer(&mut buf);
for i in 0..1000 {
- writer.write_varint64((i % 1000) * multiplier);
+ writer.write_var_i64((i % 1000) * multiplier);
}
buf
}
@@ -152,18 +152,18 @@ fn bench_read_f64(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint32_small(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint32_small");
+fn bench_read_var_i32_small(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i32_small");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint32_buffer(1); // Small values (1 byte)
+ let buf = prepare_var_i32_buffer(1); // Small values (1 byte)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum += reader.read_varint32().unwrap() as i64;
+ sum += reader.read_var_i32().unwrap() as i64;
}
black_box(sum);
})
@@ -172,18 +172,18 @@ fn bench_read_varint32_small(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint32_medium(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint32_medium");
+fn bench_read_var_i32_medium(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i32_medium");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint32_buffer(1000); // Medium values (2-3 bytes)
+ let buf = prepare_var_i32_buffer(1000); // Medium values (2-3 bytes)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum += reader.read_varint32().unwrap() as i64;
+ sum += reader.read_var_i32().unwrap() as i64;
}
black_box(sum);
})
@@ -192,18 +192,18 @@ fn bench_read_varint32_medium(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint32_large(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint32_large");
+fn bench_read_var_i32_large(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i32_large");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint32_buffer(1000000); // Large values (4-5 bytes)
+ let buf = prepare_var_i32_buffer(1000000); // Large values (4-5 bytes)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum += reader.read_varint32().unwrap() as i64;
+ sum += reader.read_var_i32().unwrap() as i64;
}
black_box(sum);
})
@@ -212,18 +212,18 @@ fn bench_read_varint32_large(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint64_small(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint64_small");
+fn bench_read_var_i64_small(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i64_small");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint64_buffer(1); // Small values (1 byte)
+ let buf = prepare_var_i64_buffer(1); // Small values (1 byte)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum = sum.wrapping_add(reader.read_varint64().unwrap());
+ sum = sum.wrapping_add(reader.read_var_i64().unwrap());
}
black_box(sum);
})
@@ -232,18 +232,18 @@ fn bench_read_varint64_small(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint64_medium(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint64_medium");
+fn bench_read_var_i64_medium(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i64_medium");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint64_buffer(1000000); // Medium values (3-4 bytes)
+ let buf = prepare_var_i64_buffer(1000000); // Medium values (3-4 bytes)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum = sum.wrapping_add(reader.read_varint64().unwrap());
+ sum = sum.wrapping_add(reader.read_var_i64().unwrap());
}
black_box(sum);
})
@@ -252,18 +252,18 @@ fn bench_read_varint64_medium(c: &mut Criterion) {
group.finish();
}
-fn bench_read_varint64_large(c: &mut Criterion) {
- let mut group = c.benchmark_group("read_varint64_large");
+fn bench_read_var_i64_large(c: &mut Criterion) {
+ let mut group = c.benchmark_group("read_var_i64_large");
group.throughput(Throughput::Elements(1000));
- let buf = prepare_varint64_buffer(1000000000000); // Large values (6-9
bytes)
+ let buf = prepare_var_i64_buffer(1000000000000); // Large values (6-9
bytes)
group.bench_function("current", |b| {
b.iter(|| {
let mut reader = Reader::new(&buf);
let mut sum = 0i64;
for _ in 0..1000 {
- sum = sum.wrapping_add(reader.read_varint64().unwrap());
+ sum = sum.wrapping_add(reader.read_var_i64().unwrap());
}
black_box(sum);
})
@@ -278,11 +278,11 @@ criterion_group!(
bench_read_i64,
bench_read_f32,
bench_read_f64,
- bench_read_varint32_small,
- bench_read_varint32_medium,
- bench_read_varint32_large,
- bench_read_varint64_small,
- bench_read_varint64_medium,
- bench_read_varint64_large
+ bench_read_var_i32_small,
+ bench_read_var_i32_medium,
+ bench_read_var_i32_large,
+ bench_read_var_i64_small,
+ bench_read_var_i64_medium,
+ bench_read_var_i64_large
);
criterion_main!(benches);
diff --git a/benchmarks/rust/benches/buffer_write_bench.rs
b/benchmarks/rust/benches/buffer_write_bench.rs
index fd48e6083..a2c9a37cf 100644
--- a/benchmarks/rust/benches/buffer_write_bench.rs
+++ b/benchmarks/rust/benches/buffer_write_bench.rs
@@ -123,8 +123,8 @@ fn bench_write_f64(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint32_small(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint32_small");
+fn bench_write_var_i32_small(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i32_small");
group.throughput(Throughput::Elements(1000));
let values: Vec<i32> = (0..1000).map(|i| i % 128).collect(); // Small
values (1 byte)
@@ -135,7 +135,7 @@ fn bench_write_varint32_small(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint32(black_box(val));
+ writer.write_var_i32(black_box(val));
}
black_box(&buf);
})
@@ -144,8 +144,8 @@ fn bench_write_varint32_small(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint32_medium(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint32_medium");
+fn bench_write_var_i32_medium(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i32_medium");
group.throughput(Throughput::Elements(1000));
let values: Vec<i32> = (0..1000).map(|i| i * 1000).collect(); // Medium
values (2-3 bytes)
@@ -156,7 +156,7 @@ fn bench_write_varint32_medium(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint32(black_box(val));
+ writer.write_var_i32(black_box(val));
}
black_box(&buf);
})
@@ -165,8 +165,8 @@ fn bench_write_varint32_medium(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint32_large(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint32_large");
+fn bench_write_var_i32_large(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i32_large");
group.throughput(Throughput::Elements(1000));
let values: Vec<i32> = (0..1000).map(|i| i * 1000000).collect(); // Large
values (4-5 bytes)
@@ -177,7 +177,7 @@ fn bench_write_varint32_large(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint32(black_box(val));
+ writer.write_var_i32(black_box(val));
}
black_box(&buf);
})
@@ -186,8 +186,8 @@ fn bench_write_varint32_large(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint64_small(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint64_small");
+fn bench_write_var_i64_small(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i64_small");
group.throughput(Throughput::Elements(1000));
let values: Vec<i64> = (0..1000).map(|i| i % 128).collect(); // Small
values (1 byte)
@@ -198,7 +198,7 @@ fn bench_write_varint64_small(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint64(black_box(val));
+ writer.write_var_i64(black_box(val));
}
black_box(&buf);
})
@@ -207,8 +207,8 @@ fn bench_write_varint64_small(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint64_medium(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint64_medium");
+fn bench_write_var_i64_medium(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i64_medium");
group.throughput(Throughput::Elements(1000));
let values: Vec<i64> = (0..1000).map(|i| i * 1000000).collect(); // Medium
values (3-4 bytes)
@@ -219,7 +219,7 @@ fn bench_write_varint64_medium(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint64(black_box(val));
+ writer.write_var_i64(black_box(val));
}
black_box(&buf);
})
@@ -228,8 +228,8 @@ fn bench_write_varint64_medium(c: &mut Criterion) {
group.finish();
}
-fn bench_write_varint64_large(c: &mut Criterion) {
- let mut group = c.benchmark_group("write_varint64_large");
+fn bench_write_var_i64_large(c: &mut Criterion) {
+ let mut group = c.benchmark_group("write_var_i64_large");
group.throughput(Throughput::Elements(1000));
let values: Vec<i64> = (0..1000).map(|i| i as i64 *
1000000000000).collect(); // Large values (6-9 bytes)
@@ -240,7 +240,7 @@ fn bench_write_varint64_large(c: &mut Criterion) {
buf.clear();
let mut writer = Writer::from_buffer(&mut buf);
for &val in &values {
- writer.write_varint64(black_box(val));
+ writer.write_var_i64(black_box(val));
}
black_box(&buf);
})
@@ -256,11 +256,11 @@ criterion_group!(
bench_write_i64,
bench_write_f32,
bench_write_f64,
- bench_write_varint32_small,
- bench_write_varint32_medium,
- bench_write_varint32_large,
- bench_write_varint64_small,
- bench_write_varint64_medium,
- bench_write_varint64_large
+ bench_write_var_i32_small,
+ bench_write_var_i32_medium,
+ bench_write_var_i32_large,
+ bench_write_var_i64_small,
+ bench_write_var_i64_medium,
+ bench_write_var_i64_large
);
criterion_main!(benches);
diff --git a/cpp/fory/serialization/basic_serializer.h
b/cpp/fory/serialization/basic_serializer.h
index 0b3132955..fb4210fa9 100644
--- a/cpp/fory/serialization/basic_serializer.h
+++ b/cpp/fory/serialization/basic_serializer.h
@@ -280,7 +280,7 @@ template <> struct Serializer<int32_t> {
}
static inline void write_data(int32_t value, WriteContext &ctx) {
- ctx.write_varint32(value);
+ ctx.write_var_int32(value);
}
static inline void write_data_generic(int32_t value, WriteContext &ctx,
@@ -305,11 +305,11 @@ template <> struct Serializer<int32_t> {
return 0;
}
}
- return ctx.read_varint32(ctx.error());
+ return ctx.read_var_int32(ctx.error());
}
static inline int32_t read_data(ReadContext &ctx) {
- return ctx.read_varint32(ctx.error());
+ return ctx.read_var_int32(ctx.error());
}
static inline int32_t read_data_generic(ReadContext &ctx, bool) {
@@ -351,7 +351,7 @@ template <> struct Serializer<int64_t> {
}
static inline void write_data(int64_t value, WriteContext &ctx) {
- ctx.write_varint64(value);
+ ctx.write_var_int64(value);
}
static inline void write_data_generic(int64_t value, WriteContext &ctx,
@@ -376,11 +376,11 @@ template <> struct Serializer<int64_t> {
return 0;
}
}
- return ctx.read_varint64(ctx.error());
+ return ctx.read_var_int64(ctx.error());
}
static inline int64_t read_data(ReadContext &ctx) {
- return ctx.read_varint64(ctx.error());
+ return ctx.read_var_int64(ctx.error());
}
static inline int64_t read_data_generic(ReadContext &ctx, bool) {
diff --git a/cpp/fory/serialization/context.h b/cpp/fory/serialization/context.h
index 3c15dec81..1dd270f56 100644
--- a/cpp/fory/serialization/context.h
+++ b/cpp/fory/serialization/context.h
@@ -239,7 +239,7 @@ public:
}
/// write int32_t value as zigzag varint to buffer.
- FORY_ALWAYS_INLINE void write_varint32(int32_t value) {
+ FORY_ALWAYS_INLINE void write_var_int32(int32_t value) {
buffer_.write_var_int32(value);
}
@@ -249,7 +249,7 @@ public:
}
/// write int64_t value as zigzag varint to buffer.
- FORY_ALWAYS_INLINE void write_varint64(int64_t value) {
+ FORY_ALWAYS_INLINE void write_var_int64(int64_t value) {
buffer_.write_var_int64(value);
}
@@ -569,7 +569,7 @@ public:
}
/// Read int32_t value as zigzag varint from buffer. Sets error on failure.
- FORY_ALWAYS_INLINE int32_t read_varint32(Error &error) {
+ FORY_ALWAYS_INLINE int32_t read_var_int32(Error &error) {
return buffer().read_var_int32(error);
}
@@ -579,7 +579,7 @@ public:
}
/// Read int64_t value as zigzag varint from buffer. Sets error on failure.
- FORY_ALWAYS_INLINE int64_t read_varint64(Error &error) {
+ FORY_ALWAYS_INLINE int64_t read_var_int64(Error &error) {
return buffer().read_var_int64(error);
}
diff --git a/cpp/fory/serialization/skip.cc b/cpp/fory/serialization/skip.cc
index 3a89e295a..15e8bbb94 100644
--- a/cpp/fory/serialization/skip.cc
+++ b/cpp/fory/serialization/skip.cc
@@ -507,7 +507,7 @@ void skip_field_value(ReadContext &ctx, const FieldType
&field_type,
// INT32 values are encoded as varint32 in the C++
// serializer, so we must consume a varint32 here
// instead of assuming fixed-width encoding.
- ctx.read_varint32(ctx.error());
+ ctx.read_var_int32(ctx.error());
return;
}
@@ -519,7 +519,7 @@ void skip_field_value(ReadContext &ctx, const FieldType
&field_type,
// INT64 values are encoded as varint64 in the C++
// serializer, so we must consume a varint64 here
// instead of assuming fixed-width encoding.
- ctx.read_varint64(ctx.error());
+ ctx.read_var_int64(ctx.error());
return;
}
diff --git a/cpp/fory/serialization/struct_serializer.h
b/cpp/fory/serialization/struct_serializer.h
index c9b4eb05b..71fcaff9e 100644
--- a/cpp/fory/serialization/struct_serializer.h
+++ b/cpp/fory/serialization/struct_serializer.h
@@ -446,9 +446,9 @@ FORY_ALWAYS_INLINE FieldType
read_configurable_int(ReadContext &ctx) {
return static_cast<FieldType>(ctx.read_tagged_int64(ctx.error()));
}
if constexpr (is_configurable_int32_v<FieldType>) {
- return static_cast<FieldType>(ctx.read_varint32(ctx.error()));
+ return static_cast<FieldType>(ctx.read_var_int32(ctx.error()));
}
- return static_cast<FieldType>(ctx.read_varint64(ctx.error()));
+ return static_cast<FieldType>(ctx.read_var_int64(ctx.error()));
} else {
if constexpr (enc == Encoding::Varint) {
if constexpr (is_configurable_int32_v<FieldType>) {
@@ -1880,7 +1880,7 @@ void write_single_field(const T &obj, WriteContext &ctx,
if constexpr (enc == Encoding::Fixed) {
ctx.buffer().write_int32(static_cast<int32_t>(value));
} else {
- ctx.write_varint32(static_cast<int32_t>(value));
+ ctx.write_var_int32(static_cast<int32_t>(value));
}
} else if constexpr (std::is_same_v<InnerType, int64_t> ||
std::is_same_v<InnerType, long long>) {
@@ -1889,7 +1889,7 @@ void write_single_field(const T &obj, WriteContext &ctx,
} else if constexpr (enc == Encoding::Tagged) {
ctx.write_tagged_int64(static_cast<int64_t>(value));
} else {
- ctx.write_varint64(static_cast<int64_t>(value));
+ ctx.write_var_int64(static_cast<int64_t>(value));
}
}
return;
@@ -1927,7 +1927,7 @@ void write_single_field(const T &obj, WriteContext &ctx,
if constexpr (enc == Encoding::Fixed) {
ctx.buffer().write_int32(static_cast<int32_t>(field_value));
} else {
- ctx.write_varint32(static_cast<int32_t>(field_value));
+ ctx.write_var_int32(static_cast<int32_t>(field_value));
}
return;
} else if constexpr (std::is_same_v<FieldType, int64_t> ||
@@ -1937,7 +1937,7 @@ void write_single_field(const T &obj, WriteContext &ctx,
} else if constexpr (enc == Encoding::Tagged) {
ctx.write_tagged_int64(static_cast<int64_t>(field_value));
} else {
- ctx.write_varint64(static_cast<int64_t>(field_value));
+ ctx.write_var_int64(static_cast<int64_t>(field_value));
}
return;
}
@@ -2098,7 +2098,7 @@ FORY_ALWAYS_INLINE TargetType
read_primitive_by_type_id(ReadContext &ctx,
return static_cast<TargetType>(ctx.read_int32(error));
case TypeId::VARINT32:
// VARINT32 uses varint encoding
- return static_cast<TargetType>(ctx.read_varint32(error));
+ return static_cast<TargetType>(ctx.read_var_int32(error));
case TypeId::UINT32:
// UINT32 uses fixed 4-byte encoding
return static_cast<TargetType>(
@@ -2111,7 +2111,7 @@ FORY_ALWAYS_INLINE TargetType
read_primitive_by_type_id(ReadContext &ctx,
return static_cast<TargetType>(ctx.read_int64(error));
case TypeId::VARINT64:
// VARINT64 uses varint encoding
- return static_cast<TargetType>(ctx.read_varint64(error));
+ return static_cast<TargetType>(ctx.read_var_int64(error));
case TypeId::TAGGED_INT64:
// TAGGED_INT64 uses tagged encoding (special hybrid encoding)
return static_cast<TargetType>(ctx.read_tagged_int64(error));
@@ -2176,13 +2176,13 @@ FORY_ALWAYS_INLINE FieldType
read_primitive_field_direct(ReadContext &ctx,
return static_cast<uint16_t>(v);
} else if constexpr (std::is_same_v<FieldType, int32_t>) {
// int32_t uses varint encoding
- return ctx.read_varint32(error);
+ return ctx.read_var_int32(error);
} else if constexpr (std::is_same_v<FieldType, uint32_t>) {
// uint32_t uses fixed 4-byte encoding (not varint!)
return static_cast<uint32_t>(ctx.read_int32(error));
} else if constexpr (std::is_same_v<FieldType, int64_t>) {
// int64_t uses varint encoding
- return ctx.read_varint64(error);
+ return ctx.read_var_int64(error);
} else if constexpr (std::is_same_v<FieldType, uint64_t>) {
// uint64_t uses fixed 8-byte encoding (not varint!)
return static_cast<uint64_t>(ctx.read_int64(error));
@@ -2344,7 +2344,7 @@ void read_single_field_by_index(T &obj, ReadContext &ctx)
{
if constexpr (enc == Encoding::Fixed) {
value = static_cast<InnerType>(ctx.read_int32(ctx.error()));
} else {
- value = static_cast<InnerType>(ctx.read_varint32(ctx.error()));
+ value = static_cast<InnerType>(ctx.read_var_int32(ctx.error()));
}
} else if constexpr (std::is_same_v<InnerType, int64_t> ||
std::is_same_v<InnerType, long long>) {
@@ -2353,7 +2353,7 @@ void read_single_field_by_index(T &obj, ReadContext &ctx)
{
} else if constexpr (enc == Encoding::Tagged) {
value = static_cast<InnerType>(ctx.read_tagged_int64(ctx.error()));
} else {
- value = static_cast<InnerType>(ctx.read_varint64(ctx.error()));
+ value = static_cast<InnerType>(ctx.read_var_int64(ctx.error()));
}
}
if constexpr (is_fory_field_v<RawFieldType>) {
diff --git a/cpp/fory/serialization/union_serializer.h
b/cpp/fory/serialization/union_serializer.h
index 47ab55fae..c90d3d0d2 100644
--- a/cpp/fory/serialization/union_serializer.h
+++ b/cpp/fory/serialization/union_serializer.h
@@ -327,13 +327,13 @@ inline void write_union_value_data(const T &value,
WriteContext &ctx,
ctx.write_tagged_uint64(static_cast<uint64_t>(inner));
return;
case TypeId::VARINT32:
- ctx.write_varint32(static_cast<int32_t>(inner));
+ ctx.write_var_int32(static_cast<int32_t>(inner));
return;
case TypeId::INT32:
ctx.buffer().write_int32(static_cast<int32_t>(inner));
return;
case TypeId::VARINT64:
- ctx.write_varint64(static_cast<int64_t>(inner));
+ ctx.write_var_int64(static_cast<int64_t>(inner));
return;
case TypeId::INT64:
ctx.buffer().write_int64(static_cast<int64_t>(inner));
@@ -370,13 +370,13 @@ inline T read_union_value_data(ReadContext &ctx, uint32_t
type_id) {
value = static_cast<Inner>(ctx.read_tagged_uint64(ctx.error()));
break;
case TypeId::VARINT32:
- value = static_cast<Inner>(ctx.read_varint32(ctx.error()));
+ value = static_cast<Inner>(ctx.read_var_int32(ctx.error()));
break;
case TypeId::INT32:
value = static_cast<Inner>(ctx.read_int32(ctx.error()));
break;
case TypeId::VARINT64:
- value = static_cast<Inner>(ctx.read_varint64(ctx.error()));
+ value = static_cast<Inner>(ctx.read_var_int64(ctx.error()));
break;
case TypeId::INT64:
value = static_cast<Inner>(ctx.read_int64(ctx.error()));
diff --git a/docs/guide/cpp/custom-serializers.md
b/docs/guide/cpp/custom-serializers.md
index 844153715..478b4e899 100644
--- a/docs/guide/cpp/custom-serializers.md
+++ b/docs/guide/cpp/custom-serializers.md
@@ -290,9 +290,9 @@ ctx.write_uint16(value);
// Variable-length integers (compact encoding)
ctx.write_var_uint32(value); // Unsigned varint
-ctx.write_varint32(value); // Signed zigzag varint
+ctx.write_var_int32(value); // Signed zigzag varint
ctx.write_var_uint64(value); // Unsigned varint
-ctx.write_varint64(value); // Signed zigzag varint
+ctx.write_var_int64(value); // Signed zigzag varint
// Tagged integers (for mixed-size encoding)
ctx.write_tagged_uint64(value);
@@ -318,9 +318,9 @@ int8_t i8 = ctx.read_int8(ctx.error());
// Variable-length integers
uint32_t u32 = ctx.read_var_uint32(ctx.error());
-int32_t i32 = ctx.read_varint32(ctx.error());
+int32_t i32 = ctx.read_var_int32(ctx.error());
uint64_t u64 = ctx.read_var_uint64(ctx.error());
-int64_t i64 = ctx.read_varint64(ctx.error());
+int64_t i64 = ctx.read_var_int64(ctx.error());
// Check for errors after read operations
if (ctx.has_error()) {
diff --git a/docs/guide/rust/custom-serializers.md
b/docs/guide/rust/custom-serializers.md
index a9d366687..87c552367 100644
--- a/docs/guide/rust/custom-serializers.md
+++ b/docs/guide/rust/custom-serializers.md
@@ -112,8 +112,8 @@ context.writer.write_f64(value);
context.writer.write_bool(value);
// Variable-length integers
-context.writer.write_varint32(value);
-context.writer.write_varuint32(value);
+context.writer.write_var_i32(value);
+context.writer.write_var_u32(value);
// Strings
context.writer.write_utf8_string(&string);
@@ -132,8 +132,8 @@ let value = context.reader.read_f64();
let value = context.reader.read_bool();
// Variable-length integers
-let value = context.reader.read_varint32();
-let value = context.reader.read_varuint32();
+let value = context.reader.read_var_i32();
+let value = context.reader.read_var_u32();
// Strings
let string = context.reader.read_utf8_string(len);
diff --git a/rust/README.md b/rust/README.md
index aed83968f..40ac4549e 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -468,13 +468,13 @@ struct CustomType {
impl Serializer for CustomType {
fn fory_write_data(&self, context: &mut WriteContext, is_field: bool) {
context.writer.write_i32(self.value);
- context.writer.write_varuint32(self.name.len() as u32);
+ context.writer.write_var_u32(self.name.len() as u32);
context.writer.write_utf8_string(&self.name);
}
fn fory_read_data(context: &mut ReadContext, is_field: bool) ->
Result<Self, Error> {
let value = context.reader.read_i32();
- let len = context.reader.read_varuint32() as usize;
+ let len = context.reader.read_var_u32() as usize;
let name = context.reader.read_utf8_string(len);
Ok(Self { value, name })
}
diff --git a/rust/fory-core/src/buffer.rs b/rust/fory-core/src/buffer.rs
index 4cab51acf..7caa63697 100644
--- a/rust/fory-core/src/buffer.rs
+++ b/rust/fory-core/src/buffer.rs
@@ -113,9 +113,9 @@ impl<'a> Writer<'a> {
// ============ VARINT32 (TypeId = 5) ============
#[inline(always)]
- pub fn write_varint32(&mut self, value: i32) {
+ pub fn write_var_i32(&mut self, value: i32) {
let zigzag = ((value as i64) << 1) ^ ((value as i64) >> 31);
- self._write_var_uint32(zigzag as u32)
+ self._write_var_u32(zigzag as u32)
}
// ============ INT64 (TypeId = 6) ============
@@ -128,9 +128,9 @@ impl<'a> Writer<'a> {
// ============ VARINT64 (TypeId = 7) ============
#[inline(always)]
- pub fn write_varint64(&mut self, value: i64) {
+ pub fn write_var_i64(&mut self, value: i64) {
let zigzag = ((value << 1) ^ (value >> 63)) as u64;
- self._write_var_uint64(zigzag);
+ self._write_var_u64(zigzag);
}
// ============ TAGGED_INT64 (TypeId = 8) ============
@@ -194,12 +194,12 @@ impl<'a> Writer<'a> {
// ============ VAR_UINT32 (TypeId = 12) ============
#[inline(always)]
- pub fn write_var_uint32(&mut self, value: u32) {
- self._write_var_uint32(value)
+ pub fn write_var_u32(&mut self, value: u32) {
+ self._write_var_u32(value)
}
#[inline(always)]
- fn _write_var_uint32(&mut self, value: u32) {
+ fn _write_var_u32(&mut self, value: u32) {
if value < 0x80 {
self.bf.push(value as u8);
} else if value < 0x4000 {
@@ -255,12 +255,12 @@ impl<'a> Writer<'a> {
// ============ VAR_UINT64 (TypeId = 14) ============
#[inline(always)]
- pub fn write_var_uint64(&mut self, value: u64) {
- self._write_var_uint64(value);
+ pub fn write_var_u64(&mut self, value: u64) {
+ self._write_var_u64(value);
}
#[inline(always)]
- fn _write_var_uint64(&mut self, value: u64) {
+ fn _write_var_u64(&mut self, value: u64) {
if value < 0x80 {
self.bf.push(value as u8);
} else if value < 0x4000 {
@@ -447,8 +447,8 @@ impl<'a> Writer<'a> {
const SIZE: usize = std::mem::size_of::<isize>();
match SIZE {
2 => self.write_i16(value as i16),
- 4 => self.write_varint32(value as i32),
- 8 => self.write_varint64(value as i64),
+ 4 => self.write_var_i32(value as i32),
+ 8 => self.write_var_i64(value as i64),
_ => unreachable!("unsupported isize size"),
}
}
@@ -458,8 +458,8 @@ impl<'a> Writer<'a> {
const SIZE: usize = std::mem::size_of::<usize>();
match SIZE {
2 => self.write_u16(value as u16),
- 4 => self.write_var_uint32(value as u32),
- 8 => self.write_var_uint64(value as u64),
+ 4 => self.write_var_u32(value as u32),
+ 8 => self.write_var_u64(value as u64),
_ => unreachable!("unsupported usize size"),
}
}
@@ -467,8 +467,11 @@ impl<'a> Writer<'a> {
// ============ Other helper methods ============
#[inline(always)]
- pub fn write_var_uint36_small(&mut self, value: u64) {
- assert!(value < (1u64 << 36), "value too large for 36-bit varint");
+ pub fn write_var_u36_small(&mut self, value: u64) {
+ assert!(
+ value < (1u64 << 36),
+ "value too large for 36-bit variable-length integer"
+ );
if value < 0x80 {
self.bf.push(value as u8);
} else if value < 0x4000 {
@@ -641,8 +644,8 @@ impl<'a> Reader<'a> {
// ============ VARINT32 (TypeId = 5) ============
#[inline(always)]
- pub fn read_varint32(&mut self) -> Result<i32, Error> {
- let encoded = self.read_varuint32()?;
+ pub fn read_var_i32(&mut self) -> Result<i32, Error> {
+ let encoded = self.read_var_u32()?;
Ok(((encoded >> 1) as i32) ^ -((encoded & 1) as i32))
}
@@ -656,8 +659,8 @@ impl<'a> Reader<'a> {
// ============ VARINT64 (TypeId = 7) ============
#[inline(always)]
- pub fn read_varint64(&mut self) -> Result<i64, Error> {
- let encoded = self.read_varuint64()?;
+ pub fn read_var_i64(&mut self) -> Result<i64, Error> {
+ let encoded = self.read_var_u64()?;
Ok(((encoded >> 1) as i64) ^ -((encoded & 1) as i64))
}
@@ -722,7 +725,7 @@ impl<'a> Reader<'a> {
// ============ VAR_UINT32 (TypeId = 12) ============
#[inline(always)]
- pub fn read_varuint32(&mut self) -> Result<u32, Error> {
+ pub fn read_var_u32(&mut self) -> Result<u32, Error> {
let b0 = self.value_at(self.cursor)? as u32;
if b0 < 0x80 {
self.move_next(1);
@@ -769,7 +772,7 @@ impl<'a> Reader<'a> {
// ============ VAR_UINT64 (TypeId = 14) ============
#[inline(always)]
- pub fn read_varuint64(&mut self) -> Result<u64, Error> {
+ pub fn read_var_u64(&mut self) -> Result<u64, Error> {
let b0 = self.value_at(self.cursor)? as u64;
if b0 < 0x80 {
self.move_next(1);
@@ -979,8 +982,8 @@ impl<'a> Reader<'a> {
const SIZE: usize = std::mem::size_of::<isize>();
match SIZE {
2 => Ok(self.read_i16()? as isize),
- 4 => Ok(self.read_varint32()? as isize),
- 8 => Ok(self.read_varint64()? as isize),
+ 4 => Ok(self.read_var_i32()? as isize),
+ 8 => Ok(self.read_var_i64()? as isize),
_ => unreachable!("unsupported isize size"),
}
}
@@ -990,8 +993,8 @@ impl<'a> Reader<'a> {
const SIZE: usize = std::mem::size_of::<usize>();
match SIZE {
2 => Ok(self.read_u16()? as usize),
- 4 => Ok(self.read_varuint32()? as usize),
- 8 => Ok(self.read_varuint64()? as usize),
+ 4 => Ok(self.read_var_u32()? as usize),
+ 8 => Ok(self.read_var_u64()? as usize),
_ => unreachable!("unsupported usize size"),
}
}
@@ -999,7 +1002,7 @@ impl<'a> Reader<'a> {
// ============ Other helper methods ============
#[inline(always)]
- pub fn read_varuint36small(&mut self) -> Result<u64, Error> {
+ pub fn read_var_u36_small(&mut self) -> Result<u64, Error> {
// Keep this API panic-free even if cursor is externally set past
buffer end.
self.check_bound(0)?;
let start = self.cursor;
@@ -1041,7 +1044,7 @@ impl<'a> Reader<'a> {
}
shift += 7;
if shift >= 36 {
- return Err(Error::encode_error("varuint36small overflow"));
+ return Err(Error::encode_error("var_u36_small overflow"));
}
}
Ok(result)
diff --git a/rust/fory-core/src/meta/meta_string.rs
b/rust/fory-core/src/meta/meta_string.rs
index 585fb926a..6ee818f95 100644
--- a/rust/fory-core/src/meta/meta_string.rs
+++ b/rust/fory-core/src/meta/meta_string.rs
@@ -95,7 +95,7 @@ impl MetaString {
}
pub fn write_to(&self, writer: &mut crate::buffer::Writer) {
- writer.write_var_uint32(self.bytes.len() as u32);
+ writer.write_var_u32(self.bytes.len() as u32);
writer.write_bytes(&self.bytes);
}
diff --git a/rust/fory-core/src/meta/type_meta.rs
b/rust/fory-core/src/meta/type_meta.rs
index 1bb5fd135..81154997d 100644
--- a/rust/fory-core/src/meta/type_meta.rs
+++ b/rust/fory-core/src/meta/type_meta.rs
@@ -145,7 +145,7 @@ impl FieldType {
if self.track_ref {
header |= 1;
}
- writer.write_var_uint32(header);
+ writer.write_var_u32(header);
} else {
writer.write_u8(header as u8);
}
@@ -177,7 +177,7 @@ impl FieldType {
nullable: Option<bool>,
) -> Result<Self, Error> {
let header = if read_flag {
- reader.read_varuint32()?
+ reader.read_var_u32()?
} else {
reader.read_u8()? as u32
};
@@ -279,7 +279,7 @@ impl FieldInfo {
let mut field_id = ((header >> 2) & FIELD_NAME_SIZE_THRESHOLD as
u8) as i16;
if field_id == SMALL_FIELD_ID_THRESHOLD {
field_id = field_id
- .checked_add(reader.read_varuint32()? as i16)
+ .checked_add(reader.read_var_u32()? as i16)
.ok_or_else(|| Error::invalid_data("field_id overflow"))?;
}
@@ -296,7 +296,7 @@ impl FieldInfo {
let encoding = Self::u8_to_encoding(encoding_bits)?;
let mut name_size = ((header >> 2) & FIELD_NAME_SIZE_THRESHOLD as
u8) as usize;
if name_size == FIELD_NAME_SIZE_THRESHOLD {
- name_size += reader.read_varuint32()? as usize;
+ name_size += reader.read_var_u32()? as usize;
}
name_size += 1;
@@ -338,7 +338,7 @@ impl FieldInfo {
header |= FIELD_ID_ENCODING_MARKER << 6;
writer.write_u8(header);
if field_id >= SMALL_FIELD_ID_THRESHOLD {
- writer.write_var_uint32((field_id - SMALL_FIELD_ID_THRESHOLD)
as u32);
+ writer.write_var_u32((field_id - SMALL_FIELD_ID_THRESHOLD) as
u32);
}
self.field_type.to_bytes(&mut writer, false, nullable)?;
// No field name written in ID mode
@@ -364,7 +364,7 @@ impl FieldInfo {
header |= encoding_idx << 6;
writer.write_u8(header);
if name_size >= FIELD_NAME_SIZE_THRESHOLD {
- writer.write_var_uint32((name_size -
FIELD_NAME_SIZE_THRESHOLD) as u32);
+ writer.write_var_u32((name_size - FIELD_NAME_SIZE_THRESHOLD)
as u32);
}
self.field_type.to_bytes(&mut writer, false, nullable)?;
// write field_name
@@ -614,7 +614,7 @@ impl TypeMeta {
let bytes = name.bytes.as_slice();
if bytes.len() >= BIG_NAME_THRESHOLD {
writer.write_u8((BIG_NAME_THRESHOLD << 2) as u8 | encoding_idx);
- writer.write_var_uint32((bytes.len() - BIG_NAME_THRESHOLD) as u32);
+ writer.write_var_u32((bytes.len() - BIG_NAME_THRESHOLD) as u32);
} else {
writer.write_u8((bytes.len() << 2) as u8 | encoding_idx);
}
@@ -638,7 +638,7 @@ impl TypeMeta {
let encoding_idx = header & 0b11;
let length = header >> 2;
let length = if length >= BIG_NAME_THRESHOLD as u8 {
- BIG_NAME_THRESHOLD + reader.read_varuint32()? as usize
+ BIG_NAME_THRESHOLD + reader.read_var_u32()? as usize
} else {
length as usize
};
@@ -670,7 +670,7 @@ impl TypeMeta {
}
writer.write_u8(meta_header);
if num_fields >= SMALL_NUM_FIELDS_THRESHOLD {
- writer.write_var_uint32((num_fields - SMALL_NUM_FIELDS_THRESHOLD)
as u32);
+ writer.write_var_u32((num_fields - SMALL_NUM_FIELDS_THRESHOLD) as
u32);
}
if self.register_by_name {
self.write_namespace(&mut writer);
@@ -682,7 +682,7 @@ impl TypeMeta {
"User type id is required for this type id",
));
}
- writer.write_var_uint32(self.user_type_id);
+ writer.write_var_u32(self.user_type_id);
}
for field in self.field_infos.iter() {
writer.write_bytes(field.to_bytes()?.as_slice());
@@ -819,7 +819,7 @@ impl TypeMeta {
let register_by_name = (meta_header & REGISTER_BY_NAME_FLAG) != 0;
let mut num_fields = meta_header as usize & SMALL_NUM_FIELDS_THRESHOLD;
if num_fields == SMALL_NUM_FIELDS_THRESHOLD {
- num_fields += reader.read_varuint32()? as usize;
+ num_fields += reader.read_var_u32()? as usize;
}
// limit the number of fields to prevent potential OOM when creating
Vec<FieldInfo>
if num_fields > MAX_TYPE_META_FIELDS {
@@ -838,7 +838,7 @@ impl TypeMeta {
type_id = 0;
} else {
type_id = reader.read_u8()? as u32;
- user_type_id = reader.read_varuint32()?;
+ user_type_id = reader.read_var_u32()?;
let empty_name = MetaString::default();
namespace = empty_name.clone();
type_name = empty_name;
@@ -978,8 +978,8 @@ impl TypeMeta {
let header = reader.read_i64()?;
let meta_size = header & META_SIZE_MASK;
if meta_size == META_SIZE_MASK {
- // meta_size += reader.read_varuint32() as i64;
- reader.read_varuint32()?;
+ // meta_size += reader.read_var_u32() as i64;
+ reader.read_var_u32()?;
}
// let write_fields_meta = (header & HAS_FIELDS_META_FLAG) != 0;
@@ -1000,8 +1000,8 @@ impl TypeMeta {
) -> Result<TypeMeta, Error> {
let meta_size = header & META_SIZE_MASK;
if meta_size == META_SIZE_MASK {
- // meta_size += reader.read_varuint32()? as i64;
- reader.read_varuint32()?;
+ // meta_size += reader.read_var_u32()? as i64;
+ reader.read_var_u32()?;
}
// let write_fields_meta = (header & HAS_FIELDS_META_FLAG) != 0;
@@ -1019,7 +1019,7 @@ impl TypeMeta {
pub fn skip_bytes(reader: &mut Reader, header: i64) -> Result<(), Error> {
let mut meta_size = header & META_SIZE_MASK;
if meta_size == META_SIZE_MASK {
- meta_size += reader.read_varuint32()? as i64;
+ meta_size += reader.read_var_u32()? as i64;
}
reader.skip(meta_size as usize)
}
@@ -1067,7 +1067,7 @@ impl TypeMeta {
header |= meta_hash_shifted;
result.write_i64(header);
if meta_size >= META_SIZE_MASK {
- result.write_var_uint32((meta_size - META_SIZE_MASK) as u32);
+ result.write_var_u32((meta_size - META_SIZE_MASK) as u32);
}
result.write_bytes(meta_buffer.as_slice());
Ok((buffer, meta_hash))
diff --git a/rust/fory-core/src/resolver/context.rs
b/rust/fory-core/src/resolver/context.rs
index 42bd19783..16c14bf1d 100644
--- a/rust/fory-core/src/resolver/context.rs
+++ b/rust/fory-core/src/resolver/context.rs
@@ -243,7 +243,7 @@ impl<'a> WriteContext<'a> {
match fory_type_id {
TypeId::ENUM | TypeId::STRUCT | TypeId::EXT | TypeId::TYPED_UNION
=> {
let user_type_id = type_info.get_user_type_id();
- self.writer.write_var_uint32(user_type_id);
+ self.writer.write_var_u32(user_type_id);
}
TypeId::COMPATIBLE_STRUCT | TypeId::NAMED_COMPATIBLE_STRUCT => {
// Write type meta inline using streaming protocol
@@ -437,7 +437,7 @@ impl<'a> ReadContext<'a> {
// should be compiled to jump table generation
match fory_type_id {
types::ENUM | types::STRUCT | types::EXT | types::TYPED_UNION => {
- let user_type_id = self.reader.read_varuint32()?;
+ let user_type_id = self.reader.read_var_u32()?;
self.type_resolver
.get_user_type_info_by_id(user_type_id)
.ok_or_else(|| Error::type_error("ID harness not found"))
diff --git a/rust/fory-core/src/resolver/meta_resolver.rs
b/rust/fory-core/src/resolver/meta_resolver.rs
index 1f1af26c8..b680461ca 100644
--- a/rust/fory-core/src/resolver/meta_resolver.rs
+++ b/rust/fory-core/src/resolver/meta_resolver.rs
@@ -48,12 +48,12 @@ impl MetaWriterResolver {
match self.type_id_index_map.get(&type_id) {
Some(&index) => {
// Reference to previously written type: (index << 1) | 1,
LSB=1
- writer.write_var_uint32(((index as u32) << 1) | 1);
+ writer.write_var_u32(((index as u32) << 1) | 1);
}
None => {
// New type: index << 1, LSB=0, followed by TypeMeta bytes
inline
let index = self.type_id_index_map.len();
- writer.write_var_uint32((index as u32) << 1);
+ writer.write_var_u32((index as u32) << 1);
self.type_id_index_map.insert(type_id, index);
// Write TypeMeta bytes inline
let type_def =
type_resolver.get_type_info(&type_id)?.get_type_def();
@@ -95,7 +95,7 @@ impl MetaReaderResolver {
reader: &mut Reader,
type_resolver: &TypeResolver,
) -> Result<Rc<TypeInfo>, Error> {
- let index_marker = reader.read_varuint32()?;
+ let index_marker = reader.read_var_u32()?;
let is_ref = (index_marker & 1) == 1;
let index = (index_marker >> 1) as usize;
diff --git a/rust/fory-core/src/resolver/meta_string_resolver.rs
b/rust/fory-core/src/resolver/meta_string_resolver.rs
index fb47acc88..705308ddf 100644
--- a/rust/fory-core/src/resolver/meta_string_resolver.rs
+++ b/rust/fory-core/src/resolver/meta_string_resolver.rs
@@ -137,7 +137,7 @@ impl MetaStringWriterResolver {
let mb_ptr: *const MetaStringBytes = mb_ref as *const _;
let id = if let Some(exist_id) = self.bytes_id_map.get_mut(&mb_ptr) {
if *exist_id != MetaStringBytes::DEFAULT_DYNAMIC_WRITE_STRING_ID {
- writer.write_var_uint32(((*exist_id as u32 + 1) << 1) | 1);
+ writer.write_var_u32(((*exist_id as u32 + 1) << 1) | 1);
return Ok(());
}
let id = self.dynamic_write_id;
@@ -156,7 +156,7 @@ impl MetaStringWriterResolver {
self.dynamic_written[id] = mb_ptr;
let len = mb_ref.bytes.len();
- writer.write_var_uint32((len as u32) << 1);
+ writer.write_var_u32((len as u32) << 1);
if len > Self::SMALL_STRING_THRESHOLD {
writer.write_i64(mb_ref.hash_code);
} else if len != 0 {
@@ -237,7 +237,7 @@ impl MetaStringReaderResolver {
&mut self,
reader: &mut Reader,
) -> Result<&MetaStringBytes, Error> {
- let header = reader.read_varuint32()?;
+ let header = reader.read_var_u32()?;
let len = (header >> 1) as usize;
if (header & 0b1) == 0 {
diff --git a/rust/fory-core/src/resolver/ref_resolver.rs
b/rust/fory-core/src/resolver/ref_resolver.rs
index f51de3154..1a26ed749 100644
--- a/rust/fory-core/src/resolver/ref_resolver.rs
+++ b/rust/fory-core/src/resolver/ref_resolver.rs
@@ -86,7 +86,7 @@ impl RefWriter {
if let Some(&ref_id) = self.refs.get(&ptr_addr) {
writer.write_i8(RefFlag::Ref as i8);
- writer.write_var_uint32(ref_id);
+ writer.write_var_u32(ref_id);
true
} else {
let ref_id = self.next_ref_id;
@@ -119,7 +119,7 @@ impl RefWriter {
if let Some(&ref_id) = self.refs.get(&ptr_addr) {
// This object has been seen before, write a reference
writer.write_i8(RefFlag::Ref as i8);
- writer.write_var_uint32(ref_id);
+ writer.write_var_u32(ref_id);
true
} else {
// First time seeing this object, register it and return false
@@ -341,7 +341,7 @@ impl RefReader {
/// The reference ID as a u32
#[inline(always)]
pub fn read_ref_id(&self, reader: &mut Reader) -> Result<u32, Error> {
- reader.read_varuint32()
+ reader.read_var_u32()
}
/// Execute all pending callbacks to resolve weak pointer references.
diff --git a/rust/fory-core/src/serializer/array.rs
b/rust/fory-core/src/serializer/array.rs
index 3e2a6d066..57d56ddf8 100644
--- a/rust/fory-core/src/serializer/array.rs
+++ b/rust/fory-core/src/serializer/array.rs
@@ -63,7 +63,7 @@ where
T: Serializer + ForyDefault,
{
// Read the size in bytes
- let size_bytes = context.reader.read_varuint32()? as usize;
+ let size_bytes = context.reader.read_var_u32()? as usize;
let elem_size = mem::size_of::<T>();
if size_bytes % elem_size != 0 {
return Err(Error::invalid_data("Invalid data length"));
@@ -94,7 +94,7 @@ where
T: Serializer + ForyDefault,
{
// Read collection length
- let len = context.reader.read_varuint32()? as usize;
+ let len = context.reader.read_var_u32()? as usize;
validate_array_length(len, N)?;
// Handle zero-sized arrays
if N == 0 {
diff --git a/rust/fory-core/src/serializer/collection.rs
b/rust/fory-core/src/serializer/collection.rs
index cdd3c1dc6..2b590daee 100644
--- a/rust/fory-core/src/serializer/collection.rs
+++ b/rust/fory-core/src/serializer/collection.rs
@@ -70,7 +70,7 @@ where
{
let iter = iter.into_iter();
let len = iter.len();
- context.writer.write_var_uint32(len as u32);
+ context.writer.write_var_u32(len as u32);
if len == 0 {
return Ok(());
}
@@ -246,7 +246,7 @@ where
T: Serializer + ForyDefault,
C: FromIterator<T>,
{
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
if len == 0 {
return Ok(C::from_iter(std::iter::empty()));
}
@@ -292,7 +292,7 @@ pub fn read_vec_data<T>(context: &mut ReadContext) ->
Result<Vec<T>, Error>
where
T: Serializer + ForyDefault,
{
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
if len == 0 {
return Ok(Vec::new());
}
diff --git a/rust/fory-core/src/serializer/datetime.rs
b/rust/fory-core/src/serializer/datetime.rs
index bd740110d..23f8c4968 100644
--- a/rust/fory-core/src/serializer/datetime.rs
+++ b/rust/fory-core/src/serializer/datetime.rs
@@ -159,20 +159,20 @@ impl Serializer for Duration {
let raw = self.as_secs();
if raw > i64::MAX as u64 {
return Err(Error::invalid_data(format!(
- "std::time::Duration seconds {} exceeds i64::MAX and cannot be
encoded as varint64",
+ "std::time::Duration seconds {} exceeds i64::MAX and cannot be
encoded with write_var_i64",
raw
)));
}
let secs = raw as i64;
let nanos = self.subsec_nanos() as i32;
- context.writer.write_varint64(secs);
+ context.writer.write_var_i64(secs);
context.writer.write_i32(nanos);
Ok(())
}
#[inline(always)]
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
- let secs = context.reader.read_varint64()?;
+ let secs = context.reader.read_var_i64()?;
if secs < 0 {
return Err(Error::invalid_data(format!(
"negative duration seconds {} cannot be represented as
std::time::Duration; use chrono::Duration instead",
@@ -194,7 +194,7 @@ impl Serializer for Duration {
#[inline(always)]
fn fory_reserved_space() -> usize {
- 9 + mem::size_of::<i32>() // max varint64 is 9 bytes + 4 bytes for i32
+ 9 + mem::size_of::<i32>() // max write_var_i64 payload is 9 bytes + 4
bytes for i32
}
#[inline(always)]
@@ -241,14 +241,14 @@ impl Serializer for ChronoDuration {
fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error>
{
let secs = self.num_seconds();
let nanos = self.subsec_nanos();
- context.writer.write_varint64(secs);
+ context.writer.write_var_i64(secs);
context.writer.write_i32(nanos);
Ok(())
}
#[inline(always)]
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
- let secs = context.reader.read_varint64()?;
+ let secs = context.reader.read_var_i64()?;
let nanos = context.reader.read_i32()?;
if !(-999_999_999..=999_999_999).contains(&nanos) {
// chrono supports negative nanoseconds by applying normalization
internally.
@@ -269,7 +269,7 @@ impl Serializer for ChronoDuration {
#[inline(always)]
fn fory_reserved_space() -> usize {
- 9 + mem::size_of::<i32>() // max varint64 is 9 bytes + 4 bytes for i32
+ 9 + mem::size_of::<i32>() // max write_var_i64 payload is 9 bytes + 4
bytes for i32
}
#[inline(always)]
diff --git a/rust/fory-core/src/serializer/enum_.rs
b/rust/fory-core/src/serializer/enum_.rs
index 2605383ef..00ae71229 100644
--- a/rust/fory-core/src/serializer/enum_.rs
+++ b/rust/fory-core/src/serializer/enum_.rs
@@ -55,9 +55,7 @@ pub fn write_type_info<T: Serializer>(context: &mut
WriteContext) -> Result<(),
let rs_type_id = std::any::TypeId::of::<T>();
if type_id == TypeId::ENUM {
let type_info =
context.get_type_resolver().get_type_info(&rs_type_id)?;
- context
- .writer
- .write_var_uint32(type_info.get_user_type_id());
+ context.writer.write_var_u32(type_info.get_user_type_id());
return Ok(());
}
if context.is_share_meta() {
@@ -118,7 +116,7 @@ pub fn read_type_info<T: Serializer>(context: &mut
ReadContext) -> Result<(), Er
let _type_name_msb = context.read_meta_string()?;
}
} else {
- context.reader.read_varuint32()?;
+ context.reader.read_var_u32()?;
}
Ok(())
}
diff --git a/rust/fory-core/src/serializer/map.rs
b/rust/fory-core/src/serializer/map.rs
index 6677679ff..9c043a048 100644
--- a/rust/fory-core/src/serializer/map.rs
+++ b/rust/fory-core/src/serializer/map.rs
@@ -64,7 +64,7 @@ where
V: Serializer,
I: Iterator<Item = (&'a K, &'a V)>,
{
- context.writer.write_var_uint32(length as u32);
+ context.writer.write_var_u32(length as u32);
if length == 0 {
return Ok(());
}
@@ -561,7 +561,7 @@ impl<K: Serializer + ForyDefault + Eq + std::hash::Hash, V:
Serializer + ForyDef
}
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
if len == 0 {
return Ok(HashMap::new());
}
@@ -717,7 +717,7 @@ impl<K: Serializer + ForyDefault + Ord + std::hash::Hash,
V: Serializer + ForyDe
}
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
if len == 0 {
return Ok(BTreeMap::new());
}
diff --git a/rust/fory-core/src/serializer/number.rs
b/rust/fory-core/src/serializer/number.rs
index 632cb9ad7..f62f7e9d0 100644
--- a/rust/fory-core/src/serializer/number.rs
+++ b/rust/fory-core/src/serializer/number.rs
@@ -67,7 +67,7 @@ macro_rules! impl_num_serializer {
#[inline(always)]
fn fory_write_type_info(context: &mut WriteContext) -> Result<(),
Error> {
- context.writer.write_var_uint32($field_type as u32);
+ context.writer.write_var_u32($field_type as u32);
Ok(())
}
@@ -89,14 +89,14 @@ impl_num_serializer!(i8, Writer::write_i8, Reader::read_i8,
TypeId::INT8);
impl_num_serializer!(i16, Writer::write_i16, Reader::read_i16, TypeId::INT16);
impl_num_serializer!(
i32,
- Writer::write_varint32,
- Reader::read_varint32,
+ Writer::write_var_i32,
+ Reader::read_var_i32,
TypeId::VARINT32
);
impl_num_serializer!(
i64,
- Writer::write_varint64,
- Reader::read_varint64,
+ Writer::write_var_i64,
+ Reader::read_var_i64,
TypeId::VARINT64
);
impl_num_serializer!(f32, Writer::write_f32, Reader::read_f32,
TypeId::FLOAT32);
@@ -135,7 +135,7 @@ impl Serializer for float16 {
}
#[inline(always)]
fn fory_write_type_info(context: &mut WriteContext) -> Result<(), Error> {
- context.writer.write_var_uint32(TypeId::FLOAT16 as u32);
+ context.writer.write_var_u32(TypeId::FLOAT16 as u32);
Ok(())
}
#[inline(always)]
diff --git a/rust/fory-core/src/serializer/primitive_list.rs
b/rust/fory-core/src/serializer/primitive_list.rs
index 5110c8d6d..df17663d0 100644
--- a/rust/fory-core/src/serializer/primitive_list.rs
+++ b/rust/fory-core/src/serializer/primitive_list.rs
@@ -55,7 +55,7 @@ pub fn fory_write_data<T: Serializer>(this: &[T], context:
&mut WriteContext) ->
}
}
let len_bytes = std::mem::size_of_val(this);
- context.writer.write_var_uint32(len_bytes as u32);
+ context.writer.write_var_u32(len_bytes as u32);
if !this.is_empty() {
#[cfg(target_endian = "little")]
@@ -84,7 +84,7 @@ pub fn fory_write_type_info(context: &mut WriteContext,
type_id: TypeId) -> Resu
}
pub fn fory_read_data<T: Serializer>(context: &mut ReadContext) ->
Result<Vec<T>, Error> {
- let size_bytes = context.reader.read_varuint32()? as usize;
+ let size_bytes = context.reader.read_var_u32()? as usize;
if size_bytes % std::mem::size_of::<T>() != 0 {
return Err(Error::invalid_data("Invalid data length"));
}
diff --git a/rust/fory-core/src/serializer/skip.rs
b/rust/fory-core/src/serializer/skip.rs
index 84fbf7647..177bdfc73 100644
--- a/rust/fory-core/src/serializer/skip.rs
+++ b/rust/fory-core/src/serializer/skip.rs
@@ -54,7 +54,7 @@ pub fn skip_any_value(context: &mut ReadContext,
read_ref_flag: bool) -> Result<
}
if ref_flag == (RefFlag::Ref as i8) {
// Reference to already-seen object, skip the reference index
- let _ref_index = context.reader.read_varuint32()?;
+ let _ref_index = context.reader.read_var_u32()?;
return Ok(());
}
// RefValue (0) or NotNullValue (-1) means we need to read the actual
object
@@ -65,7 +65,7 @@ pub fn skip_any_value(context: &mut ReadContext,
read_ref_flag: bool) -> Result<
let internal_id = type_id;
let _user_type_id = if types::needs_user_type_id(type_id) && type_id !=
types::COMPATIBLE_STRUCT
{
- Some(context.reader.read_varuint32()?)
+ Some(context.reader.read_var_u32()?)
} else {
None
};
@@ -172,7 +172,7 @@ pub fn skip_any_value(context: &mut ReadContext,
read_ref_flag: bool) -> Result<
}
fn skip_collection(context: &mut ReadContext, field_type: &FieldType) ->
Result<(), Error> {
- let length = context.reader.read_varuint32()? as usize;
+ let length = context.reader.read_var_u32()? as usize;
if length == 0 {
return Ok(());
}
@@ -210,7 +210,7 @@ fn skip_collection(context: &mut ReadContext, field_type:
&FieldType) -> Result<
}
fn skip_map(context: &mut ReadContext, field_type: &FieldType) -> Result<(),
Error> {
- let length = context.reader.read_varuint32()?;
+ let length = context.reader.read_var_u32()?;
if length == 0 {
return Ok(());
}
@@ -418,7 +418,7 @@ fn skip_value(
}
if ref_flag == (RefFlag::Ref as i8) {
// Reference to already-seen object, skip the reference index
- let _ref_index = context.reader.read_varuint32()?;
+ let _ref_index = context.reader.read_var_u32()?;
return Ok(());
}
// RefValue (0) or NotNullValue (-1) means we need to read the actual
object
@@ -443,7 +443,7 @@ fn skip_value(
|| type_id_num == types::TYPED_UNION
|| type_id_num == types::NAMED_UNION
{
- let _ordinal = context.reader.read_varuint32()?;
+ let _ordinal = context.reader.read_var_u32()?;
return Ok(());
} else if type_id_num == types::EXT || type_id_num == types::NAMED_EXT
{
return skip_ext(context, type_id_num, type_info);
@@ -572,12 +572,12 @@ fn skip_value(
// ============ ENUM (TypeId = 23) ============
types::ENUM => {
- let _ordinal = context.reader.read_varuint32()?;
+ let _ordinal = context.reader.read_var_u32()?;
}
// ============ NAMED_ENUM (TypeId = 24) ============
types::NAMED_ENUM => {
- let _ordinal = context.reader.read_varuint32()?;
+ let _ordinal = context.reader.read_var_u32()?;
}
// ============ STRUCT (TypeId = 25) ============
@@ -612,19 +612,19 @@ fn skip_value(
// ============ UNION (TypeId = 31) ============
types::UNION => {
- let _ = context.reader.read_varuint32()?;
+ let _ = context.reader.read_var_u32()?;
return skip_any_value(context, true);
}
// ============ TYPED_UNION (TypeId = 32) ============
types::TYPED_UNION => {
- let _ = context.reader.read_varuint32()?;
+ let _ = context.reader.read_var_u32()?;
return skip_any_value(context, true);
}
// ============ NAMED_UNION (TypeId = 33) ============
types::NAMED_UNION => {
- let _ = context.reader.read_varuint32()?;
+ let _ = context.reader.read_var_u32()?;
return skip_any_value(context, true);
}
diff --git a/rust/fory-core/src/serializer/string.rs
b/rust/fory-core/src/serializer/string.rs
index 1893cba9a..8edef1ee4 100644
--- a/rust/fory-core/src/serializer/string.rs
+++ b/rust/fory-core/src/serializer/string.rs
@@ -35,7 +35,7 @@ impl Serializer for String {
#[inline(always)]
fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), Error>
{
let bitor = (self.len() as i32 as u64) << 2 | StrEncoding::Utf8 as u64;
- context.writer.write_var_uint36_small(bitor);
+ context.writer.write_var_u36_small(bitor);
context.writer.write_utf8_string(self);
Ok(())
}
@@ -43,7 +43,7 @@ impl Serializer for String {
#[inline(always)]
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
// xlang mode: read encoding header and decode accordingly
- let bitor = context.reader.read_varuint36small()?;
+ let bitor = context.reader.read_var_u36_small()?;
let len = bitor >> 2;
let encoding = bitor & 0b11;
let s = match encoding {
diff --git a/rust/fory-core/src/serializer/struct_.rs
b/rust/fory-core/src/serializer/struct_.rs
index aecc8711b..9c6871e5b 100644
--- a/rust/fory-core/src/serializer/struct_.rs
+++ b/rust/fory-core/src/serializer/struct_.rs
@@ -69,7 +69,7 @@ pub fn read_type_info_fast<T: StructSerializer>(context: &mut
ReadContext) -> Re
local_type_id_u32 == remote_type_id,
Error::type_mismatch(local_type_id_u32, remote_type_id)
);
- let remote_user_type_id = context.reader.read_varuint32()?;
+ let remote_user_type_id = context.reader.read_var_u32()?;
let local_user_type_id = context
.get_type_resolver()
.get_user_type_id_by_index(&std::any::TypeId::of::<T>(),
T::fory_type_index())?;
diff --git a/rust/fory-core/src/serializer/tuple.rs
b/rust/fory-core/src/serializer/tuple.rs
index 97cf78b20..59570407c 100644
--- a/rust/fory-core/src/serializer/tuple.rs
+++ b/rust/fory-core/src/serializer/tuple.rs
@@ -120,7 +120,7 @@ impl<T0: Serializer + ForyDefault> Serializer for (T0,) {
write_tuple_element(&self.0, context)?;
} else {
// Compatible mode: use collection protocol (heterogeneous)
- context.writer.write_var_uint32(1);
+ context.writer.write_var_u32(1);
let header = 0u8; // No IS_SAME_TYPE flag
context.writer.write_u8(header);
self.0.fory_write(context, RefMode::NullOnly, true, false)?;
@@ -141,7 +141,7 @@ impl<T0: Serializer + ForyDefault> Serializer for (T0,) {
Ok((elem0,))
} else {
// Compatible mode: read collection protocol (heterogeneous)
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
let _header = context.reader.read_u8()?;
let elem0 = if len > 0 {
@@ -360,7 +360,7 @@ macro_rules! impl_tuple_serializer {
} else {
// Compatible mode: use collection protocol (always
heterogeneous)
let len = fory_tuple_count!($T0, $($T),*);
- context.writer.write_var_uint32(len as u32);
+ context.writer.write_var_u32(len as u32);
// Write header without IS_SAME_TYPE flag
let header = 0u8;
@@ -393,7 +393,7 @@ macro_rules! impl_tuple_serializer {
} else {
// Compatible mode: read collection protocol (always
heterogeneous)
// Handle flexible length: use defaults for missing
elements, skip extras
- let len = context.reader.read_varuint32()?;
+ let len = context.reader.read_var_u32()?;
let _header = context.reader.read_u8()?;
// Track how many elements we've read
diff --git a/rust/fory-core/src/serializer/unsigned_number.rs
b/rust/fory-core/src/serializer/unsigned_number.rs
index 597e31434..26c9a58c6 100644
--- a/rust/fory-core/src/serializer/unsigned_number.rs
+++ b/rust/fory-core/src/serializer/unsigned_number.rs
@@ -66,7 +66,7 @@ macro_rules! impl_xlang_unsigned_num_serializer {
#[inline(always)]
fn fory_write_type_info(context: &mut WriteContext) -> Result<(),
Error> {
- context.writer.write_var_uint32($field_type as u32);
+ context.writer.write_var_u32($field_type as u32);
Ok(())
}
@@ -132,7 +132,7 @@ macro_rules! impl_rust_unsigned_num_serializer {
#[inline(always)]
fn fory_write_type_info(context: &mut WriteContext) -> Result<(),
Error> {
- context.writer.write_var_uint32($field_type as u32);
+ context.writer.write_var_u32($field_type as u32);
Ok(())
}
@@ -155,14 +155,14 @@ impl_xlang_unsigned_num_serializer!(u8, Writer::write_u8,
Reader::read_u8, TypeI
impl_xlang_unsigned_num_serializer!(u16, Writer::write_u16, Reader::read_u16,
TypeId::UINT16);
impl_xlang_unsigned_num_serializer!(
u32,
- Writer::write_var_uint32,
- Reader::read_varuint32,
+ Writer::write_var_u32,
+ Reader::read_var_u32,
TypeId::VAR_UINT32
);
impl_xlang_unsigned_num_serializer!(
u64,
- Writer::write_var_uint64,
- Reader::read_varuint64,
+ Writer::write_var_u64,
+ Reader::read_var_u64,
TypeId::VAR_UINT64
);
diff --git a/rust/fory-derive/src/object/derive_enum.rs
b/rust/fory-derive/src/object/derive_enum.rs
index 67a296f61..3949618b9 100644
--- a/rust/fory-derive/src/object/derive_enum.rs
+++ b/rust/fory-derive/src/object/derive_enum.rs
@@ -208,7 +208,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
// Union-compatible: write tag + null flag (matches
Java/C++ Union with null value)
quote! {
Self::#ident => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
// Write null flag for unit variant (no value)
context.writer.write_i8(fory_core::types::RefFlag::Null as i8);
}
@@ -216,7 +216,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
} else {
quote! {
Self::#ident => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
}
}
}
@@ -226,7 +226,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
// Union-compatible single field: write tag + value
with type info (like xwriteRef)
quote! {
Self::#ident(ref value) => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
use fory_core::serializer::Serializer;
value.fory_write(context,
fory_core::types::RefMode::Tracking, true, false)?;
}
@@ -234,7 +234,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
} else {
quote! {
Self::#ident(..) => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
}
}
}
@@ -246,7 +246,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
fields_named.named.first().unwrap().ident.as_ref().unwrap();
quote! {
Self::#ident { ref #field_ident } => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
use fory_core::serializer::Serializer;
#field_ident.fory_write(context,
fory_core::types::RefMode::Tracking, true, false)?;
}
@@ -254,7 +254,7 @@ fn xlang_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> V
} else {
quote! {
Self::#ident { .. } => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
}
}
}
@@ -280,7 +280,7 @@ fn rust_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> Ve
Fields::Unit => {
quote! {
Self::#ident => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
}
}
}
@@ -298,7 +298,7 @@ fn rust_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> Ve
quote! {
Self::#ident( #(#field_idents),* ) => {
- context.writer.write_var_uint32(#tag_value);
+ context.writer.write_var_u32(#tag_value);
#(#write_fields)*
}
}
@@ -322,7 +322,7 @@ fn rust_variant_branches(data_enum: &DataEnum,
default_variant_value: u32) -> Ve
quote! {
Self::#ident { #(#field_idents),* } => {
- context.writer.write_var_uint32(#tag_value) ;
+ context.writer.write_var_u32(#tag_value) ;
#(#write_fields)*
}
}
@@ -354,7 +354,7 @@ fn rust_compatible_variant_write_branches(
Fields::Unit => {
quote! {
Self::#ident => {
- context.writer.write_var_uint32((#tag_value << 2)
| 0b0);
+ context.writer.write_var_u32((#tag_value << 2) |
0b0);
}
}
}
@@ -368,9 +368,9 @@ fn rust_compatible_variant_write_branches(
quote! {
Self::#ident( #(ref #field_idents),* ) => {
- context.writer.write_var_uint32((#tag_value << 2)
| 0b1);
+ context.writer.write_var_u32((#tag_value << 2) |
0b1);
// Write as collection format (same as tuple)
- context.writer.write_var_uint32(#field_count as
u32);
+ context.writer.write_var_u32(#field_count as u32);
let header = 0u8; // No IS_SAME_TYPE flag
context.writer.write_u8(header);
use fory_core::serializer::Serializer;
@@ -401,7 +401,7 @@ fn rust_compatible_variant_write_branches(
quote! {
Self::#ident { #(#field_idents),* } => {
- context.writer.write_var_uint32((#tag_value << 2)
| 0b10);
+ context.writer.write_var_u32((#tag_value << 2) |
0b10);
// Write type meta inline using streaming protocol
context.write_type_meta(std::any::TypeId::of::<#meta_type_ident>())?;
// Write fields same as struct
@@ -770,7 +770,7 @@ fn rust_compatible_variant_read_branches(
return Ok(#default_value);
}
// Read collection format (same as tuple)
- let len = context.reader.read_varuint32()? as
usize;
+ let len = context.reader.read_var_u32()? as usize;
let _header = context.reader.read_u8()?;
#(#read_fields;)*
@@ -917,14 +917,14 @@ pub fn gen_read_data(data_enum: &DataEnum) -> TokenStream
{
quote! {
if context.is_xlang() {
- let ordinal = context.reader.read_varuint32()?;
+ let ordinal = context.reader.read_var_u32()?;
match ordinal {
#(#xlang_variant_branches)*
#unknown_xlang_branch
}
} else {
if context.is_compatible() {
- let encoded_tag = context.reader.read_varuint32()?;
+ let encoded_tag = context.reader.read_var_u32()?;
let tag = encoded_tag >> 2;
let variant_type = encoded_tag & 0b11;
@@ -941,7 +941,7 @@ pub fn gen_read_data(data_enum: &DataEnum) -> TokenStream {
}
}
} else {
- let tag = context.reader.read_varuint32()?;
+ let tag = context.reader.read_var_u32()?;
match tag {
#(#rust_variant_branches)*
_ => return
Err(fory_core::error::Error::unknown_enum("unknown enum value")),
diff --git a/rust/fory-derive/src/object/read.rs
b/rust/fory-derive/src/object/read.rs
index 787334730..e7ae9dd9e 100644
--- a/rust/fory-derive/src/object/read.rs
+++ b/rust/fory-derive/src/object/read.rs
@@ -69,8 +69,8 @@ fn gen_compatible_unsigned_read(
// Read u32 based on remote type_id
match _field.field_type.type_id {
fory_core::types::UINT32 => context.reader.read_u32()?,
- fory_core::types::VAR_UINT32 =>
context.reader.read_varuint32()?,
- _ => context.reader.read_varuint32()?, // Default to varint
+ fory_core::types::VAR_UINT32 => context.reader.read_var_u32()?,
+ _ => context.reader.read_var_u32()?, // Default to varint
}
}
} else {
@@ -79,9 +79,9 @@ fn gen_compatible_unsigned_read(
// Read u64 based on remote type_id
match _field.field_type.type_id {
fory_core::types::UINT64 => context.reader.read_u64()?,
- fory_core::types::VAR_UINT64 =>
context.reader.read_varuint64()?,
+ fory_core::types::VAR_UINT64 => context.reader.read_var_u64()?,
fory_core::types::TAGGED_UINT64 =>
context.reader.read_tagged_u64()?,
- _ => context.reader.read_varuint64()?, // Default to varint
+ _ => context.reader.read_var_u64()?, // Default to varint
}
}
};
diff --git a/rust/fory-derive/src/object/util.rs
b/rust/fory-derive/src/object/util.rs
index 07c40b495..cc938a117 100644
--- a/rust/fory-derive/src/object/util.rs
+++ b/rust/fory-derive/src/object/util.rs
@@ -736,8 +736,8 @@ static PRIMITIVE_IO_METHODS: &[(&str, &str, &str)] = &[
("bool", "write_bool", "read_bool"),
("i8", "write_i8", "read_i8"),
("i16", "write_i16", "read_i16"),
- ("i32", "write_varint32", "read_varint32"),
- ("i64", "write_varint64", "read_varint64"),
+ ("i32", "write_var_i32", "read_var_i32"),
+ ("i64", "write_var_i64", "read_var_i64"),
("f32", "write_f32", "read_f32"),
("f64", "write_f64", "read_f64"),
("u8", "write_u8", "read_u8"),
@@ -782,15 +782,15 @@ pub(super) fn get_primitive_writer_method(type_name:
&str) -> &'static str {
/// Get the writer method name for a primitive numeric type, considering
encoding attributes.
///
/// For i32 fields:
-/// - type_id=VARINT32 (default): write_varint32
+/// - type_id=VARINT32 (default): write_var_i32
/// - type_id=INT32: write_i32 (fixed 4-byte)
///
/// For u32 fields:
-/// - type_id=VARINT32/VAR_UINT32 (default): write_var_uint32
+/// - type_id=VARINT32/VAR_UINT32 (default): write_var_u32
/// - type_id=INT32/UINT32: write_u32 (fixed 4-byte)
///
/// For u64 fields:
-/// - type_id=VARINT32/VAR_UINT64 (default): write_var_uint64
+/// - type_id=VARINT32/VAR_UINT64 (default): write_var_u64
/// - type_id=INT32/UINT64: write_u64 (fixed 8-byte)
/// - type_id=TAGGED_UINT64: write_tagged_u64
pub(super) fn get_primitive_writer_method_with_encoding(
@@ -806,7 +806,7 @@ pub(super) fn get_primitive_writer_method_with_encoding(
return "write_i32"; // Fixed 4-byte encoding
}
}
- return "write_varint32"; // Variable-length (default)
+ return "write_var_i32"; // Variable-length (default)
}
// Handle u32 with type_id
@@ -816,7 +816,7 @@ pub(super) fn get_primitive_writer_method_with_encoding(
return "write_u32"; // Fixed 4-byte encoding
}
}
- return "write_var_uint32"; // Variable-length (default)
+ return "write_var_u32"; // Variable-length (default)
}
// Handle u64 with type_id
@@ -828,7 +828,7 @@ pub(super) fn get_primitive_writer_method_with_encoding(
return "write_tagged_u64"; // Tagged variable-length
}
}
- return "write_var_uint64"; // Variable-length (default)
+ return "write_var_u64"; // Variable-length (default)
}
// For other types, use the default method from PRIMITIVE_IO_METHODS
@@ -848,15 +848,15 @@ pub(super) fn get_primitive_reader_method(type_name:
&str) -> &'static str {
/// Get the reader method name for a primitive numeric type, considering
encoding attributes.
///
/// For i32 fields:
-/// - type_id=VARINT32 (default): read_varint32
+/// - type_id=VARINT32 (default): read_var_i32
/// - type_id=INT32: read_i32 (fixed 4-byte)
///
/// For u32 fields:
-/// - type_id=VARINT32/VAR_UINT32 (default): read_varuint32
+/// - type_id=VARINT32/VAR_UINT32 (default): read_var_u32
/// - type_id=INT32/UINT32: read_u32 (fixed 4-byte)
///
/// For u64 fields:
-/// - type_id=VARINT32/VAR_UINT64 (default): read_varuint64
+/// - type_id=VARINT32/VAR_UINT64 (default): read_var_u64
/// - type_id=INT32/UINT64: read_u64 (fixed 8-byte)
/// - type_id=TAGGED_UINT64: read_tagged_u64
pub(super) fn get_primitive_reader_method_with_encoding(
@@ -872,7 +872,7 @@ pub(super) fn get_primitive_reader_method_with_encoding(
return "read_i32"; // Fixed 4-byte encoding
}
}
- return "read_varint32"; // Variable-length (default)
+ return "read_var_i32"; // Variable-length (default)
}
// Handle u32 with type_id
@@ -882,7 +882,7 @@ pub(super) fn get_primitive_reader_method_with_encoding(
return "read_u32"; // Fixed 4-byte encoding
}
}
- return "read_varuint32"; // Variable-length (default)
+ return "read_var_u32"; // Variable-length (default)
}
// Handle u64 with type_id
@@ -894,7 +894,7 @@ pub(super) fn get_primitive_reader_method_with_encoding(
return "read_tagged_u64"; // Tagged variable-length
}
}
- return "read_varuint64"; // Variable-length (default)
+ return "read_var_u64"; // Variable-length (default)
}
// For other types, use the default method from PRIMITIVE_IO_METHODS
diff --git a/rust/fory/src/lib.rs b/rust/fory/src/lib.rs
index 3ba72033e..f38cc7a37 100644
--- a/rust/fory/src/lib.rs
+++ b/rust/fory/src/lib.rs
@@ -827,14 +827,14 @@
//! impl Serializer for CustomType {
//! fn fory_write_data(&self, context: &mut WriteContext) -> Result<(),
Error> {
//! context.writer.write_i32(self.value);
-//! context.writer.write_var_uint32(self.name.len() as u32);
+//! context.writer.write_var_u32(self.name.len() as u32);
//! context.writer.write_utf8_string(&self.name);
//! Ok(())
//! }
//!
//! fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
//! let value = context.reader.read_i32()?;
-//! let len = context.reader.read_varuint32()? as usize;
+//! let len = context.reader.read_var_u32()? as usize;
//! let name = context.reader.read_utf8_string(len)?;
//! Ok(Self { value, name })
//! }
diff --git a/rust/tests/tests/compatible/test_struct.rs
b/rust/tests/tests/compatible/test_struct.rs
index 8e9c9461c..50533e51c 100644
--- a/rust/tests/tests/compatible/test_struct.rs
+++ b/rust/tests/tests/compatible/test_struct.rs
@@ -628,14 +628,14 @@ fn test_struct_with_generic() {
impl<T: 'static + Serializer + ForyDefault> Serializer for Wrapper<T> {
fn fory_write_data(&self, context: &mut WriteContext) -> Result<(),
Error> {
- context.writer.write_var_uint32(self.value.len() as u32);
+ context.writer.write_var_u32(self.value.len() as u32);
context.writer.write_utf8_string(&self.value);
self.data.fory_write_data(context)?;
Ok(())
}
fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
- let len = context.reader.read_varuint32()? as usize;
+ let len = context.reader.read_var_u32()? as usize;
let value = context.reader.read_utf8_string(len)?;
let data = T::fory_read_data(context)?;
Ok(Self {
diff --git a/rust/tests/tests/test_buffer.rs b/rust/tests/tests/test_buffer.rs
index d589c16c3..ed5c3fc26 100644
--- a/rust/tests/tests/test_buffer.rs
+++ b/rust/tests/tests/test_buffer.rs
@@ -18,7 +18,7 @@
use fory_core::buffer::{Reader, Writer};
#[test]
-fn test_varint32() {
+fn test_var_i32() {
let test_data: Vec<i32> = vec![
// 1 byte(0..127)
0,
@@ -43,25 +43,25 @@ fn test_varint32() {
for &data in &test_data {
let mut buffer = vec![];
let mut writer = Writer::from_buffer(&mut buffer);
- writer.write_varint32(data);
+ writer.write_var_i32(data);
let binding = writer.dump();
let mut reader = Reader::new(binding.as_slice());
- let res = reader.read_varint32().unwrap();
+ let res = reader.read_var_i32().unwrap();
assert_eq!(res, data);
}
for &data in &test_data {
let mut buffer = vec![];
let mut writer = Writer::from_buffer(&mut buffer);
- writer.write_var_uint32(data as u32);
+ writer.write_var_u32(data as u32);
let binding = writer.dump();
let mut reader = Reader::new(binding.as_slice());
- let res = reader.read_varuint32().unwrap();
+ let res = reader.read_var_u32().unwrap();
assert_eq!(res, data as u32);
}
}
#[test]
-fn test_varuint36_small() {
+fn test_var_u36_small() {
let test_data: Vec<u64> = vec![
// 1 byte
0,
@@ -88,11 +88,11 @@ fn test_varuint36_small() {
for &data in &test_data {
let mut buffer = vec![];
let mut writer = Writer::from_buffer(&mut buffer);
- writer.write_var_uint36_small(data);
+ writer.write_var_u36_small(data);
let buf = writer.dump();
let mut reader = Reader::new(buf.as_slice());
- let value = reader.read_varuint36small().unwrap();
+ let value = reader.read_var_u36_small().unwrap();
assert_eq!(value, data, "failed for data {}", data);
}
}
@@ -114,5 +114,5 @@ fn test_fixed_width_read_bounds_checks() {
let mut bad_cursor = Reader::new(&[1, 2, 3, 4]);
bad_cursor.set_cursor(10);
assert!(bad_cursor.read_u16().is_err());
- assert!(bad_cursor.read_varuint36small().is_err());
+ assert!(bad_cursor.read_var_u36_small().is_err());
}
diff --git a/rust/tests/tests/test_cross_language.rs
b/rust/tests/tests/test_cross_language.rs
index 5a06b6f41..8a7b48288 100644
--- a/rust/tests/tests/test_cross_language.rs
+++ b/rust/tests/tests/test_cross_language.rs
@@ -92,7 +92,7 @@ fn test_buffer() {
assert_eq!(reader.read_i64().unwrap(), i64::MAX);
assert_eq!(reader.read_f32().unwrap(), -1.1f32);
assert_eq!(reader.read_f64().unwrap(), -1.1f64);
- assert_eq!(reader.read_varuint32().unwrap(), 100);
+ assert_eq!(reader.read_var_u32().unwrap(), 100);
let bytes_size = reader.read_i32().unwrap() as usize;
let binary = b"ab";
assert_eq!(reader.read_bytes(bytes_size).unwrap(), binary);
@@ -106,7 +106,7 @@ fn test_buffer() {
writer.write_i64(i64::MAX);
writer.write_f32(-1.1);
writer.write_f64(-1.1);
- writer.write_var_uint32(100);
+ writer.write_var_u32(100);
writer.write_i32(binary.len() as i32);
writer.write_bytes(binary);
@@ -120,7 +120,7 @@ fn test_buffer_var() {
let bytes = fs::read(&data_file_path).unwrap();
let mut reader = Reader::new(bytes.as_slice());
- let varint32_values = vec![
+ let var_i32_values = vec![
i32::MIN,
i32::MIN + 1,
-1000000,
@@ -140,11 +140,11 @@ fn test_buffer_var() {
i32::MAX - 1,
i32::MAX,
];
- for &expected in &varint32_values {
- let value = reader.read_varint32().unwrap();
- assert_eq!(expected, value, "varint32 value mismatch");
+ for &expected in &var_i32_values {
+ let value = reader.read_var_i32().unwrap();
+ assert_eq!(expected, value, "var_i32 value mismatch");
}
- let varuint32_values = vec![
+ let var_u32_values = vec![
0,
1,
127,
@@ -158,11 +158,11 @@ fn test_buffer_var() {
i32::MAX - 1,
i32::MAX,
];
- for &expected in &varuint32_values {
- let value = reader.read_varuint32().unwrap();
- assert_eq!(expected, value as i32, "varuint32 value mismatch");
+ for &expected in &var_u32_values {
+ let value = reader.read_var_u32().unwrap();
+ assert_eq!(expected, value as i32, "var_u32 value mismatch");
}
- let varuint64_values = vec![
+ let var_u64_values = vec![
0u64,
1,
127,
@@ -183,11 +183,11 @@ fn test_buffer_var() {
72057594037927936,
i64::MAX as u64,
];
- for &expected in &varuint64_values {
- let value = reader.read_varuint64().unwrap();
- assert_eq!(expected, value, "varuint64 value mismatch");
+ for &expected in &var_u64_values {
+ let value = reader.read_var_u64().unwrap();
+ assert_eq!(expected, value, "var_u64 value mismatch");
}
- let varint64_values = vec![
+ let var_i64_values = vec![
i64::MIN,
i64::MIN + 1,
-1000000000000,
@@ -204,24 +204,24 @@ fn test_buffer_var() {
i64::MAX - 1,
i64::MAX,
];
- for &expected in &varint64_values {
- let value = reader.read_varint64().unwrap();
- assert_eq!(expected, value, "varint64 value mismatch");
+ for &expected in &var_i64_values {
+ let value = reader.read_var_i64().unwrap();
+ assert_eq!(expected, value, "var_i64 value mismatch");
}
let mut buffer = vec![];
let mut writer = Writer::from_buffer(&mut buffer);
- for &value in &varint32_values {
- writer.write_varint32(value);
+ for &value in &var_i32_values {
+ writer.write_var_i32(value);
}
- for &value in &varuint32_values {
- writer.write_var_uint32(value as u32);
+ for &value in &var_u32_values {
+ writer.write_var_u32(value as u32);
}
- for &value in &varuint64_values {
- writer.write_var_uint64(value);
+ for &value in &var_u64_values {
+ writer.write_var_u64(value);
}
- for &value in &varint64_values {
- writer.write_varint64(value);
+ for &value in &var_i64_values {
+ writer.write_var_i64(value);
}
fs::write(data_file_path, writer.dump()).unwrap();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]