Ignore:
Timestamp:
Mar 7, 2011, 7:47:42 PM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
fa0d0ef
Parents:
5cfb358
git-author:
Jessica B. Hamrick <jhamrick@…> (03/07/11 19:47:42)
git-committer:
Jessica B. Hamrick <jhamrick@…> (03/07/11 19:47:42)
Message:

Update API for Value, Attribute, and AttributeGroup?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ippvalue.py

    r5cfb358 rc269bc7  
    6565        self.value_tag    = None # one byte, the type of value
    6666        self.value        = None # non-binary value of self.value
    67         self.value_size   = None # size of self.value
     67        self.tag_size     = 1    # length of the tag in bytes
     68        self.value_size   = None # size of self.value in bytes
    6869        self.binary_value = None # binary value of self.value
    6970
     
    7273                self.value_tag = value_tag
    7374                self.binary_value = value
    74                 self.unpack()
    75                 self.pack()
     75                self.value_size, self.value = self.unpack()
    7676            else:
    7777                self.value_tag = value_tag
    7878                self.value = value
    79                 self.pack()
    80                 self.unpack()
     79                self.value_size, self.binary_value = self.pack()
     80
     81            self.verify()
    8182
    8283    def unpack(self):
     
    196197                   "unpacked value is not the same as self.value!"
    197198
    198         self.value_size = value_size
    199         self.value = value
    200        
    201199        return value_size, value
    202200
     
    313311            binary_value = self.value
    314312
    315         if self.value_size is not None:
    316             assert value_size == self.value_size, \
    317                    "packed value size is not the same as " + \
    318                    "self.value_size!"
    319         if self.binary_value is not None:
    320             assert binary_value == self.binary_value, \
    321                    "packed binary value is not the same as " + \
    322                    "self.binary_value!"
    323 
    324         self.value_size = value_size
    325         self.binary_value = binary_value
    326 
    327313        return value_size, binary_value
    328314
     
    346332               "value type is unknown!"
    347333
    348         self.pack()
    349         self.unpack()
     334        value_size1, binary_value = self.pack()
     335        value_size2, value = self.unpack()
     336
     337        assert value_size1 == value_size2, \
     338               "packed value size is not the same as " + \
     339               "unpacked value size!"
     340        assert value_size == self.value_size, \
     341               "packed value size is not the same as " + \
     342               "self.value_size!"
     343        assert binary_value == self.binary_value, \
     344               "packed binary value is not the same as " + \
     345               "self.binary_value!"
    350346
    351347    def getValue(self):
     
    371367        return self.value_tag
    372368
    373     def getSize(self):
     369    def getValueSize(self):
    374370        """
    375371        Get the size of the value in bytes.
     
    378374        return self.value_size
    379375
     376    def getTagSize(self):
     377        """
     378        Get the size of the value tag in bytes.
     379        """
     380
     381        return self.tag_size
     382
    380383    def setValue(self, value):
    381384        """
    382385        Set the non-binary value.
    383386        """
    384        
     387
    385388        self.value = value
    386389
     
    389392        Set the binary value.
    390393        """
     394
    391395        self.binary_value = binary_value
    392396
     
    399403        self.value_tag = value_tag
    400404
    401     def setSize(self, size):
     405    def setValueSize(self, size):
    402406        """
    403407        Set the size of the value in bytes.
     
    405409       
    406410        self.value_size = size
     411
     412    def getTotalSize(self):
     413        """
     414        Get the total size of the IPP value.
     415        """
     416
     417        return self.value_size + self.tag_size
    407418
    408419    def __str__(self):
Note: See TracChangeset for help on using the changeset viewer.