Custom decoder
By default, OCMAM uses the protopack
library to decode the requested layer data.
To decode layer data using a custom decoder, use the schema_decoder
field of the DataStoreServerSettings
structure.
In this section, learn how to:
Use a custom decoder for a specific layer
To decode a specific layer using a custom decoder:
-
Create the custom decoder for the layer.
Example:
struct RoadAttributeLayerDecoder
{
bool
operator( )( const void* data,
const int size,
clientmap::decoder::LayerConfigurationPtr configuration,
clientmap::decoder::ClientMapTile& tile ) const
{
tile.road_attribute_layer_configuration
= std::move( configuration );
if ( data == nullptr || size <= 0 )
{
return true;
}
if ( !tile.arena )
{
tile.arena = std::make_shared<
clientmap::decoder::ClientMapTile::ArenaType >( );
}
auto* const road_attribute_layer = google::protobuf::Arena::Create<
clientmap::decoder::RoadAttributeLayer >( tile.arena.get( ) );
...
tile.road_attribute_layer = clientmap::decoder::LayerPtr<
const clientmap::decoder::RoadAttributeLayer >(
road_attribute_layer, tile.arena );
return true;
}
};
Note: operator( )
must be of the clientmap::decoder::AbstractSchemaDecoder::LayerDecoderType
type.
-
Create a DefaultSchemaDecoder
instance and configure it to use the custom decoder for the specific layer.
Note: The layers for which custom decoders are not set are decoded using the protopack
library by default.
Example:
auto decoder
= std::make_shared< clientmap::decoder::DefaultSchemaDecoder >( );
decoder->SetDecoder( clientmap::rendering::kRoadAttributeLayerName,
RoadAttributeLayerDecoder( ) );
-
Create a DataStoreServer
instance that uses the DefaultSchemaDecoder
instance.
Example:
olp::clientmap::datastore::DataStoreServerSettings server_settings;
server_settings.schema_decoder = decoder;
...
auto server
= std::make_shared< olp::clientmap::datastore::DataStoreServer >(
server_settings );
Use a custom decoder for all layers
To decode all layers using a custom decoder:
-
Create the custom decoder for all layers.
Example:
struct CustomLayerDecoder
{
bool
operator( )( const void* data,
const int size,
clientmap::decoder::LayerConfigurationPtr configuration,
clientmap::decoder::ClientMapTile& tile ) const
{
...
}
};
Notes:
-
operator( )
must be of the clientmap::decoder::AbstractSchemaDecoder::LayerDecoderType
type. - For each layer,
operator( )
must set the correct layer data and layer configuration fields of the tile
instance.
-
Create a DefaultSchemaDecoder
instance and configure it to use the custom decoder for all layers.
Example:
auto decoder
= std::make_shared< clientmap::decoder::DefaultSchemaDecoder >( );
decoder->SetDecoder( CustomLayerDecoder( ) );
-
Create a DataStoreServer
instance that uses the DefaultSchemaDecoder
instance.
Example:
olp::clientmap::datastore::DataStoreServerSettings server_settings;
server_settings.schema_decoder = decoder;
...
auto server
= std::make_shared< olp::clientmap::datastore::DataStoreServer >(
server_settings );
Use a custom schema
To decode all layers using a custom schema:
-
Inherit the custom schema decoder from the clientmap::decoder::AbstractSchemaDecoder
abstract class.
Example:
class CustomSchemaDecoder : public AbstractSchemaDecoder
{
public:
...
};
-
Create a DataStoreServer
instance that uses the custom schema decoder instance.
Example:
olp::clientmap::datastore::DataStoreServerSettings server_settings;
server_settings.schema_decoder
= std::make_shared< CustomSchemaDecoder >( );
...
auto server
= std::make_shared< olp::clientmap::datastore::DataStoreServer >(
server_settings );