Source of truth: VictoriaMetrics/lib/encoding (local clone at ./VictoriaMetrics).
Port: crates/encoding. One Go file → one Rust module; function order preserved.
| Go file | Rust module |
|---|---|
| int.go | src/int.rs |
| encoding.go | src/encoding.rs |
| nearest_delta.go | src/nearest_delta.rs |
| nearest_delta2.go | src/nearest_delta2.rs |
| compress.go + lib/encoding/zstd | src/compress.rs |
| float.go + pools in int.go | src/pool.rs |
| util.go | src/util.rs |
| lib/fastnum (subset) | src/fastnum.rs |
| — (optimization kernels, no Go counterpart) | src/simd.rs, simd_decode.rs, simd_encode.rs, simd_scan.rs |
Naming: Go MarshalVarInt64s → marshal_var_int64s, etc. Unexported Go
functions keep their names (marshalInt64Array → marshal_int64_array, public
in Rust for in-package-style tests).
- Go append-style
func F(dst []byte, ...) []byte→fn f(dst: &mut Vec<u8>, ...). - Go
(value, size int)wheresize <= 0signals failure →(T, isize)same contract. - Go
(result, error)→Result<T, encoding::Error>(Error wraps the fmt.Errorf string). - Go silent integer wraparound → explicit
wrapping_*. sync.Pool→ thread-local pools inpool.rs(same cost model: hit = length reset, miss = zeroed alloc).logger.Panicf("BUG: ...")→panic!("BUG: ...").
- zstd: real libzstd via the
zstd/zstd-safecrates with thread-local reused CCtx/DCtx (equivalent of gozstd's context pooling). Go cgo builds use the same libzstd; pure-Go builds use klauspost/compress, which produces different (but interoperable) frames and slightly different compressed sizes — this can flip the marshal-type compress-or-plain decision near the 0.9 threshold, so golden parity fixtures are generated with CGO_ENABLED=1. - vm_zstd_* metrics counters (compress.go): not ported.
- Optimization pass rewrote hot loop internals (SIMD kernels, spare-capacity writes, bulk fills); wire format, results, and error conditions are unchanged and enforced by tests/parity_test.rs golden vectors generated from upstream Go.
| Go test file | Rust |
|---|---|
| int_test.go | tests/int_test.rs |
| util_test.go | tests/util_test.rs |
| compress_test.go | tests/compress_test.rs |
| encoding_test.go | tests/encoding_test.rs |
| nearest_delta_test.go | tests/nearest_delta_test.rs |
| nearest_delta2_test.go | tests/nearest_delta2_test.rs |
| — | tests/parity_test.rs (golden vectors vs real Go output; see bench/go/gen) |
encoding_pure_test.go / encoding_cgo_test.go (zstd-impl-specific size goldens) were not ported.