protofirestore

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

protofirestore

Go module for encoding/decoding protobuf messages to/from firestore documents.

Currently only supports encoding and the only supported well known types are google.protobuf.Timestamp and google.protobuf.Empty.

The module is still in early development and is not ready for production use. Any feedback or contributions are welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(m proto.Message) (map[string]interface{}, error)

Types

type MarshalOptions

type MarshalOptions struct {
	// EmitFirestoreSensibleDefaults specifies whether to emit default values
	// for fields which would otherwise be omitted. This is useful for ensuring that
	// the firestore database queries can be used to filter on the fields because
	// firestore does not support checking for the absence of a field.
	// The fields affected are as follows:
	//  ╔═══════╤════════════════════════════════════════╗
	//  ║ JSON  │ Protobuf field                         ║
	//  ╠═══════╪════════════════════════════════════════╣
	//  ║ false │ non-optional scalar boolean fields     ║
	//  ║ 0     │ non-optional scalar numeric fields     ║
	//  ║ ""    │ non-optional scalar string/byte fields ║
	//  ║ {}    │ non-optional messages within one ofs   ║
	//  ╚═══════╧════════════════════════════════════════╝
	//
	// The reason for the non-optional restriction is that optional fields
	// are not guaranteed to be present in the proto message, and therefore
	// the firestore query would not be able to filter on the field.
	//
	// The reason for the oneof non-optional messages being empty map in json
	// is that when deserializing from firestore, the oneof field needs to know
	// which field to populate, and if the field is not present in the json,
	// then it will just be nil.
	EmitFirestoreSensibleDefaults bool

	// Resolver is used for looking up types when expanding google.protobuf.Any
	// messages. If nil, this defaults to using protoregistry.GlobalTypes.
	Resolver interface {
		protoregistry.ExtensionTypeResolver
		protoregistry.MessageTypeResolver
	}
}

func (MarshalOptions) Marshal

func (o MarshalOptions) Marshal(m proto.Message) (map[string]interface{}, error)

Directories

Path Synopsis
internal
genid
Package genid contains constants for declarations in descriptor.proto and the well-known types.
Package genid contains constants for declarations in descriptor.proto and the well-known types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL