Giter Site home page Giter Site logo

codecs's Introduction

#codecs

Provides interfaces, functions and codecs that can be used to encode/decode data to/from various formats.

Documentation

You can get stuck into the API documentation by checking out these API docs:

How to use the codecs package

// make a codec service
codecService := new(codecs.WebCodecService)

// get the content type (probably from the request)
var contentType string = "application/json"

// get the codec
codec, err := codecService.GetCodec(contentType)

if err != nil {
	// handle errors - specifially ErrorContentTypeNotSupported
}

/*
	[]bytes to object
*/

// get the raw data
dataBytes := []byte(`{"somedata": true}`)

// use the codec to unmarshal the dataBytes
var obj interface{}
unmarshalErr := codecService.UnmarshalWithCodec(codec, dataBytes, obj) error

if unmarshalErr != nil {
	// handle this error
}

// obj will now be an object built from the dataBytes

// get some details about the kind of response we're going to make
// (probably from the request headers again)
var accept string = "application/json"
var extension string = ".json"
var hasCallback bool = false

// get the codec to respond with (it could be different)
responseCodec, responseCodecErr := codecService.GetCodecForResponding(accept, extension, hasCallback)

if responseCodecErr != nil {
    // handle this error
}

/*
	object to []bytes
*/

// get the data object
dataObject := map[string]interface{}{"name": "Mat"}

// use the codec service to marshal to bytes
bytes, marshalErr := codecService.MarshalWithCodec(responseCodecErr, dataObject, nil)

if marshalErr != nil {
	// handle marshalErr
}

// bytes would now be a representation of the data object

Contributing

Please feel free to submit issues, fork the repository and send pull requests!

When submitting an issue, we ask that you please include steps to reproduce the issue so we can see it on our end also!

Licence

Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell

Please consider promoting this project if you find it useful.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

codecs's People

Contributors

matryer avatar nelsam avatar syohex avatar tylerb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

codecs's Issues

Default codecs

By default, should all codecs be installed?

// InstalledCodecs is an array of installed codec objects, initialized with the provided default codecs.
var InstalledCodecs []codecs.Codec = []codecs.Codec{new(json.JsonCodec), new(jsonp.JsonPCodec)}

Add codec removal

Sometimes an application may want to remove a codec from the default list.

Use proper Reader and Writer semantics

Why do you encode/marshal into a freshly allocated []byte, and do you require a []byte for unmarshal? Even proper encodings/csv is hidden behind this memory-hungry, nonscalable interface...

msgpack has been deprecated

see stretchr/goweb#25

package github.com/ugorji/go-msgpack has been deprecated (05/29/2013). 
It will be retired anytime from July 1, 2013.
Please update to faster and much much better github.com/ugorji/go/codec.
See https://github.com/ugorji/go/tree/master/codec#readme for more information.

Add `csv` option to codecs

It's be cool if codecs could speak CSV for legacy reasons.

POST /resources.csv
header1,header2
row1value1,row1value2
row2value1,row2value2
row3value1,row3value2

and also reading...

GET /resources.csv

name,age,male
Mat,30,true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.