Version: v0.0.0-...-ffa821b Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2017 License: Apache-2.0 Imports: 9 Imported by: 2



Package usbid provides human-readable text output for the usb package.

On load, the usbid package parses an embedded mapping of vendors/products and class/subclass/protocols. They can also be loaded from a URL or from a reader.

The bread and butter of this package are the following two functions:

Describe - Pretty-print the vendor and product of a device descriptor
Classify - Pretty-print the class/protocol info for a device/interface



View Source
const (
	// LinuxUsbDotOrg is one source of files in the format used by this package.
	LinuxUsbDotOrg = ""


View Source
var (
	// Vendors stores the vendor and product ID mappings.
	Vendors map[usb.ID]*Vendor

	// Classes stores the class, subclass and protocol mappings.
	Classes map[uint8]*Class
View Source
var LastUpdate = time.Unix(0, 1459738999628811942)

LastUpdate stores the latest time that the library was updated.

The baked-in data was last generated:

2016-04-03 20:03:19.628811942 -0700 PDT


func Classify

func Classify(val interface{}) string

Classify returns a human-readable string describing the class, subclass, and protocol associated with a device or interface.

The given val must be one of the following:

  • *usb.Descriptor "Class (SubClass) Protocol"
  • usb.InterfaceSetup "IfClass (IfSubClass) IfProtocol"

func Describe

func Describe(val interface{}) string

Describe returns a human readable string describing the vendor and product of the given device.

The given val must be one of the following:

  • *usb.Descriptor "Product (Vendor)"

func LoadFromURL

func LoadFromURL(url string) error

LoadFromURL replaces the built-in vendor and class mappings with ones loaded from the given URL.

This should usually only be necessary if the mappings in the library are stale. The contents of this file as of February 2012 are embedded in the library itself.

func ParseIDs

func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[uint8]*Class, error)

ParseIDs parses and returns mappings from the given reader. In general, this should not be necessary, as a set of mappings is already embedded in the library. If a new or specialized file is obtained, this can be used to retrieve the mappings, which can be stored in the global Vendors and Classes map.


type Class

type Class struct {
	Name     string
	SubClass map[uint8]*SubClass

A Class contains the name of the class and mappings for each subclass.

func (Class) String

func (c Class) String() string

String returns the name of the class.

type Product

type Product struct {
	Name      string
	Interface map[usb.ID]string

A Product contains the name of the product (from a particular vendor) and the names of any interfaces that were specified.

func (Product) String

func (p Product) String() string

String returns the name of the product.

type SubClass

type SubClass struct {
	Name     string
	Protocol map[uint8]string

A SubClass contains the name of the subclass and any associated protocols.

func (SubClass) String

func (s SubClass) String() string

String returns the name of the SubClass.

type Vendor

type Vendor struct {
	Name    string
	Product map[usb.ID]*Product

A Vendor contains the name of the vendor and mappings corresponding to all known products by their ID.

func (Vendor) String

func (v Vendor) String() string

String returns the name of the vendor.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL