filepb

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: GPL-3.0 Imports: 13 Imported by: 2

README

// Copyright 2025 WIT.COM Inc Licensed GPL 3.0

Used to identify protobuf files (requires autogenpb)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty error = fmt.Errorf("config file was empty")
View Source
var ErrMarshal error = fmt.Errorf("protobuf parse error")
View Source
var ErrProtoNoVarName error = errors.New("name not in .proto")
View Source
var ErrProtoVarNotString error = errors.New("name exists but is not a string")
View Source
var File_fakefile_proto protoreflect.FileDescriptor
View Source
var File_filetype_proto protoreflect.FileDescriptor

Functions

func GetFilename added in v0.0.8

func GetFilename(pb proto.Message) (string, error)

this will try both "filename" and "Filename"

func GetString added in v0.0.8

func GetString(pb proto.Message, varname string) (string, error)

this will try both "filename" and "Filename"

func IdentifyPB

func IdentifyPB(filename string) (string, string, error)

print the protobuf in human form

func SetFilename added in v0.0.8

func SetFilename(pb proto.Message, filename string) (bool, error)

sets "Filename" if it exists in the protobuf

func VersionCheck added in v0.0.11

func VersionCheck(pb proto.Message) (string, string, error)

verify 'version' for .pb files application should die if they don't match returns (newVersion, oldVersion, error)

func VersionCheckFile added in v0.0.11

func VersionCheckFile(pb proto.Message, filename string) (string, string, error)

verify 'version' for .pb files application should die if they don't match returns (newVersion, oldVersion, error)

Types

type FakeFile added in v0.0.8

type FakeFile struct {
	Uuid    string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`       // `autogenpb:uuid:`
	Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:`
	// contains filtered or unexported fields
}

func (*FakeFile) Descriptor deprecated added in v0.0.8

func (*FakeFile) Descriptor() ([]byte, []int)

Deprecated: Use FakeFile.ProtoReflect.Descriptor instead.

func (*FakeFile) GetUuid added in v0.0.8

func (x *FakeFile) GetUuid() string

func (*FakeFile) GetVersion added in v0.0.8

func (x *FakeFile) GetVersion() string

func (*FakeFile) ProtoMessage added in v0.0.8

func (*FakeFile) ProtoMessage()

func (*FakeFile) ProtoReflect added in v0.0.8

func (x *FakeFile) ProtoReflect() protoreflect.Message

func (*FakeFile) Reset added in v0.0.8

func (x *FakeFile) Reset()

func (*FakeFile) String added in v0.0.8

func (x *FakeFile) String() string

func (*FakeFile) Unmarshal added in v0.0.8

func (v *FakeFile) Unmarshal(data []byte) error

unmarshal from wire. You have won.

type Filetype

type Filetype struct {
	Nothing bool `protobuf:"varint,1,opt,name=nothing,proto3" json:"nothing,omitempty"` // generate autosave functions (in marshal.go ?)
	// contains filtered or unexported fields
}

func (*Filetype) Descriptor deprecated

func (*Filetype) Descriptor() ([]byte, []int)

Deprecated: Use Filetype.ProtoReflect.Descriptor instead.

func (*Filetype) GetNothing

func (x *Filetype) GetNothing() bool

func (*Filetype) ProtoMessage

func (*Filetype) ProtoMessage()

func (*Filetype) ProtoReflect

func (x *Filetype) ProtoReflect() protoreflect.Message

func (*Filetype) Reset

func (x *Filetype) Reset()

func (*Filetype) String

func (x *Filetype) String() string

type FiletypeScanner

type FiletypeScanner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*FiletypeScanner) Next

func (it *FiletypeScanner) Next() *Filetype

Next() returns the next thing in the array

func (*FiletypeScanner) Scan

func (it *FiletypeScanner) Scan() bool

type Filetypes

type Filetypes struct {
	Uuid      string      `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`           // `autogenpb:uuid:c1239110-ad4f-41f3-b0f5-189034f0a3a7`
	Version   string      `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`     // `autogenpb:version:v0.0.1`
	Filetypes []*Filetype `protobuf:"bytes,3,rep,name=Filetypes,proto3" json:"Filetypes,omitempty"` // an array of each .proto file in the working directory
	// contains filtered or unexported fields
}

I know, I know, the whole point of using protobuf is so you don't need a uuid or versions because it's inherently forward compatable. nonetheless, a simple stubbed out trivial and empty protobuf message can marshal and identify all the files also, this could be used to modify /usr/bin/file /usr/share/magic to identify the files maybe this is already been done and is pointless, but it seems like a good idea

func NewFiletypes

func NewFiletypes() *Filetypes

func (*Filetypes) All

func (x *Filetypes) All() *FiletypeScanner

func (*Filetypes) Append

func (x *Filetypes) Append(y *Filetype)

a Append() shortcut (that does Clone() with a mutex) notsure if it really works doesn't allow nil

func (*Filetypes) Clone added in v0.0.5

func (x *Filetypes) Clone(y *Filetype) *Filetype

a Clone() shortcut (with a mutex). notsure if it really works

func (*Filetypes) Delete

func (x *Filetypes) Delete(y *Filetype) bool

func (*Filetypes) Descriptor deprecated

func (*Filetypes) Descriptor() ([]byte, []int)

Deprecated: Use Filetypes.ProtoReflect.Descriptor instead.

func (*Filetypes) FormatJSON

func (v *Filetypes) FormatJSON() string

human readable JSON

func (*Filetypes) FormatTEXT

func (v *Filetypes) FormatTEXT() string

apparently this isn't stable, but it's awesomely better https://protobuf.dev/reference/go/faq/#unstable-text it's brilliant for config files!

func (*Filetypes) GetFiletypes

func (x *Filetypes) GetFiletypes() []*Filetype

func (*Filetypes) GetUuid

func (x *Filetypes) GetUuid() string

func (*Filetypes) GetVersion

func (x *Filetypes) GetVersion() string

func (*Filetypes) IterAll

func (x *Filetypes) IterAll() iter.Seq[*Filetype]

Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'

func (*Filetypes) Len

func (x *Filetypes) Len() int

func (*Filetypes) Marshal

func (v *Filetypes) Marshal() ([]byte, error)

marshal to wire. This is called winning.

func (*Filetypes) MarshalJSON

func (v *Filetypes) MarshalJSON() ([]byte, error)

marshal json

func (*Filetypes) ProtoMessage

func (*Filetypes) ProtoMessage()

func (*Filetypes) ProtoReflect

func (x *Filetypes) ProtoReflect() protoreflect.Message

func (*Filetypes) Reset

func (x *Filetypes) Reset()

func (*Filetypes) String

func (x *Filetypes) String() string

func (*Filetypes) Unmarshal

func (v *Filetypes) Unmarshal(data []byte) error

unmarshal from wire. You have won.

func (*Filetypes) UnmarshalJSON

func (v *Filetypes) UnmarshalJSON(data []byte) error

unmarshal json

func (*Filetypes) UnmarshalTEXT

func (v *Filetypes) UnmarshalTEXT(data []byte) error

unmarshalTEXT. This reads the .text config file back in after the user edits it

type FiletypesScanner

type FiletypesScanner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*FiletypesScanner) Next

func (it *FiletypesScanner) Next() *Filetypes

Next() returns the next thing in the array

func (*FiletypesScanner) Scan

func (it *FiletypesScanner) Scan() bool

type Identify

type Identify struct {
	Uuid    string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`       //
	Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` //
	// contains filtered or unexported fields
}

func (*Identify) Descriptor deprecated

func (*Identify) Descriptor() ([]byte, []int)

Deprecated: Use Identify.ProtoReflect.Descriptor instead.

func (*Identify) FormatJSON

func (v *Identify) FormatJSON() string

human readable JSON

func (*Identify) FormatTEXT

func (v *Identify) FormatTEXT() string

apparently this isn't stable, but it's awesomely better https://protobuf.dev/reference/go/faq/#unstable-text it's brilliant for config files!

func (*Identify) GetUuid

func (x *Identify) GetUuid() string

func (*Identify) GetVersion

func (x *Identify) GetVersion() string

func (*Identify) Marshal

func (v *Identify) Marshal() ([]byte, error)

marshal to wire. This is called winning.

func (*Identify) MarshalJSON

func (v *Identify) MarshalJSON() ([]byte, error)

marshal json

func (*Identify) ProtoMessage

func (*Identify) ProtoMessage()

func (*Identify) ProtoReflect

func (x *Identify) ProtoReflect() protoreflect.Message

func (*Identify) Reset

func (x *Identify) Reset()

func (*Identify) String

func (x *Identify) String() string

func (*Identify) Unmarshal

func (v *Identify) Unmarshal(data []byte) error

unmarshal from wire. You have won.

func (*Identify) UnmarshalJSON

func (v *Identify) UnmarshalJSON(data []byte) error

unmarshal json

func (*Identify) UnmarshalTEXT

func (v *Identify) UnmarshalTEXT(data []byte) error

unmarshalTEXT. This reads the .text config file back in after the user edits it

type IdentifyScanner

type IdentifyScanner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*IdentifyScanner) Next

func (it *IdentifyScanner) Next() *Identify

Next() returns the next thing in the array

func (*IdentifyScanner) Scan

func (it *IdentifyScanner) Scan() bool

type PatchError added in v0.0.8

type PatchError struct {
	// Note: The `XXX_` fields are part of the older struct tags,
	// but the reflection logic comes from the modern API.
	// In a real generated file, you wouldn't see these tags.
	UserName  string                 `protobuf:"bytes,1,opt,name=user_name,json=userName,proto3" json:"user_name,omitempty"`
	UserId    int64                  `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	Email     string                 `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
	LastLogin *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=last_login,json=lastLogin,proto3" json:"last_login,omitempty"`
}

--- Mock of a generated user.pb.go file ---

func (*PatchError) ProtoMessage added in v0.0.8

func (*PatchError) ProtoMessage()

func (*PatchError) ProtoReflect added in v0.0.8

func (x *PatchError) ProtoReflect() protoreflect.Message

In a real generated file, ProtoReflect() would be fully implemented. For this example, we don't need it as the marshallers will use reflection.

func (*PatchError) Reset added in v0.0.8

func (x *PatchError) Reset()

func (*PatchError) String added in v0.0.8

func (x *PatchError) String() string

Jump to

Keyboard shortcuts

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