Skip to content

Commit

Permalink
add leb128
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Feb 6, 2025
1 parent d893b34 commit f892e30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/layout/core/types/leb128.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:blockchain_utils/layout/core/core.dart';
///
/// LEB128 is a variable-length encoding method that is efficient for representing small numbers compactly.
/// This layout is used in serialization frameworks like BCS (Binary Canonical Serialization).
class LEB128DIntLayout extends Layout<int> {
class LEB128IntLayout extends Layout<int> {
/// Constructor for [LEB128IntLayout].
///
/// [layout] is the underlying integer layout used for validation.
/// [property] is an optional key associated with this layout for structured data handling.
LEB128DIntLayout(this.layout, {String? property})
LEB128IntLayout(this.layout, {String? property})
: super(-1, property: property);

/// The integer layout used to validate values before encoding.
Expand Down Expand Up @@ -97,7 +97,7 @@ class LEB128DIntLayout extends Layout<int> {
///
/// Useful when reusing the layout structure with different property associations.
@override
LEB128DIntLayout clone({String? newProperty}) {
return LEB128DIntLayout(layout, property: newProperty);
LEB128IntLayout clone({String? newProperty}) {
return LEB128IntLayout(layout, property: newProperty);
}
}
4 changes: 2 additions & 2 deletions lib/layout/core/types/leb128_offset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LEB128U32OffsetLayout extends ExternalOffsetLayout {
LEB128U32OffsetLayout({super.property});

/// Internal layout used for encoding and decoding LEB128 integers.
final LEB128DIntLayout layout = LEB128DIntLayout(LayoutConst.u32());
final LEB128IntLayout layout = LEB128IntLayout(LayoutConst.u32());

/// Indicates that this layout represents a count (such as the length of a vector).
@override
Expand Down Expand Up @@ -43,7 +43,7 @@ class LEB128U32OffsetLayout extends ExternalOffsetLayout {
/// Returns the number of bytes written after encoding.
@override
int encode(int source, LayoutByteWriter writer, {int offset = 0}) {
final encodeLength = LEB128DIntLayout.writeVarint(source);
final encodeLength = LEB128IntLayout.writeVarint(source);
writer.setAll(offset, encodeLength);
return encodeLength.length;
}
Expand Down

0 comments on commit f892e30

Please sign in to comment.