def DeserializePointer(self, size, nb_elements, context): if self.length != 0 and nb_elements != self.length: raise serialization.DeserializationException( 'Incorrect array size') if (size < serialization.HEADER_STRUCT.size + self.SizeForLength(nb_elements)): raise serialization.DeserializationException( 'Incorrect array size') return self.DeserializeArray(size, nb_elements, context)
def Deserialize(self, value, context): if value == -1: if not self.nullable: raise serialization.DeserializationException( 'Trying to deserialize null for non nullable type.') return self.FromHandle(mojo_system.Handle()) return self.FromHandle(context.ClaimHandle(value))
def Deserialize(self, value, context): s = self.struct_type.Deserialize(value, context) if s: if len(s.keys) != len(s.values): raise serialization.DeserializationException( 'keys and values do not have the same length.') return dict(zip(s.keys, s.values)) return None
def Deserialize(cls, data): buf = buffer(data) if len(data) < cls._SIMPLE_MESSAGE_STRUCT.size: raise serialization.DeserializationException('Header is too short.') (size, version, message_type, flags) = ( cls._SIMPLE_MESSAGE_STRUCT.unpack_from(buf)) if (version < cls._SIMPLE_MESSAGE_VERSION): raise serialization.DeserializationException('Incorrect version.') request_id = 0 if _HasRequestId(flags): if version < cls._MESSAGE_WITH_REQUEST_ID_VERSION: raise serialization.DeserializationException('Incorrect version.') if (size < cls._MESSAGE_WITH_REQUEST_ID_SIZE or len(data) < cls._MESSAGE_WITH_REQUEST_ID_SIZE): raise serialization.DeserializationException('Header is too short.') (request_id, ) = cls._REQUEST_ID_STRUCT.unpack_from( buf, cls._REQUEST_ID_OFFSET) return MessageHeader(message_type, flags, request_id, data)
def Deserialize(self, value, context): if value == 0: if not self.nullable: raise serialization.DeserializationException( 'Trying to deserialize null for non nullable type.') return None if value % 8 != 0: raise serialization.DeserializationException( 'Pointer alignment is incorrect.') sub_context = context.GetSubContext(value) if len(sub_context.data) < serialization.HEADER_STRUCT.size: raise serialization.DeserializationException( 'Available data too short to contain header.') (size, nb_elements) = serialization.HEADER_STRUCT.unpack_from( sub_context.data) if len(sub_context.data) < size or size < serialization.HEADER_STRUCT.size: raise serialization.DeserializationException('Header size is incorrect.') sub_context.ClaimMemory(0, size) return self.DeserializePointer(size, nb_elements, sub_context)
def Deserialize(self, value, context): result = self.union_type.Deserialize(context) if not result and not self.nullable: raise serialization.DeserializationException( 'Trying to deserialize null for non nullable type.') return result