25

I have a system that I'm working on at the moment that requires users to log into the system, and the client wants to use a barcode scanner and cards to keep prices down. (Yes username and password cheaper, but she wants a card type solution so she gets one.)

All my data uses GUIDs as key fields, so I'd like to store the GUID directly on the card in the barcode. While its simple enough to code it as 3 of 9 its not going to be the most efficient use of space.

Is there a best practice or most efficient method for storing GUIDs in a barcode? I'd have assumed that since there's a consistent length, and depth to the data there would be a standard, but I can't find it. Would be easy enough to generate my own - control char either end and then binary data between, but would like something that standard readers will know how to interpret.

Any help gratefully received.

2
  • Any reason you can't simply add another table mapping numeric bar codes to GUIDs? That way if a card is compromised you can easily reissue a barcode with a new number mapping to the same GUID without having to change lots of related records. Add an expiration date column and you can also retire cards after a set period of time (e.g. annually).
    – Ian Mercer
    Oct 20, 2016 at 0:32
  • Hi Ian. Was looking at storing the GUID directly as it is the key field and is the clustered index. As it happens I ended up almost using your solution. Each user has an ID Number and I ended up encoding that into the barcode instead, and creating a non-clustered index on that. Pretty much what you suggested here. Many thanks. Oct 20, 2016 at 9:42

1 Answer 1

36

There are no open standards for special-purpose data compaction with generic linear barcodes such as Code 39 and Code 128. Most ISO/IEC-standardised 2D barcodes do support a special-purpose data encoding mechanism called Extended Channel Interpretation (ECI) which allows you to specify that data conforms to a certain application standard or encoding regime, for example ECI 298765 for IPv4 address compaction [*]. Unfortunately GUID compaction isn't amongst those that have been registered and even if it were you would nevertheless need to handle this within your application as reader support would be lacking.

That leaves you with having to pre-encode (and subsequently decode) the GUID into a format that can be handled efficiently by some ubiquitous barcode symbology.

An efficient way to store a GUID would be to convert it to a 40-digit[†] decimal representation and store the result in a Code 128 barcode using double-density numeric compression ("Mode C").

For example, consider the GUID:

cd171f7c-560d-4a62-8d65-16b87419a58c

Expressed as a hexadecimal number:

0xCD171F7C560D4A628D6516B87419A58C

Converted to 40 decimal digits:

0272611800569275698104677545117639878028

Encoded within a Code 128 barcode:

GUID encoded in decimal within a Code 128

Your application would of course need to recognise this input as a decimal-encoded GUID and reverse the above process but I doubt that a significantly more efficient approach exists that doesn't require you to transform the data into an unusual radix and then deal with the complexities of handling ASCII control characters at scan time.

[*] The register of assigned ECI codes is available from the AIM store as "ECI Part 3: Register".

[†] Whilst it is possible to store the entire GUID range within 39 digits a 39-digit Mode C Code 128 symbol is in fact longer than a 40-digit symbol.

1
  • Hi Terry. Thanks for the response. Your answer is pretty much what I'd found from reading up on things myself. I've got used to using the approach though of if you can't find an answer then ask anyway. Nothing like finding out you've used the wrong approach 6 months down the line where everything else revolves around it. I won't mark this as the answer just yet in the hope that there may be an answer somewhere. If I don't see anything in a week or so I'll mark it up. Jul 30, 2015 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.