phpserializer

package module
v0.0.0-...-0f0c576 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2013 License: MIT Imports: 9 Imported by: 0

README

PHPSerializer for Go

Purpose

This package provide some Features to decode/encode PHP serialialized objects into Go structures.

See phpserializer_test.go for usage examples.

But Why ?

At work (Rivet & Sway) I needed to handle some data from a Drupal database from Go.

Among all the terrible things Drupal does one particular painful one is that it stores serialized PHP objects in the database (in text fields) ... Yeah, really !

Added to that there is apparently NO official PHP serializtion format specifications, other than checking the PHP source code and crying in the process.

So anyway this allows Encoding/Decoding Serialized PHP object strings into Go structures. There is no guarantees it supports all possible PHP objects at this point, pull requests welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NameConverter

type NameConverter interface {
	Convert(str string) string
}

Converter interface, takes a string and convert to another

type PhpSerializer

type PhpSerializer struct {
	EncodeNameConverter NameConverter
	DecodeNameConverter NameConverter
	IgnoreCastErrors    bool // Wether to fail on type mistmatch or ignore and continue
}

Encode / Decode serialized PHP objects from Go / Golang Note that there are apparently **NO** PHP serialization format specs, so this might not be perfect. Defaults to SnakeToUnderscore & UnderscoreToSnake for Name conversion, but can be replaced.

func (PhpSerializer) Decode

func (p PhpSerializer) Decode(reader io.Reader, v interface{}) (err error)

Decode serialized PHP content into target object Note: Not closing the reader

func (PhpSerializer) Encode

func (p PhpSerializer) Encode(v interface{}, writer io.Writer) (err error)

type SnakeToUnderscore

type SnakeToUnderscore struct{}

Convert snake case name to a lower case underscored name ie: "ThisIsAnExample" -> "this_is_an_example"

func (SnakeToUnderscore) Convert

func (c SnakeToUnderscore) Convert(str string) string

type UnderscoreToSnake

type UnderscoreToSnake struct{}

Convert an underscored name to a snake case name ie: "this_is_an_example" -> "ThisIsAnExample"

func (UnderscoreToSnake) Convert

func (c UnderscoreToSnake) Convert(str string) string

Jump to

Keyboard shortcuts

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