mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-04 22:17:59 +08:00

* Use normalizer as stream source Renamed 'writer' service to 'normalizer' and dropped Cassandra facilities from it. Extracted the common dependencies to 'mainflux' package for easier sharing. Fixed the API docs and unified environment variables. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use docker build arguments to specify build Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove cassandra libraries Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update go-kit version to 0.6.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix manager configuration Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Refactor docker-compose Merged individual compose files and dropped external links. Remove CoAP container since it is not referenced from NginX config at the moment. Update port mapping in compose and nginx.conf. Dropped bin scripts. Updated service documentation. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Drop content-type check Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement users data access layer in PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Bump version to 0.1.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use go-kit logger everywhere (except CoAP) Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Improve factory methods naming Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement clients data access layer on PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Make tests stateless All tests are refactored to use map-based table-driven tests. No cross-tests dependencies is present anymore. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove gitignore Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nginx proxying Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Mark client-user FK explicit Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update API documentation Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update channel model Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add channel PostgreSQL repository tests Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement PostgreSQL channels DAO Replaced update queries with raw SQL. Explicitly defined M2M table due to difficulties of ensuring the referential integrity through GORM. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Expose connection endpoints Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix swagger docs and remove DB logging Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nested query remarks Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add unique indices Signed-off-by: Dejan Mijic <dejan@mainflux.com>
230 lines
6.3 KiB
Go
230 lines
6.3 KiB
Go
// Protocol Buffers for Go with Gadgets
|
|
//
|
|
// Copyright (c) 2016, The GoGo Authors. All rights reserved.
|
|
// http://github.com/gogo/protobuf
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are
|
|
// met:
|
|
//
|
|
// * Redistributions of source code must retain the above copyright
|
|
// notice, this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
// in the documentation and/or other materials provided with the
|
|
// distribution.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
package proto
|
|
|
|
import (
|
|
"reflect"
|
|
"time"
|
|
)
|
|
|
|
var timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
|
|
|
|
type timestamp struct {
|
|
Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
|
|
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
|
|
}
|
|
|
|
func (m *timestamp) Reset() { *m = timestamp{} }
|
|
func (*timestamp) ProtoMessage() {}
|
|
func (*timestamp) String() string { return "timestamp<string>" }
|
|
|
|
func init() {
|
|
RegisterType((*timestamp)(nil), "gogo.protobuf.proto.timestamp")
|
|
}
|
|
|
|
func (o *Buffer) decTimestamp() (time.Time, error) {
|
|
b, err := o.DecodeRawBytes(true)
|
|
if err != nil {
|
|
return time.Time{}, err
|
|
}
|
|
tproto := ×tamp{}
|
|
if err := Unmarshal(b, tproto); err != nil {
|
|
return time.Time{}, err
|
|
}
|
|
return timestampFromProto(tproto)
|
|
}
|
|
|
|
func (o *Buffer) dec_time(p *Properties, base structPointer) error {
|
|
t, err := o.decTimestamp()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
setPtrCustomType(base, p.field, &t)
|
|
return nil
|
|
}
|
|
|
|
func (o *Buffer) dec_ref_time(p *Properties, base structPointer) error {
|
|
t, err := o.decTimestamp()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
setCustomType(base, p.field, &t)
|
|
return nil
|
|
}
|
|
|
|
func (o *Buffer) dec_slice_time(p *Properties, base structPointer) error {
|
|
t, err := o.decTimestamp()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
newBas := appendStructPointer(base, p.field, reflect.SliceOf(reflect.PtrTo(timeType)))
|
|
var zero field
|
|
setPtrCustomType(newBas, zero, &t)
|
|
return nil
|
|
}
|
|
|
|
func (o *Buffer) dec_slice_ref_time(p *Properties, base structPointer) error {
|
|
t, err := o.decTimestamp()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
newBas := appendStructPointer(base, p.field, reflect.SliceOf(timeType))
|
|
var zero field
|
|
setCustomType(newBas, zero, &t)
|
|
return nil
|
|
}
|
|
|
|
func size_time(p *Properties, base structPointer) (n int) {
|
|
structp := structPointer_GetStructPointer(base, p.field)
|
|
if structPointer_IsNil(structp) {
|
|
return 0
|
|
}
|
|
tim := structPointer_Interface(structp, timeType).(*time.Time)
|
|
t, err := timestampProto(*tim)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
size := Size(t)
|
|
return size + sizeVarint(uint64(size)) + len(p.tagcode)
|
|
}
|
|
|
|
func (o *Buffer) enc_time(p *Properties, base structPointer) error {
|
|
structp := structPointer_GetStructPointer(base, p.field)
|
|
if structPointer_IsNil(structp) {
|
|
return ErrNil
|
|
}
|
|
tim := structPointer_Interface(structp, timeType).(*time.Time)
|
|
t, err := timestampProto(*tim)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := Marshal(t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o.buf = append(o.buf, p.tagcode...)
|
|
o.EncodeRawBytes(data)
|
|
return nil
|
|
}
|
|
|
|
func size_ref_time(p *Properties, base structPointer) (n int) {
|
|
tim := structPointer_InterfaceAt(base, p.field, timeType).(*time.Time)
|
|
t, err := timestampProto(*tim)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
size := Size(t)
|
|
return size + sizeVarint(uint64(size)) + len(p.tagcode)
|
|
}
|
|
|
|
func (o *Buffer) enc_ref_time(p *Properties, base structPointer) error {
|
|
tim := structPointer_InterfaceAt(base, p.field, timeType).(*time.Time)
|
|
t, err := timestampProto(*tim)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := Marshal(t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o.buf = append(o.buf, p.tagcode...)
|
|
o.EncodeRawBytes(data)
|
|
return nil
|
|
}
|
|
|
|
func size_slice_time(p *Properties, base structPointer) (n int) {
|
|
ptims := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(reflect.PtrTo(timeType))).(*[]*time.Time)
|
|
tims := *ptims
|
|
for i := 0; i < len(tims); i++ {
|
|
if tims[i] == nil {
|
|
return 0
|
|
}
|
|
tproto, err := timestampProto(*tims[i])
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
size := Size(tproto)
|
|
n += len(p.tagcode) + size + sizeVarint(uint64(size))
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (o *Buffer) enc_slice_time(p *Properties, base structPointer) error {
|
|
ptims := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(reflect.PtrTo(timeType))).(*[]*time.Time)
|
|
tims := *ptims
|
|
for i := 0; i < len(tims); i++ {
|
|
if tims[i] == nil {
|
|
return errRepeatedHasNil
|
|
}
|
|
tproto, err := timestampProto(*tims[i])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := Marshal(tproto)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o.buf = append(o.buf, p.tagcode...)
|
|
o.EncodeRawBytes(data)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func size_slice_ref_time(p *Properties, base structPointer) (n int) {
|
|
ptims := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(timeType)).(*[]time.Time)
|
|
tims := *ptims
|
|
for i := 0; i < len(tims); i++ {
|
|
tproto, err := timestampProto(tims[i])
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
size := Size(tproto)
|
|
n += len(p.tagcode) + size + sizeVarint(uint64(size))
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (o *Buffer) enc_slice_ref_time(p *Properties, base structPointer) error {
|
|
ptims := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(timeType)).(*[]time.Time)
|
|
tims := *ptims
|
|
for i := 0; i < len(tims); i++ {
|
|
tproto, err := timestampProto(tims[i])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := Marshal(tproto)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o.buf = append(o.buf, p.tagcode...)
|
|
o.EncodeRawBytes(data)
|
|
}
|
|
return nil
|
|
}
|