Git Product home page Git Product logo

Comments (3)

kasei avatar kasei commented on September 26, 2024

Oops. That actually won't work because of the while conditional read.count < size. Perhaps instead of writing directly to a Data index like read[position], the UInt8 value could be appended to the empty Data object instead...?

from thrift-swift.

kasei avatar kasei commented on September 26, 2024

I think it'll work if the object is constructed the same as Data(capacity: size), but within the read loop, it is filled with:

read.append(nextChar)

from thrift-swift.

apocolipse avatar apocolipse commented on September 26, 2024

Hmm good catch, I've not tested the TFileTransport extensively (just barely)
Could you replace the read method with this one and let me know if it fixes your issues?
After a quick test it seems that index addressing doesn't play nice with Data(capacity:) because it just reserved space, instead of fully allocating it to the Data object, so while it has n-bytes capacity to write to, it technically only has 0 bytes (reported by count), and index replacements on Data since its a value type use replaceBytesInRange:withBytes, since the range is {0,0} that obviously doesn't work well does it?

  public func read(size: Int) throws -> Data {
    // set up read buffer, position 0
    var read = Data(capacity: size)
    
    // read character buffer
    var nextChar: UInt8 = 0
    
    // continue until we've read size bytes
    while read.count < size {
      if fread(&nextChar, 1, 1, self.fileHandle) == 1 {
        read.append(nextChar)
      } else {
        throw TTransportError(error: .endOfFile)
      }
    }
    return read
  }

from thrift-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.