swift3 - Swift 3 Unsafe Pointer Ambiguous init and bytes -


i having 2 major problems when trying upgrade library involves file exporting swift 3. have read apple/swift migration page, still unsure best way go make sure don't lose of these bytes. lot of examples converting string, need bytes.

the first problem having within every line below starts stream.write, unsafepointer<uintx>(&var) returns error saying ambigious use of init.

var xbuffer = [uint8](repeating: 0, count: 2048 + 171*1024) let stream : outputstream = outputstream(tobuffer: &xbuffer, capacity: 2048 + 171*1024); stream.open();  //version number (2 bytes) stream.write(data(bytes: unsafepointer<uint8>(&(self.version)), count: 1).bytes.bindmemory(to: uint8.self, capacity: data(bytes: unsafepointer<uint8>(&(self.version)), count: 1).count),maxlength: 1);  stream.write(data(bytes: unsafepointer<uint8>(&(self.subversion)), count: 1).bytes.bindmemory(to: uint8.self, capacity: data(bytes: unsafepointer<uint8>(&(self.subversion)), count: 1).count),maxlength: 1);  //operation id status code (2 bytes) var opid_big = cfswapint16hosttobig(self.operationid); stream.write(data(bytes: unsafepointer<uint8>(&(opid_big)), count: 2).bytes.bindmemory(to: uint8.self, capacity: data(bytes: unsafepointer<uint8>(&(opid_big)), count: 2).count),maxlength: 2);  //request id (4 bytes) requestid = requestid | 0x1; var rqid_big = cfswapint32hosttobig(requestid); stream.write(data(bytes: unsafepointer<uint8>(&(rqid_big)), count: 4).bytes.bindmemory(to: uint8.self, capacity: data(bytes: unsafepointer<uint8>(&(rqid_big)), count: 4).count), maxlength: 4); 

i able to change performing changes unsaferawpointer , unsafebufferpointer when creating data.

after have issue xcode print error bytes unavailable use withunsafebytes instead.

so overall, able fix minor parts piece piece using stuff this, because of chained commands, having trouble making multiple changes , trying stackoverflow solutions , swift migration practices because of multiple required changes on chained commands.

i appreciate answers or enlightment/direction.

other migration page helpful

stackoverflow reference 1

generally, have no need create intermediate data write byte sequences outputstream.

    var xbuffer = [uint8](repeating: 0, count: 2048 + 171*1024)     xbuffer.withunsafemutablebufferpointer{bufferpointer in         let stream : outputstream = outputstream(tobuffer: bufferpointer.baseaddress!, capacity: xbuffer.count);         stream.open();          //version number (2 bytes)         withunsafebytes(of: &self.version) {             stream.write($0.baseaddress!.assumingmemorybound(to: uint8.self), maxlength: 1)         }          withunsafebytes(of: &self.subversion) {             stream.write($0.baseaddress!.assumingmemorybound(to: uint8.self), maxlength: 1)         }          //operation id status code (2 bytes)         var opid_big = self.operationid.bigendian         withunsafebytes(of: &opid_big) {             stream.write($0.baseaddress!.assumingmemorybound(to: uint8.self), maxlength: 2)         }          //request id (4 bytes)         var rqid_big = (requestid | 0x1).bigendian;         withunsafebytes(of: &rqid_big) {             stream.write($0.baseaddress!.assumingmemorybound(to: uint8.self), maxlength: 4)         }     } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -