-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add multi range support Update descriptors. Add multirange codec. Add simple multi range test. * Add multirange to encoder/decoder & update test * Fix multiRange encode/decode to use range encoder/decoder * Remove multirange from protocol V1 * Add multirange const to descriptor file * Fix docs * Add multi range type aliases * Add gendocs for multi range type aliases * Add comments for public multi range aliases * Put long comments in 2 lines * Fix lint error * Make gendocs for multi range type aliases * Update multirange comments * Delete contains multirange test * Update rstdocs/types.rst file
- Loading branch information
Showing
10 changed files
with
358 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
edgedb | ||
*.test | ||
/.vscode |
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
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,150 @@ | ||
// This source file is part of the EdgeDB open source project. | ||
// | ||
// Copyright EdgeDB Inc. and the EdgeDB authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package codecs | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"unsafe" | ||
|
||
"github.com/edgedb/edgedb-go/internal" | ||
"github.com/edgedb/edgedb-go/internal/buff" | ||
"github.com/edgedb/edgedb-go/internal/descriptor" | ||
types "github.com/edgedb/edgedb-go/internal/edgedbtypes" | ||
) | ||
|
||
func buildMultiRangeEncoderV2( | ||
desc *descriptor.V2, | ||
version internal.ProtocolVersion, | ||
) (Encoder, error) { | ||
child, err := buildRangeEncoderV2(&desc.Fields[0].Desc, version) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &multiRangeEncoder{desc.ID, child}, nil | ||
} | ||
|
||
type multiRangeEncoder struct { | ||
id types.UUID | ||
child Encoder | ||
} | ||
|
||
func (c *multiRangeEncoder) DescriptorID() types.UUID { return c.id } | ||
|
||
func (c *multiRangeEncoder) Encode( | ||
w *buff.Writer, | ||
val interface{}, | ||
path Path, | ||
required bool, | ||
) error { | ||
in := reflect.ValueOf(val) | ||
|
||
if in.Kind() != reflect.Slice { | ||
return fmt.Errorf( | ||
"expected %v to be a slice got: %T", path, val, | ||
) | ||
} | ||
|
||
if in.IsNil() && required { | ||
return missingValueError(val, path) | ||
} | ||
|
||
if in.IsNil() { | ||
w.PushUint32(0xffffffff) | ||
return nil | ||
} | ||
|
||
elmCount := in.Len() | ||
|
||
w.BeginBytes() | ||
w.PushUint32(uint32(elmCount)) | ||
|
||
var err error | ||
for i := 0; i < elmCount; i++ { | ||
err = c.child.Encode( | ||
w, | ||
in.Index(i).Interface(), | ||
path.AddIndex(i), | ||
true, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
w.EndBytes() | ||
return nil | ||
} | ||
|
||
func buildMultiRangeDecoderV2( | ||
desc *descriptor.V2, | ||
typ reflect.Type, | ||
path Path, | ||
) (Decoder, error) { | ||
if typ.Kind() != reflect.Slice { | ||
return nil, fmt.Errorf( | ||
"expected %v to be a Slice, got %v", path, typ.Kind(), | ||
) | ||
} | ||
|
||
child, err := buildRangeDecoderV2(&desc.Fields[0].Desc, typ.Elem(), path) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &multiRangeDecoder{desc.ID, child, typ, calcStep(typ.Elem())}, nil | ||
} | ||
|
||
type multiRangeDecoder struct { | ||
id types.UUID | ||
child Decoder | ||
typ reflect.Type | ||
|
||
// step is the element width in bytes for a go array of type `Array.typ`. | ||
step int | ||
} | ||
|
||
func (c *multiRangeDecoder) DescriptorID() types.UUID { return c.id } | ||
|
||
func (c *multiRangeDecoder) Decode(r *buff.Reader, out unsafe.Pointer) error { | ||
elmCount := int(int32(r.PopUint32())) | ||
|
||
slice := (*sliceHeader)(out) | ||
setSliceLen(slice, c.typ, elmCount) | ||
|
||
for i := 0; i < elmCount; i++ { | ||
elmLen := r.PopUint32() | ||
|
||
if elmLen == 0xffffffff { | ||
continue | ||
} | ||
|
||
err := c.child.Decode( | ||
r.PopSlice(elmLen), | ||
pAdd(slice.Data, uintptr(i*c.step)), | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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,40 @@ | ||
// This source file is part of the EdgeDB open source project. | ||
// | ||
// Copyright EdgeDB Inc. and the EdgeDB authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package edgedbtypes | ||
|
||
// MultiRangeInt32 is a type alias for a slice of RangeInt32 values. | ||
type MultiRangeInt32 = []RangeInt32 | ||
|
||
// MultiRangeInt64 is a type alias for a slice of RangeInt64 values. | ||
type MultiRangeInt64 = []RangeInt64 | ||
|
||
// MultiRangeFloat32 is a type alias for a slice of RangeFloat32 values. | ||
type MultiRangeFloat32 = []RangeFloat32 | ||
|
||
// MultiRangeFloat64 is a type alias for a slice of RangeFloat64 values. | ||
type MultiRangeFloat64 = []RangeFloat64 | ||
|
||
// MultiRangeDateTime is a type alias for a slice of RangeDateTime values. | ||
type MultiRangeDateTime = []RangeDateTime | ||
|
||
// MultiRangeLocalDateTime is a type alias for a slice of | ||
// RangeLocalDateTime values. | ||
type MultiRangeLocalDateTime = []RangeLocalDateTime | ||
|
||
// MultiRangeLocalDate is a type alias for a slice of | ||
// RangeLocalDate values. | ||
type MultiRangeLocalDate = []RangeLocalDate |
Oops, something went wrong.