Skip to content

Commit

Permalink
Updated dependencies (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar authored May 25, 2020
1 parent 226117a commit 06ef70b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 95 deletions.
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@ go 1.14

require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/aws/aws-sdk-go v1.30.24 // indirect
github.com/aws/aws-sdk-go v1.31.4 // indirect
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f
github.com/coocood/freecache v1.1.0
github.com/dgraph-io/badger v1.6.1
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/emitter-io/address v1.0.0
github.com/emitter-io/config v1.0.0
github.com/emitter-io/stats v1.0.3
github.com/golang/protobuf v1.4.1 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/golang/snappy v0.0.1
github.com/gorilla/websocket v1.4.2
github.com/jawher/mow.cli v1.1.0
github.com/kelindar/binary v1.0.8
github.com/kelindar/binary v1.0.9
github.com/kelindar/rate v1.0.0
github.com/kelindar/tcp v1.0.0
github.com/klauspost/compress v1.10.5 // indirect
github.com/klauspost/compress v1.10.6 // indirect
github.com/prometheus/client_golang v1.6.0
github.com/prometheus/common v0.10.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/tidwall/buntdb v1.1.2
github.com/tidwall/gjson v1.6.0 // indirect
github.com/tidwall/pretty v1.0.1 // indirect
github.com/valyala/fasthttp v1.12.0
github.com/weaveworks/mesh v0.0.0-20191105120815-58dbcc3e8e63
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f // indirect
golang.org/x/sys v0.0.0-20200508214444-3aab700007d7 // indirect
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/alexcesaro/statsd.v2 v2.0.0
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
36 changes: 20 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v0.0.0-20181019205654-b2427922671b/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.30.24 h1:y3JPD51VuEmVqN3BEDVm4amGpDma2cKJcDPuAU1OR58=
github.com/aws/aws-sdk-go v1.30.24/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.31.4 h1:YZ0uEYIWeanGuAomElHmRWMAbXVqrQixxgf2vtIjO6M=
github.com/aws/aws-sdk-go v1.31.4/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f h1:y06x6vGnFYfXUoVMbrcP1Uzpj4JG01eB5vRps9G8agM=
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f/go.mod h1:2stgcRjl6QmW+gU2h5E7BQXg4HU0gzxKWDuT5HviN9s=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
Expand Down Expand Up @@ -72,8 +72,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
Expand Down Expand Up @@ -110,15 +110,17 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kelindar/binary v1.0.8 h1:YwahocVzCFY+1+WF5JUqwrYZpe4vcNo7JhWKZA/uBQs=
github.com/kelindar/binary v1.0.8/go.mod h1:4zDwr5pQvY3i4xrRd1kC7pcuWvSU/Jbh/v2D0tZUPfE=
github.com/kelindar/binary v1.0.9 h1:Rngq8Kd8BTdqJlmH6fvIlgKypMLcJGykynsyigjbMG8=
github.com/kelindar/binary v1.0.9/go.mod h1:4zDwr5pQvY3i4xrRd1kC7pcuWvSU/Jbh/v2D0tZUPfE=
github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3 h1:6If+E1dikQbdT7DlhZqLplfGkEt6dSoz7+MK+TFC7+U=
github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3/go.mod h1:+lTCLnZFXOkqwD8sLPl6u4erAc0cP8wFegQHfipz7KE=
github.com/kelindar/rate v1.0.0 h1:JNZdufLjtDzr/E/rCtWkqo2OVU4yJSScZngJ8LuZ7kU=
github.com/kelindar/rate v1.0.0/go.mod h1:AjT4G+hTItNwt30lucEGZIz8y7Uk5zPho6vurIZ+1Es=
github.com/kelindar/tcp v1.0.0 h1:585JE7qmc6S5EQPYLAkRqfGo4PqDxalke98AXjxPmrE=
github.com/kelindar/tcp v1.0.0/go.mod h1:JB5hj1cshLU60XrLij2BBxW3JQ4hOye8vqbyvuKb52k=
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.10.5 h1:7q6vHIqubShURwQz8cQK6yIe/xC3IF0Vm7TGfqjewrc=
github.com/klauspost/compress v1.10.5/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.10.6 h1:SP6zavvTG3YjOosWePXFDlExpKIWMTO4SE/Y8MZB2vI=
github.com/klauspost/compress v1.10.6/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -162,6 +164,8 @@ github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6T
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.11 h1:DhHlBtkHWPYi8O2y31JkK0TF+DGM+51OopZjH/Ia5qI=
Expand Down Expand Up @@ -226,8 +230,8 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 h1:IaQbIIB2X/Mp/DKctl6ROxz1KyMlKp4uyvL6+kQ7C88=
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
Expand All @@ -238,8 +242,8 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f h1:QBjCr1Fz5kw158VqdE9JfI9cJnl/ymnJWAdMuinqL7Y=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 h1:eDrdRpKgkcCqKZQwyZRyeFZgfqt37SL7Kv3tok06cKE=
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -257,8 +261,8 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200508214444-3aab700007d7 h1:EEDKzZsac90dOwDpumCaAWrqnvbzVPdlUH9lCZ1yExw=
golang.org/x/sys v0.0.0-20200508214444-3aab700007d7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -271,8 +275,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/alexcesaro/statsd.v2 v2.0.0 h1:FXkZSCZIH17vLCO5sO2UucTHsH9pc+17F6pl3JVCwMc=
gopkg.in/alexcesaro/statsd.v2 v2.0.0/go.mod h1:i0ubccKGzBVNBpdGV5MocxyA/XlLUJzA7SLonnE4drU=
Expand All @@ -291,5 +295,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
20 changes: 9 additions & 11 deletions internal/event/crdt/durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (s *Durable) store(tx *buntdb.Tx, key string, t Time) {

// Fetch fetches the item either from transaction or cache.
func (s *Durable) fetch(item string) Time {
cacheKey := stringToBinary(item)
cacheKey := binary.ToBytes(item)
if v, err := s.cache.Get(cacheKey); err == nil {
return decodeTime(binaryToString(&v))
return decodeTime(binary.ToString(&v))
}

tx, _ := s.db.Begin(false)
defer tx.Rollback()
if t, err := tx.Get(item); err == nil {
s.cache.Set(cacheKey, stringToBinary(t), 60)
s.cache.Set(cacheKey, binary.ToBytes(t), 60)
return decodeTime(t)
}
return Time{}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *Durable) Merge(other Set) {
func (s *Durable) Range(prefix []byte, f func(string, Time) bool) {
s.db.View(func(tx *buntdb.Tx) error {
return tx.Ascend("", func(k, v string) bool {
if !bytes.HasPrefix(stringToBinary(k), prefix) {
if !bytes.HasPrefix(binary.ToBytes(k), prefix) {
return true
}

Expand Down Expand Up @@ -250,10 +250,8 @@ func (c *durableCodec) EncodeTo(e *binary.Encoder, rv reflect.Value) (err error)
// Write the entire sample
e.WriteUvarint(uint64(len(entries)))
for _, v := range entries {
e.WriteUvarint(uint64(len(v.Key)))
e.Write(stringToBinary(v.Key))
e.WriteUvarint(uint64(len(v.Val)))
e.Write(stringToBinary(v.Val))
e.WriteString(v.Key)
e.WriteString(v.Val)
}
return
}
Expand All @@ -268,17 +266,17 @@ func (c *durableCodec) DecodeTo(d *binary.Decoder, rv reflect.Value) (err error)

out.db.Update(func(tx *buntdb.Tx) error {
for i := 0; i < int(size); i++ {
k, err := readBytes(d)
k, err := d.ReadSlice()
if err != nil {
return nil
}

v, err := readBytes(d)
v, err := d.ReadSlice()
if err != nil {
return nil
}

tx.Set(binaryToString(&k), binaryToString(&v), nil)
tx.Set(binary.ToString(&k), binary.ToString(&v), nil)
}
return nil
})
Expand Down
31 changes: 2 additions & 29 deletions internal/event/crdt/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ package crdt

import (
bin "encoding/binary"
"reflect"
"time"
"unsafe"

"github.com/kelindar/binary"
)
Expand Down Expand Up @@ -71,44 +69,19 @@ func (t Time) Encode() string {
n1 := bin.PutVarint(b, t.AddTime)
n2 := bin.PutVarint(b[n1:], t.DelTime)
b = b[:n1+n2]
return binaryToString(&b)
return binary.ToString(&b)
}

// DecodeTime decodes the time from a string
func decodeTime(t string) (v Time) {
b, n := stringToBinary(t), 0
b, n := binary.ToBytes(t), 0
v.AddTime, n = bin.Varint(b)
v.DelTime, _ = bin.Varint(b[n:])
return
}

// ------------------------------------------------------------------------------------

func readBytes(d *binary.Decoder) (buffer []byte, err error) {
var l uint64
if l, err = d.ReadUvarint(); err == nil && l > 0 {
buffer, err = d.Slice(int(l))
}
return
}

func binaryToString(b *[]byte) string {
return *(*string)(unsafe.Pointer(b))
}

func stringToBinary(v string) (b []byte) {
strHeader := (*reflect.StringHeader)(unsafe.Pointer(&v))
byteHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
byteHeader.Data = strHeader.Data

l := len(v)
byteHeader.Len = l
byteHeader.Cap = l
return
}

// ------------------------------------------------------------------------------------

// The clock for unit-testing
type clock func() int64

Expand Down
14 changes: 5 additions & 9 deletions internal/event/crdt/volatile.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,8 @@ func (c *codecVolatile) EncodeTo(e *binary.Encoder, rv reflect.Value) (err error

e.WriteUvarint(uint64(len(s.data)))
for k, t := range s.data {
v := t.Encode()

e.WriteUvarint(uint64(len(k)))
e.Write(stringToBinary(k))
e.WriteUvarint(uint64(len(v)))
e.Write(stringToBinary(v))
e.WriteString(k)
e.WriteString(t.Encode())
}
return
}
Expand All @@ -168,17 +164,17 @@ func (c *codecVolatile) DecodeTo(d *binary.Decoder, rv reflect.Value) (err error
}

for i := 0; i < int(size); i++ {
k, err := readBytes(d)
k, err := d.ReadSlice()
if err != nil {
return nil
}

v, err := readBytes(d)
v, err := d.ReadSlice()
if err != nil {
return nil
}

out.data[binaryToString(&k)] = decodeTime(binaryToString(&v))
out.data[binary.ToString(&k)] = decodeTime(binary.ToString(&v))
}

rv.Set(reflect.ValueOf(*out))
Expand Down
1 change: 1 addition & 0 deletions internal/event/crdt/volatile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestRange(t *testing.T) {
return true
})
assert.Equal(t, 5, count)
assert.Equal(t, 6, state.Count())
}

// ------------------------------------------------------------------------------------
Expand Down
10 changes: 3 additions & 7 deletions internal/security/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"fmt"
"strconv"
"time"
"unsafe"

"github.com/emitter-io/emitter/internal/config"
"github.com/emitter-io/emitter/internal/security/hash"
"github.com/kelindar/binary"
)

// Channel types
Expand Down Expand Up @@ -302,8 +302,8 @@ func (c *Channel) parseOptions(text []byte) (i int, ok bool) {

// Set the option
c.Options = append(c.Options, ChannelOption{
Key: binaryToString(&key),
Value: binaryToString(&val),
Key: binary.ToString(&key),
Value: binary.ToString(&val),
})

val = val[0:0]
Expand All @@ -312,7 +312,3 @@ func (c *Channel) parseOptions(text []byte) (i int, ok bool) {

return i, true
}

func binaryToString(b *[]byte) string {
return *(*string)(unsafe.Pointer(b))
}
17 changes: 3 additions & 14 deletions internal/security/hash/murmur.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package hash

import (
"math/bits"
"reflect"
"unsafe"

"github.com/kelindar/binary"
)

const (
Expand All @@ -27,7 +27,7 @@ const (

// OfString returns a murmur32 hash for the string
func OfString(value string) uint32 {
return Of(stringToBinary(value))
return Of(binary.ToBytes(value))
}

// Of returns a murmur32 hash for the data slice.
Expand Down Expand Up @@ -74,14 +74,3 @@ func Of(data []byte) uint32 {

return (h1 << 24) | (((h1 >> 8) << 16) & 0xFF0000) | (((h1 >> 16) << 8) & 0xFF00) | (h1 >> 24)
}

func stringToBinary(v string) (b []byte) {
strHeader := (*reflect.StringHeader)(unsafe.Pointer(&v))
byteHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
byteHeader.Data = strHeader.Data

l := len(v)
byteHeader.Len = l
byteHeader.Cap = l
return
}
3 changes: 2 additions & 1 deletion internal/security/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/emitter-io/emitter/internal/security/hash"
"github.com/kelindar/binary"
)

// Gets the beginning of time for the timestamp, which is 2010/1/1 00:00:00
Expand Down Expand Up @@ -142,7 +143,7 @@ func (k Key) ValidateChannel(ch *Channel) bool {
}

// Split by `/`
channel := binaryToString(&topic)
channel := binary.ToString(&topic)
parts := strings.Split(channel, "/")
wc := parts[len(parts)-1] == "#"
if wc {
Expand Down

0 comments on commit 06ef70b

Please sign in to comment.