Table of Contents Previous Next
Logo
Client-Side Slice-to-Java Mapping : 10.17 Using Slice Checksums
Copyright © 2003-2008 ZeroC, Inc.

10.17 Using Slice Checksums

As described in Section 4.20, the Slice compilers can optionally generate checksums of Slice definitions. For slice2java, the checksum option causes the compiler to generate a new Java class that adds checksums to a static map member. Assuming we supplied the option checksum Checksums to slice2java, the generated class Checksums.java looks like this:
public class Checksums {
    public static java.util.Map checksums;
}
The read-only map checksums is initialized automatically prior to first use; no action is required by the application.
In order to verify a server’s checksums, a client could simply compare the dictionaries using the equals method. However, this is not feasible if it is possible that the server might return a superset of the client’s checksums. A more general solution is to iterate over the local checksums as demonstrated below:
java.util.Map serverChecksums = ...
java.util.Iterator i = Checksums.checksums.entrySet().iterator();
while(i.hasNext()) {
    java.util.Map.Entry e = (java.util.Map.Entry)i.next();
    String id = (String)e.getKey();
    String checksum = (String)e.getValue();
    String serverChecksum = (String)serverChecksums.get(id);
    if (serverChecksum == null) {
        // No match found for type id!
    } else if (!checksum.equals(serverChecksum)) {
        // Checksum mismatch!
    }
}
In this example, the client first verifies that the server’s dictionary contains an entry for each Slice type ID, and then it proceeds to compare the checksums.
Table of Contents Previous Next
Logo