@@ -72,8 +72,13 @@ template <> struct string_traits<pgvector::Vector> {
7272 }
7373
7474 static size_t size_buffer (const pgvector::Vector& value) noexcept {
75+ auto values = static_cast <std::vector<float >>(value);
76+
77+ // cannot throw an exception here on overflow
78+ // so throw in into_buf
79+
7580 size_t size = 2 ; // [ and ]
76- for (const auto v : static_cast <std::vector< float >>(value) ) {
81+ for (const auto v : values ) {
7782 size += 1 ; // ,
7883 size += string_traits<float >::size_buffer (v);
7984 }
@@ -132,8 +137,13 @@ template <> struct string_traits<pgvector::HalfVector> {
132137 }
133138
134139 static size_t size_buffer (const pgvector::HalfVector& value) noexcept {
140+ auto values = static_cast <std::vector<float >>(value);
141+
142+ // cannot throw an exception here on overflow
143+ // so throw in into_buf
144+
135145 size_t size = 2 ; // [ and ]
136- for (const auto v : static_cast <std::vector< float >>(value) ) {
146+ for (const auto v : values ) {
137147 size += 1 ; // ,
138148 size += string_traits<float >::size_buffer (v);
139149 }
@@ -237,7 +247,7 @@ template <> struct string_traits<pgvector::SparseVector> {
237247 // cannot throw an exception here on overflow
238248 // so throw in into_buf
239249
240- size_t size = 4 ; // {, }, /, and \0
250+ size_t size = 3 ; // {, }, and /
241251 size += string_traits<int >::size_buffer (dimensions);
242252 for (size_t i = 0 ; i < nnz; i++) {
243253 size += 2 ; // : and ,
0 commit comments