Decorative site banner
Project icon

com.io7m.jserial

  • About
  • Releases
  • Manual
  • Sources
  • License
  • Issues
Maven Central Version Maven Snapshot Code Coverage

jserial


A Java implementation of enhanced serial number arithmetic.

Features


  • 8-bit serial number arithmetic
  • 16-bit serial number arithmetic
  • 24-bit serial number arithmetic
  • 32-bit serial number arithmetic
  • 40-bit serial number arithmetic
  • 48-bit serial number arithmetic
  • 56-bit serial number arithmetic
  • 62-bit serial number arithmetic
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Motivation


Many communications protocols use fixed-sized fields to store sequence numbers. Unfortunately, given that the fields are of a fixed size, it is inevitable that the sequence numbers will eventually reach the maximum possible value that can be stored in fields of that size and, using unsigned arithmetic, will then wrap around to 0. This can cause serious problems for systems tracking sequence numbers as the numbers are no longer monotonically increasing.

Using serial number arithmetic, it's possible to have sequence numbers that can wrap around indefinitely, but that the application can still treat as being conceptually monotonically increasing.

Usage


Choose an implementation based on the number of bits used to store serial numbers in your intended protocol. Most protocols will want to use 32 bits:

var s = SerialNumber32.get();

Given a starting number x, get the next number in the sequence according to serial number arithmetic at the specified implementation size:

var y = s.add(x, 1L);

The SerialNumberLongType and SerialNumberIntType interfaces expose numerous methods to increment and compare numbers. In the above code, the value y can be compared with x, and the compare implementation will indicate that y is greater than x, even if y has wrapped around to zero.

Releases & Development Snapshots


Releases


You can subscribe to the atom feed to be notified of project releases.

The most recently released version of the package is 1.0.0.

1.0.0 Release (2024-06-01Z)

  • Update ch.qos.logback:logback-classic:1.4.14 → 1.5.6.
  • Update org.slf4j:slf4j-api:2.0.10 → 2.0.13.
  • Initial release.

The compiled artifacts for the release (and all previous releases) are available on Maven Central.

Maven Modules


<dependency> <group>com.io7m.jserial</group> <artifactId>com.io7m.jserial.core</artifactId> <version>1.0.0</version> </dependency><dependency> <group>com.io7m.jserial</group> <artifactId>com.io7m.jserial.tests</artifactId> <version>1.0.0</version> </dependency>

Previous Releases


The changelogs for the most recent previous releases are as follows:

0.4.0 Release (2017-08-09Z)

  • Correct value wrapping: Distance comparisons were incorrect near the upper bounds of ranges.
  • Add unsigned distance functions.
  • Require JDK 9, publish Java 9 modules. (Backwards incompatible)
  • Remove com.io7m.jnull dependency. (Backwards incompatible)

0.3.0 Release (2017-04-16Z)

  • Complete rewrite. Use interfaces and provide specialized 8, 16, 24, 32, 40, 48, 56, and 62 bit variants. (Backwards incompatible)
  • Require JDK 8 for unsigned functionality. (Backwards incompatible)
  • Rename project. Use the new primogenitor POM and 2017 project conventions. (Backwards incompatible)

0.1.0 Release (2016-06-09Z)

  • Initial release.

Development Snapshots


At the time of writing, the current unstable development version of the package is 1.0.1-SNAPSHOT.

Development snapshots may be available in the Central Portal Snapshots repository. Snapshots are published to this repository every time the project is built by the project's continuous integration system, but snapshots do expire after around ninety days and so may or may not be available depending on when a build of the package was last triggered.

Manual


This project does not have any user manuals or other documentation beyond what might be present on the page above.

Sources


This project uses Git to manage source code.

Repository: https://www.github.com/io7m-com/jserial

$ git clone --recursive https://www.github.com/io7m-com/jserial

Issues


This project uses GitHub Issues to track issues.

License


Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Last Updated 2025-08-09T14:57:24Z