Skip to content
/ pb Public

Public Mapped Platform Service Definitions

License

Notifications You must be signed in to change notification settings

mapped/pb

Repository files navigation

PB

This repo contains all the public protobufs for Mapped Platform Service Definitions. Please refer to Mapped Developer Docs for more information.

Outputs

This monorepo generates packages or outputs for several languages:

  • C# - Published as a package to GPR: Mapped.PB
  • Java - Published as a package to GPR: com.mapped.pb
  • TypeScript
    • For Node.JS - Published as a package to GPR: pb-node
    • For Browsers - Published as a package to GPR: pb-browser
  • Python - Published on PyPi: mapped.pb
  • Go - Published as a module to go.mapped.dev/pb (which in turn points to https://github.com/mapped/pb-go)
    • Use go get go.mapped.dev/pb/cloud or go get go.mapped.dev/pb/gateway

GeoJSON Types

All GeoJSON is carried in google.protobuf.Struct, as can be seen in mapped/cloud/types/typed_value.proto. Each language's Google Protobuf library has handlers for going from JSON<->google.protobuf.Struct. To simplify things, this section will list how to do each transform in languages we use at Mapped.

(All samples skip over normal protobuf message marshal/unmarshal work, as it doesn't change based on the use of structs)

C#

From GeoJSON to Struct:

string json = File.ReadAllText(@"test.json");
var pbStruct = Google.Protobuf.WellKnownTypes.Struct.Parser.ParseJson(json);
myMsg.Value.GeojsonValue = pbStruct;

From Struct to GeoJSON:

string json = Google.Protobuf.JsonFormatter.Default.Format(myMsg.Value.GeojsonValue);

Go

(Samples are missing all error checking for brevity)

From GeoJSON to Struct:

import (
	"encoding/json"
	"io/ioutil"
	"os"

	"go.mapped.dev/pb/cloud"
	"google.golang.org/protobuf/types/known/structpb"
)

func geojsonToStruct() *cloud.types.TypedValue {
	// Read some json from disk
	jsonFile, _ := os.Open("test.json")
	defer jsonFile.Close()
	byteValue, _ := ioutil.ReadAll(jsonFile)

	// Unmarshal the json
	var jsonMap map[string]interface{}
	json.Unmarshal([]byte(byteValue), &jsonMap)

	// Put the json in to a Struct
	pbStruct, _ := structpb.NewStruct(jsonMap)

	// Use the Struct
	return &cloud.types.TypedValue{
		Value: &cloud.types.TypedValue_GeojsonValue{GeojsonValue: pbStruct},
	}
}

From Struct to GeoJSON:

import (
	"encoding/json"
	"io/ioutil"
	"os"

	"go.mapped.dev/pb/cloud"
	"google.golang.org/protobuf/types/known/structpb"
)

func structToGeojson(v *cloud.types.TypedValue) string {
	// Marshal to json
	jsonMap := v.GetGeojsonValue().AsMap()
	jsonBytes, _ := json.Marshal(jsonMap)

	// Return as a string
	return string(jsonBytes)
}

Weirdness

DO NOT MANUALLY CREATE TAGS

The CI build pipeline creates tags automatically.

About

Public Mapped Platform Service Definitions

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages