sizeHint method

  1. @override
int sizeHint(
  1. RuntimeVersion value
)
override

If possible give a hint of expected size of the encoding.

This method is used inside default implementation of encode to avoid re-allocations.

Implementation

@override
int sizeHint(RuntimeVersion value) {
  int size = 0;
  size += StrCodec.codec.sizeHint(value.specName);
  size += StrCodec.codec.sizeHint(value.implName);
  size += U32Codec.codec.sizeHint(value.authoringVersion);
  size += U32Codec.codec.sizeHint(value.specVersion);
  size += U32Codec.codec.sizeHint(value.implVersion);
  size +=
      const SequenceCodec<ApiVersion>(ApiVersion.codec).sizeHint(value.apis);

  // - `Core` version < 3 is a runtime version without a transaction version and state version.
  // - `Core` version 3 is a runtime version without a state version.
  // - `Core` version 4 is the latest runtime version.
  final int? coreVersion = coreVersionFromApis(value.apis);
  if (coreVersion == null || coreVersion >= 3) {
    size += U32Codec.codec.sizeHint(value.transactionVersion);
  }
  if (coreVersion == null || coreVersion >= 4) {
    size += U8Codec.codec.sizeHint(value.stateVersion);
  }
  return size;
}