The idea is to create a system in which any geo location can be represented by a printable string.

The main application area being commerce supply chain and logistics.

We propose a base32 encoded protocol buffer structure, which produces a printable result.

BhuPatra.proto
    message BhuPatra {
        required float lat  = 1; // Lattitude
        required float long = 2; // longitude
        optional float accuracy = 3; // in meters
        repeated float geometry = 4 [packed=true]; // array length defines geometry, in meters
    }

Geometry is defined by array length

  • length:

  • 0= point

  • 1= circle, the scalar value represents Radius

  • 2= line

  • 3= traingle

  • 4=quadilatral

  • >= polygon

The Protocol Buffer encoded binary is converted to base32 encoded ASCII.

GoLang Procol Buffers

go get -u github.com/golang/protobuf/proto

go get -u github.com/golang/protobuf/protoc-gen-go

After installing the above backend packages, we need to install the C++ Protocol Buffer compiler.

After un-zipping the package in a local directory, run the following commands.

shell commands
make
make check
sudo make install

Now we can generate the go language code.

~/Innomon/BhuPatra$ protoc --go_out=. *.proto

The above command generates the following source code.

BhuPatra.pb.go
// Code generated by protoc-gen-go.
// source: BhuPatra.proto
// DO NOT EDIT!

/*
Package BhuPatra is a generated protocol buffer package.

It is generated from these files:
        BhuPatra.proto

It has these top-level messages:
        BhuPatra
*/
package main

import proto "github.com/golang/protobuf/proto"
import math "math"

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = math.Inf

// *
// Geometry is defined by array length
//
// length 0= point
// 1= circle, the scalar value represents Radius
// 2= line
// 3= traingle
// 4=quadilatral
// >= polygon
//
// The Protocol Buffer encoded binary is converted to `base32` encoded ASCII.
//
type BhuPatra struct {
        Lat              *float32  `protobuf:"fixed32,1,req,name=lat" json:"lat,omitempty"`
        Long             *float32  `protobuf:"fixed32,2,req,name=long" json:"long,omitempty"`
        Accuracy         *float32  `protobuf:"fixed32,3,opt,name=accuracy" json:"accuracy,omitempty"`
        Geometry         []float32 `protobuf:"fixed32,4,rep,packed,name=geometry" json:"geometry,omitempty"`
        XXX_unrecognized []byte    `json:"-"`
}

func (m *BhuPatra) Reset()         { *m = BhuPatra{} }
func (m *BhuPatra) String() string { return proto.CompactTextString(m) }
func (*BhuPatra) ProtoMessage()    {}

func (m *BhuPatra) GetLat() float32 {
        if m != nil && m.Lat != nil {
                return *m.Lat
        }
        return 0
}

func (m *BhuPatra) GetLong() float32 {
        if m != nil && m.Long != nil {
                return *m.Long
        }
        return 0
}

func (m *BhuPatra) GetAccuracy() float32 {
        if m != nil && m.Accuracy != nil {
                return *m.Accuracy
        }
        return 0
}

func (m *BhuPatra) GetGeometry() []float32 {
        if m != nil {
                return m.Geometry
        }
        return nil
}

func init() {
}

I changed the package name in the above code. To support the test program below.

test-bhu.go
package main

import (
        "encoding/base32"
        "encoding/hex"
        "fmt"

)

func main() {
// 28.576793, 77.371372 : Stellar Kings Court co-ord.
   var lat float32 = 28.576793
   var long float32 = 77.371372
  var accuracy float32 = 10
  geom := []float32  {0,12.3,123,312.2}

   bpat := &BhuPatra { Lat: &lat, Long: &long , Accuracy: &accuracy , Geometry: geom }
   encProto := []byte(bpat.String())

   str := base32.StdEncoding.EncodeToString(encProto)

   fmt.Printf("The b32 [%s] len = %d\n",str, len(str))

   str = hex.EncodeToString(encProto)

   fmt.Printf("The Hex [%s] len = %d\n",str, len(str))

}

The command :

go run test-bhu.go BhuPatra.pb.go

Produces the following output.

Console Output
The b32 [NRQXIORSHAXDKNZWG44TIIDMN5XGO...DSPE5DGMJSFYZCA===] len = 152
The Hex [6c61743a32382...656f6d657472793a3331322e3220] len = 186

Source Code

Resources

Other Systems