summaryrefslogtreecommitdiff
path: root/swift/src
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2019-04-03 15:08:27 +0200
committerJose <jose@zeroc.com>2019-04-03 15:08:27 +0200
commitadec71218c1503663a371ea7cf30ea9068f95eb9 (patch)
treefcd2af866ee6d85d90bd231c1386c0aedeccd64f /swift/src
parentFixes for optional marshalling unmarshalling (diff)
downloadice-adec71218c1503663a371ea7cf30ea9068f95eb9.tar.bz2
ice-adec71218c1503663a371ea7cf30ea9068f95eb9.tar.xz
ice-adec71218c1503663a371ea7cf30ea9068f95eb9.zip
Fixes for optional marshalling unmarshalling
Diffstat (limited to 'swift/src')
-rw-r--r--swift/src/Ice/OutputStream.swift27
1 files changed, 10 insertions, 17 deletions
diff --git a/swift/src/Ice/OutputStream.swift b/swift/src/Ice/OutputStream.swift
index 4eced4b9674..11157adda61 100644
--- a/swift/src/Ice/OutputStream.swift
+++ b/swift/src/Ice/OutputStream.swift
@@ -222,7 +222,7 @@ public extension OutputStream {
return
}
- if writeOptional(tag: tag, format: OptionalFormat.VSize) {
+ if writeOptionalVSize(tag: tag, len: val.count, elemSize: 1) {
write(val)
}
}
@@ -235,7 +235,10 @@ public extension OutputStream {
}
func write(tag: Int32, value v: Bool?) {
- writeNumeric(tag, UInt8(v == true ? 1 : 0), OptionalFormat.F1)
+ guard let val = v else {
+ return
+ }
+ writeNumeric(tag, UInt8(val == true ? 1 : 0), OptionalFormat.F1)
}
func write(_ v: [Bool]) {
@@ -251,7 +254,8 @@ public extension OutputStream {
guard let val = v else {
return
}
- if writeOptional(tag: tag, format: OptionalFormat.VSize) {
+
+ if writeOptionalVSize(tag: tag, len: val.count, elemSize: 1) {
write(val)
}
}
@@ -389,7 +393,7 @@ public extension OutputStream {
write(size)
} else {
// pre-allocate size memory
- buf.ensure(bytesNeeded: Int(1 + size))
+ buf.ensure(bytesNeeded: Int(1))
write(UInt8(size))
}
}
@@ -562,19 +566,8 @@ public extension OutputStream {
func writeOptionalVSize(tag: Int32, len: Int, elemSize: Int) -> Bool {
if writeOptional(tag: tag, format: OptionalFormat.VSize) {
- if len == 0 {
- write(size: 1)
- write(size: 0)
- } else {
- var sz = len * elemSize
- if len > 254 {
- sz += 5
- } else {
- sz += 1
- }
- write(size: sz)
- return true
- }
+ write(size: len == 0 ? 1 : (len * elemSize) + (len > 254 ? 5 : 1))
+ return true
}
return false
}