def capture(self, interest, transport): # print("capture cmd received start processing") interestName = interest.getName() if (interestName.size() >= 7): #right format segmentIndex = interestName.get(6).toSegment() # print "request segmentIndex : ",segmentIndex if segmentIndex == 0: # print("a new picture") #request a new picture self.stream = io.BytesIO() self.stream.flush() self.segmentList = [] self.dataList = [] self.camera.capture(self.stream, 'jpeg') #print("photo caputred in stream") imageBytes = self.stream.getvalue() print ("imageBytes %d" % len(imageBytes)) #segmentation self.segmentNumber = len(imageBytes)/(self.segmentSize+1)+1 print("segmentNumber: %d" % self.segmentNumber) for i in range(self.segmentNumber): startIndex = i*self.segmentSize if (i != self.segmentNumber -1): segBytes = imageBytes[startIndex:(startIndex+self.segmentSize)] else: segBytes = imageBytes[startIndex:] #self.segmentList.append(segBytes) newName = interestName.getPrefix(-1).appendSegment(i) #print newName.toUri() data = Data(newName) metaInfo = MetaInfo() metaInfo.setFinalBlockId(Blob.fromRawStr(str(self.segmentNumber-1))) data.setMetaInfo(metaInfo) #data.setContent(Blob.fromRawStr(self.segmentList[i])) data.setContent(Blob.fromRawStr(segBytes)) self.dataList.append(data) self.sendData(self.dataList[0], transport, sign=False) else: self.sendData(self.dataList[segmentIndex], transport, sign=False)
def setMetaInfo(self, metaInfo): """ Set metaInfo to a copy of the given MetaInfo. :param MetaInfo metaInfo: The MetaInfo which is copied. :return: This Data so that you can chain calls to update values. :rtype: Data """ self._metaInfo.set(MetaInfo() if metaInfo == None else MetaInfo(metaInfo)) self._changeCount += 1 return self
def __init__(self, value=None): if isinstance(value, Data): # Copy the values. self._name = ChangeCounter(Name(value.getName())) self._metaInfo = ChangeCounter(MetaInfo(value.getMetaInfo())) self._signature = ChangeCounter(value.getSignature().clone()) self._content = value._content self._defaultWireEncoding = value.getDefaultWireEncoding() self._defaultWireEncodingFormat = value._defaultWireEncodingFormat else: self._name = ChangeCounter( Name(value) if type(value) is Name else Name()) self._metaInfo = ChangeCounter(MetaInfo()) self._signature = ChangeCounter(Sha256WithRsaSignature()) self._content = Blob() self._defaultWireEncoding = SignedBlob() self._defaultWireEncodingFormat = None self._getDefaultWireEncodingChangeCount = 0 self._changeCount = 0
from pyndn.control_parameters import ControlParameters from pyndn.forwarding_flags import ForwardingFlags for p in [("name",Name("yes"),Name("another")), ("faceId", 32, None), ("localControlFeature", 1, None), ("origin", 2, 9), ("cost", 1, None), ("forwardingFlags", ForwardingFlags(), ForwardingFlags()), ("expirationPeriod", 1000.1, None)]: res = testPropertyRW( ControlParameters(), p[0], [p[1],p[2]]) if not res[0]: print(res) # Data # from pyndn.data import Data from pyndn.name import Name from pyndn.meta_info import MetaInfo from pyndn.signature import Signature from pyndn.util.blob import Blob # We do not test the signature property because clone is not yet implemented for it. # for p in [("name",Name("yes"),Name("another")), ("metaInfo", MetaInfo(), MetaInfo()), ("content", Blob("foo"), Blob("bar"))]: res = testPropertyRW( Data(), p[0], [p[1],p[2]]) if not res[0]: print(res) # ForwardingFlags # All boolean, so use shortcut below # from pyndn.forwarding_flags import ForwardingFlags for p in ["active", "childInherit", "advertise", "last", "capture", "local", "tap", "captureOk"]: res = testPropertyRW( ForwardingFlags(), p, [True, False] ) if not res[0]: print(res) # Interest # TODO: We do not check exclude because there is no equals() for it yet. # TODO: When passing None as the KeyLocator, it generates a blank KeyLocator object, so equivalence checks fail. Don't check None. #
("forwardingFlags", ForwardingFlags(), ForwardingFlags()), ("expirationPeriod", 1000.1, None)]: res = testPropertyRW(ControlParameters(), p[0], [p[1], p[2]]) if not res[0]: print(res) # Data # from pyndn.data import Data from pyndn.name import Name from pyndn.meta_info import MetaInfo from pyndn.signature import Signature from pyndn.util.blob import Blob # We do not test the signature property because clone is not yet implemented for it. # for p in [("name", Name("yes"), Name("another")), ("metaInfo", MetaInfo(), MetaInfo()), ("content", Blob("foo"), Blob("bar"))]: res = testPropertyRW(Data(), p[0], [p[1], p[2]]) if not res[0]: print(res) # ForwardingFlags # All boolean, so use shortcut below # from pyndn.forwarding_flags import ForwardingFlags for p in [ "active", "childInherit", "advertise", "last", "capture", "local", "tap", "captureOk" ]: res = testPropertyRW(ForwardingFlags(), p, [True, False]) if not res[0]: print(res)