Class Payload
- Direct Known Subclasses:
RawPayload
The BaseReader.Symbology
property reveals the type of item detected and
contained in the Payload. This can help inform the developer if the detection was a Digimarc Barcode, a
traditional 1D barcode, or a QR Code and handle each payload accordingly. For example, the developer may
want to use the Resolver to resolve Digimarc Barcodes but may want to open QR Code contents directly
within the app:
BaseReader.Symbology symbology = payload.getSymbology();
if (symbology.equals(BaseReader.ImageSymbology.Image_Digimarc)) {
// Resolve
} else if (symbology.equals(BaseReader.ImageSymbology.Image_QRCode)) {
// Open contents
}
The best way for an application to access payload data is via the Payload.Representation
object.
Representations allow an app to request data in the format that it wants to handle. For instance, if an app wants
to process UPCA barcodes then it can request the BasicRepresentation.UPC_A
representation. If the payload can be represented that way then a string containing the UPCA code value will
be returned, otherwise null. It doesn't matter what code type this data came from, whether it was an actual UPCA
barcode, a Digimarc Barcode or something else entirely. If the data can be represented as a UPCA barcode then
it will be returned that way.
String upcaRepresentation = (String) payload.getRepresentation(Payload.BasicRepresentation.UPC_A);
if (upcaRepresentation != null) {
// upcaRepresentation contains a UPCA value
}
The most frequently used representation types can be found in the Payload.BasicRepresentation
enumeration.
Some specific representations for GS1 AIs can be found in the Payload.GS1_AI_Representation
. Most
applications will not have a need to use the specialized representations.
Payload also carries any applicable GS1 Application Identifiers (AIs), which can be queried through the
GS1 map as shown below. In general we recommend accessing GS1 AI data directly via the getGS1Data()
method rather than using Payload.GS1_AI_Representation
.
String gtin14AI = "01";
Map<String, String> aiMap = payload.getGS1Data();
if (aiMap.containsKey("01")) {
// aiMap contains a GTIN-14 value
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
BasicRepresentation contains the representations that most applications will need.static class
Payload data packaged as a carrier (format descriptor) and a value.static enum
Used with thegetData(DataFormatMode)
method for formatting payload data.static enum
Deprecated.static enum
GS1_AI_Representation contains representations that correspond to standard GS1 AI (Application Identifier) values.static interface
All representations implement the Representation interface.static enum
Deprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check equality of two payload objects.Gets all valid representations of the current payload and returns it within a Map of Representations to string values.getData()
Gets the payload data and a representation describing its format.Gets the payload data and a representation describing its format.Gets all GS1 data fields from the payload.Gets the CPM path of the payload.Gets the payload versiongetRepresentation
(Payload.Representation representation) Retrieves a string representation of the payload value in the requested format.Gets the symbology ID of the detector that decoded this payload.int
hashCode()
boolean
Is this payload value ephemeral or is it stable across reader sessions? Some watermarks, like digital watermarks that require certificates, return ephemeral payload values.
-
Constructor Details
-
Payload
Constructor.- Parameters:
cpmPath
- The CPM path of the payload.
-
-
Method Details
-
getPayloadString
Gets the CPM path of the payload.- Returns:
- Payload contents as a CPM path string.
-
getPayloadVersion
Gets the payload version- Returns:
- Payload contents as a CPM path string.
-
getSymbology
Gets the symbology ID of the detector that decoded this payload. This method can be used to determine how a payload should be handled by the application.- Returns:
- A symbology ID from the enum set defined by
BaseReader.ImageSymbology
,BaseReader.AudioSymbology
andBaseReader.UndefinedSymbology
.
-
equals
Check equality of two payload objects. This method should not be used if either payload in the comparison is ephemeral. SeeisEphemeral()
for more information. -
hashCode
public int hashCode() -
getRepresentation
Retrieves a string representation of the payload value in the requested format. Note that many payloads are only available in specific representations.- Parameters:
representation
- The requested representation type fromPayload.BasicRepresentation
,Payload.Sgtin96Representation
,Payload.GS1_AI_Representation
orPayload.GIAIFieldRepresentation
.- Returns:
- Returns a string containing the payload in the requested representation. Returns null if the representation is invalid for this payload.
-
getAllRepresentations
Gets all valid representations of the current payload and returns it within a Map of Representations to string values. For each representation within the map the app can get the Key value and callPayload.Representation.getName()
on it to get a string name of the representation type.- Returns:
- Returns a Map object containing Representations and their string values. If no representations are valid for the payload then an empty Map will be returned.
-
isEphemeral
public boolean isEphemeral()Is this payload value ephemeral or is it stable across reader sessions? Some watermarks, like digital watermarks that require certificates, return ephemeral payload values. These values might change between reader sessions. Don't compare ephemeral payloads using theequals(Object)
method because the result won't be consistent.- Returns:
- True if this is an ephemeral value, false otherwise.
-
getData
Gets the payload data and a representation describing its format.Note that in most cases,
Payload.DataFormatMode.Compatible
provides sufficient information.Payload.DataFormatMode.Native
is usually more useful to developers who prefer handling results as GS1 element strings.- Parameters:
mode
- Format to return data in.- Returns:
- Data in the requested format or null if the payload is invalid or unsupported.
-
getData
Gets the payload data and a representation describing its format. This method returns the data in Compatible format mode.- Returns:
- Data in the Compatible format or null if the payload is invalid or unsupported.
-
getGS1Data
Gets all GS1 data fields from the payload. This is returned as a map of AI and value strings. Note that invalid AI entries within the payload will be excluded from the returned data. The term "invalid" here refers to AI/value entries that don't conform to the GS1 spec. Specifically, the GS1 spec states that while AIs may appear more than once in a GS1 encoded string the values must be the same for each occurrence (GS1 Specification section 4.14).Note that these checks are performed only on the individual AIs and values within the string. No checks are performed as to the overall validity of the GS1 string (i.e. required fields when certain AIs are present, AIs that can't appear together, etc).
- Returns:
- A map of all valid AIs and values within the payload. If no valid AIs are present an empty map will be returned.
-