diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2023-04-28 11:42:02 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2023-04-28 12:09:10 -0400 |
| commit | eb279c6dbe2e9359e2c5eb5407b1ca1e23e2e04f (patch) | |
| tree | 67507e4aa57aa30b5479efcc407905c2a52d0d94 | |
| parent | 8834434b67f239d37e0dc8fcc23dbbbdaf7360eb (diff) | |
| download | pyisda-eb279c6dbe2e9359e2c5eb5407b1ca1e23e2e04f.tar.gz | |
finish packing format for spread curve
| -rw-r--r-- | pyisda/curve.pyx | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 02bf22a..1322c9e 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -96,7 +96,7 @@ cdef class Curve(object): elif fmt == 0: r = self.buf.get()[:self.buf_size] elif fmt == 2: - packed_size = sizeof(TCurve) + curve.fNumItems * (sizeof(double) + sizeof(uint16_t)) + packed_size = size - curve.fNumItems * (sizeof(TDate) - sizeof(uint16_t)) r = PyBytes_FromStringAndSize(NULL, packed_size) dst = PyBytes_AS_STRING(r) src = <char*>curve @@ -108,6 +108,11 @@ cdef class Curve(object): (<uint16_t*>dst)[i] = (<TRatePt*>src)[i].fDate - ref_date ref_date = (<TRatePt*>src)[i].fDate (<double*>(dst + curve.fNumItems * sizeof(uint16_t)))[i] = (<TRatePt*>src)[i].fRate + size -= sizeof(TCurve) + curve.fNumItems * sizeof(TRatePt) + if size > 0: + src += curve.fNumItems * sizeof(TRatePt) + dst += curve.fNumItems * (sizeof(double) + sizeof(uint16_t)) + memcpy(dst, src, size) return r def __getstate__(self): |
