- def __struct (self, t, n = None, e = -1, vl = None):
- """Create a packing structure for a message."""
- base_types = { 'u8' : 'B',
- 'u16' : 'H',
- 'u32' : 'I',
- 'i32' : 'i',
- 'u64' : 'Q',
- 'f64' : 'd',
- }
- pack = None
- if t in base_types:
- pack = base_types[t]
- if not vl:
- if e > 0 and t == 'u8':
- # Fixed byte array
- return struct.Struct('>' + str(e) + 's')
- if e > 0:
- # Fixed array of base type
- return [e, struct.Struct('>' + base_types[t])]
- elif e == 0:
- # Old style variable array
- return [-1, struct.Struct('>' + base_types[t])]
- else:
- # Variable length array
- return [vl, struct.Struct('>s')] if t == 'u8' else \
- [vl, struct.Struct('>' + base_types[t])]
-
- return struct.Struct('>' + base_types[t])
-
- if t in self.messages:
- ### Return a list in case of array ###
- if e > 0 and not vl:
- return [e, lambda self, encode, buf, offset, args: (
- self.__struct_type(encode, self.messages[t], buf, offset,
- args))]
- if vl:
- return [vl, lambda self, encode, buf, offset, args: (
- self.__struct_type(encode, self.messages[t], buf, offset,
- args))]
- elif e == 0:
- # Old style VLA
- raise NotImplementedError(1, 'No support for compound types ' + t)
- return lambda self, encode, buf, offset, args: (
- self.__struct_type(encode, self.messages[t], buf, offset, args)
- )
-
- raise ValueError(1, 'Invalid message type: ' + t)
-
- def __struct_type(self, encode, msgdef, buf, offset, kwargs):
- """Get a message packer or unpacker."""
- if encode:
- return self.__struct_type_encode(msgdef, buf, offset, kwargs)
+ if 'VPP_API_DIR' in os.environ:
+ dirs.append(os.environ['VPP_API_DIR'])
+
+ # perhaps we're in the 'src/scripts' or 'src/vpp-api/python' dir;
+ # in which case, plot a course to likely places in the src tree
+ import __main__ as main
+ if hasattr(main, '__file__'):
+ # get the path of the calling script
+ localdir = os.path.dirname(os.path.realpath(main.__file__))