def read(self, istream): """ Read the encoding of the Enumeration from the input stream. Args: istream (stream): A buffer containing the encoded bytes of an Enumeration. Usually a BytearrayStream object. Required. Raises: InvalidPrimitiveLength: if the Enumeration encoding read in has an invalid encoded length. InvalidPaddingBytes: if the Enumeration encoding read in does not use zeroes for its padding bytes. """ super(Enumeration, self).read(istream) # Check for a valid length before even trying to parse the value. if self.length != Enumeration.LENGTH: raise exceptions.InvalidPrimitiveLength( "enumeration length must be {0}".format(Enumeration.LENGTH)) # Decode the Enumeration value and the padding bytes. value = unpack('!I', istream.read(Enumeration.LENGTH))[0] self.value = self.enum(value) pad = unpack('!I', istream.read(Enumeration.LENGTH))[0] # Verify that the padding bytes are zero bytes. if pad is not 0: raise exceptions.InvalidPaddingBytes("padding bytes must be zero") self.validate()
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the encoding of the Interval from the input stream. Args: istream (stream): A buffer containing the encoded bytes of the value of an Interval. Usually a BytearrayStream object. Required. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 1.0. Raises: InvalidPrimitiveLength: if the Interval encoding read in has an invalid encoded length. InvalidPaddingBytes: if the Interval encoding read in does not use zeroes for its padding bytes. """ super(Interval, self).read(istream, kmip_version=kmip_version) # Check for a valid length before even trying to parse the value. if self.length != Interval.LENGTH: raise exceptions.InvalidPrimitiveLength( "interval length must be {0}".format(Interval.LENGTH)) # Decode the Interval value and the padding bytes. self.value = unpack('!I', istream.read(Interval.LENGTH))[0] pad = unpack('!I', istream.read(Interval.LENGTH))[0] # Verify that the padding bytes are zero bytes. if pad != 0: raise exceptions.InvalidPaddingBytes("padding bytes must be zero") self.validate()