mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
5620be211c
* Renamed DOCUMENT to PAGE * Added PageLoadParams * Added PageLoadParams * Renamed LoadPageParams -> PageLoadParams * Added support for context.Done() (#201) * Bug/#189 operators precedence (#202) * Fixed math operators precedence * Fixed logical operators precedence * Fixed array operator * Added support for parentheses to enforce a different operator evaluation order * Feature/#200 drivers (#209) * Added new interfaces * Renamed dynamic to cdp driver * Renamed drivers * Added ELEMENT_EXISTS function (#210) * Renamed back PAGE to DOCUMENT (#211) * Added Getter and Setter interfaces
85 lines
1.2 KiB
Go
85 lines
1.2 KiB
Go
package values
|
|
|
|
import (
|
|
"encoding/json"
|
|
"hash/fnv"
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
)
|
|
|
|
type Binary []byte
|
|
|
|
func NewBinary(values []byte) Binary {
|
|
return Binary(values)
|
|
}
|
|
|
|
func NewBinaryFrom(stream io.Reader) (Binary, error) {
|
|
values, err := ioutil.ReadAll(stream)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return Binary(values), nil
|
|
}
|
|
|
|
func (b Binary) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal([]byte(b))
|
|
}
|
|
|
|
func (b Binary) Type() core.Type {
|
|
return core.BinaryType
|
|
}
|
|
|
|
func (b Binary) String() string {
|
|
return string(b)
|
|
}
|
|
|
|
func (b Binary) Compare(other core.Value) int {
|
|
// TODO: Lame comparison, need to think more about it
|
|
switch other.Type() {
|
|
case core.BooleanType:
|
|
b2 := other.(*Binary)
|
|
|
|
if b2.Length() == b.Length() {
|
|
return 0
|
|
}
|
|
|
|
if b.Length() > b2.Length() {
|
|
return 1
|
|
}
|
|
|
|
return -1
|
|
default:
|
|
return 1
|
|
}
|
|
}
|
|
|
|
func (b Binary) Unwrap() interface{} {
|
|
return []byte(b)
|
|
}
|
|
|
|
func (b Binary) Hash() uint64 {
|
|
h := fnv.New64a()
|
|
|
|
h.Write([]byte(b.Type().String()))
|
|
h.Write([]byte(":"))
|
|
h.Write(b)
|
|
|
|
return h.Sum64()
|
|
}
|
|
|
|
func (b Binary) Copy() core.Value {
|
|
c := make([]byte, len(b))
|
|
|
|
copy(c, b)
|
|
|
|
return NewBinary(c)
|
|
}
|
|
|
|
func (b Binary) Length() Int {
|
|
return NewInt(len(b))
|
|
}
|