forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: add support of a batch insert request
Draft changes: add support the IPROTO_INSERT_ARROW request and message pack type MP_ARROW . Closes #399
- Loading branch information
Showing
4 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package arrow | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
// Arrow MessagePack extension type | ||
const arrowExtId = 8 | ||
|
||
// Arrow struct wraps a raw arrow data buffer. | ||
type Arrow struct { | ||
data []byte | ||
} | ||
|
||
// MakeArrow returns a new arrow.Arrow object that contains | ||
// wrapped a raw arrow data buffer. | ||
func MakeArrow(arrow []byte) (Arrow, error) { | ||
if len(arrow) == 0 { | ||
return Arrow{}, fmt.Errorf("no Arrow data") | ||
} | ||
return Arrow{arrow}, nil | ||
} | ||
|
||
// ToArrow returns a []byte that contains Arrow raw data. | ||
func (a *Arrow) ToArrow() []byte { | ||
return a.data | ||
} | ||
|
||
func arrowDecoder(d *msgpack.Decoder, v reflect.Value, extLen int) error { | ||
arrow := Arrow{ | ||
data: make([]byte, 0, extLen), | ||
} | ||
n, err := d.Buffered().Read(arrow.data) | ||
if err != nil { | ||
return fmt.Errorf("msgpack: can't read bytes on Arrow decode: %w", err) | ||
} | ||
if n < extLen || n != len(arrow.data) { | ||
return fmt.Errorf("msgpack: unexpected end of stream after %d Arrow bytes", n) | ||
} | ||
|
||
v.Set(reflect.ValueOf(arrow)) | ||
return nil | ||
} | ||
|
||
func arrowEncoder(e *msgpack.Encoder, v reflect.Value) ([]byte, error) { | ||
if v.IsValid() { | ||
return v.Interface().(Arrow).data, nil | ||
} | ||
|
||
return []byte{}, fmt.Errorf("msgpack: not valid Arrow value") | ||
} | ||
|
||
func init() { | ||
msgpack.RegisterExtDecoder(arrowExtId, Arrow{}, arrowDecoder) | ||
msgpack.RegisterExtEncoder(arrowExtId, Arrow{}, arrowEncoder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package arrow_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters